[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 235 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 236 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 237 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 240 | } // namespace |
| 241 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 242 | class HttpNetworkTransactionTest |
| 243 | : public PlatformTest, |
| 244 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 245 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 246 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 247 | // Important to restore the per-pool limit first, since the pool limit must |
| 248 | // always be greater than group limit, and the tests reduce both limits. |
| 249 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 250 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 251 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 252 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 253 | } |
| 254 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 255 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 256 | HttpNetworkTransactionTest() |
| 257 | : spdy_util_(GetParam()), |
| 258 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 259 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 260 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 261 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 262 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 263 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 264 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 265 | struct SimpleGetHelperResult { |
| 266 | int rv; |
| 267 | std::string status_line; |
| 268 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 269 | int64_t total_received_bytes; |
| 270 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 271 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 272 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 273 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 274 | }; |
| 275 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 276 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 277 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 278 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 279 | } |
| 280 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 281 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 282 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 283 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 284 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 285 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 286 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 287 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 288 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 289 | } |
| 290 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 291 | const char* GetAlternateProtocolFromParam() { |
| 292 | return |
| 293 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 294 | } |
| 295 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 296 | std::string GetAlternativeServiceHttpHeader() { |
| 297 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 298 | "=\"www.example.com:443\"\r\n"; |
| 299 | } |
| 300 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 301 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 302 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 303 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 306 | // Either |write_failure| specifies a write failure or |read_failure| |
| 307 | // specifies a read failure when using a reused socket. In either case, the |
| 308 | // failure should cause the network transaction to resend the request, and the |
| 309 | // other argument should be NULL. |
| 310 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 311 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 312 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 313 | // Either |write_failure| specifies a write failure or |read_failure| |
| 314 | // specifies a read failure when using a reused socket. In either case, the |
| 315 | // failure should cause the network transaction to resend the request, and the |
| 316 | // other argument should be NULL. |
| 317 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 318 | const MockRead* read_failure, |
| 319 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 320 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 321 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 322 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 324 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 325 | HttpRequestInfo request; |
| 326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 327 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 328 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 329 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 330 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 331 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 332 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 333 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 334 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 335 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 336 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 337 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 338 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 340 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 341 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 342 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 343 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 344 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 345 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 346 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 347 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 348 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 349 | |
| 350 | // Even in the failure cases that use this function, connections are always |
| 351 | // successfully established before the error. |
| 352 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 353 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 354 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 355 | if (out.rv != OK) |
| 356 | return out; |
| 357 | |
| 358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 359 | // Can't use ASSERT_* inside helper functions like this, so |
| 360 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 361 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 362 | out.rv = ERR_UNEXPECTED; |
| 363 | return out; |
| 364 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 365 | out.status_line = response->headers->GetStatusLine(); |
| 366 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 367 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 368 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 369 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 370 | bool got_endpoint = |
| 371 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 372 | EXPECT_EQ(got_endpoint, |
| 373 | out.remote_endpoint_after_start.address().size() > 0); |
| 374 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 375 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 376 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 377 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 378 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 379 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 380 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 381 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 382 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 383 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 384 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 385 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 386 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 387 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 388 | std::string line; |
| 389 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 390 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 391 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 392 | HttpRequestHeaders request_headers; |
| 393 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 394 | std::string value; |
| 395 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 396 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 397 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 398 | EXPECT_EQ("keep-alive", value); |
| 399 | |
| 400 | std::string response_headers; |
| 401 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 402 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 403 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 404 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 405 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 406 | // The total number of sent bytes should not have changed. |
| 407 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 408 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 409 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 410 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 411 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 412 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 413 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 414 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 415 | MockWrite data_writes[] = { |
| 416 | MockWrite("GET / HTTP/1.1\r\n" |
| 417 | "Host: www.example.org\r\n" |
| 418 | "Connection: keep-alive\r\n\r\n"), |
| 419 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 420 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 421 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 422 | arraysize(data_writes)); |
| 423 | StaticSocketDataProvider* data[] = {&reads}; |
| 424 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 425 | |
| 426 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 427 | out.total_sent_bytes); |
| 428 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 429 | } |
| 430 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 431 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 432 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 433 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 434 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 435 | |
| 436 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 437 | |
| 438 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 439 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 440 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 441 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 442 | |
| 443 | // Original socket limits. Some tests set these. Safest to always restore |
| 444 | // them once each test has been run. |
| 445 | int old_max_group_sockets_; |
| 446 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 448 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 449 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 450 | HttpNetworkTransactionTest, |
| 451 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 452 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 453 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 454 | namespace { |
| 455 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 456 | class BeforeNetworkStartHandler { |
| 457 | public: |
| 458 | explicit BeforeNetworkStartHandler(bool defer) |
| 459 | : defer_on_before_network_start_(defer), |
| 460 | observed_before_network_start_(false) {} |
| 461 | |
| 462 | void OnBeforeNetworkStart(bool* defer) { |
| 463 | *defer = defer_on_before_network_start_; |
| 464 | observed_before_network_start_ = true; |
| 465 | } |
| 466 | |
| 467 | bool observed_before_network_start() const { |
| 468 | return observed_before_network_start_; |
| 469 | } |
| 470 | |
| 471 | private: |
| 472 | const bool defer_on_before_network_start_; |
| 473 | bool observed_before_network_start_; |
| 474 | |
| 475 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 476 | }; |
| 477 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 478 | class BeforeProxyHeadersSentHandler { |
| 479 | public: |
| 480 | BeforeProxyHeadersSentHandler() |
| 481 | : observed_before_proxy_headers_sent_(false) {} |
| 482 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 483 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 484 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 485 | observed_before_proxy_headers_sent_ = true; |
| 486 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 487 | } |
| 488 | |
| 489 | bool observed_before_proxy_headers_sent() const { |
| 490 | return observed_before_proxy_headers_sent_; |
| 491 | } |
| 492 | |
| 493 | std::string observed_proxy_server_uri() const { |
| 494 | return observed_proxy_server_uri_; |
| 495 | } |
| 496 | |
| 497 | private: |
| 498 | bool observed_before_proxy_headers_sent_; |
| 499 | std::string observed_proxy_server_uri_; |
| 500 | |
| 501 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 502 | }; |
| 503 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 504 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 505 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 506 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 507 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 508 | const int sizeof_row = strlen(row); |
| 509 | const int num_rows = static_cast<int>( |
| 510 | ceil(static_cast<float>(size) / sizeof_row)); |
| 511 | const int sizeof_data = num_rows * sizeof_row; |
| 512 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 513 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 514 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 515 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 516 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 517 | } |
| 518 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 519 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 520 | // Alternative functions that eliminate randomness and dependency on the local |
| 521 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 522 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 523 | static const uint8 bytes[] = { |
| 524 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 525 | }; |
| 526 | static size_t current_byte = 0; |
| 527 | for (size_t i = 0; i < n; ++i) { |
| 528 | output[i] = bytes[current_byte++]; |
| 529 | current_byte %= arraysize(bytes); |
| 530 | } |
| 531 | } |
| 532 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 533 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 534 | static const uint8 bytes[] = { |
| 535 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 536 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 537 | }; |
| 538 | static size_t current_byte = 0; |
| 539 | for (size_t i = 0; i < n; ++i) { |
| 540 | output[i] = bytes[current_byte++]; |
| 541 | current_byte %= arraysize(bytes); |
| 542 | } |
| 543 | } |
| 544 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 545 | std::string MockGetHostName() { |
| 546 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 547 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 548 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 549 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 550 | template<typename ParentPool> |
| 551 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 552 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 553 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 554 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 555 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 556 | const std::string last_group_name_received() const { |
| 557 | return last_group_name_; |
| 558 | } |
| 559 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 560 | int RequestSocket(const std::string& group_name, |
| 561 | const void* socket_params, |
| 562 | RequestPriority priority, |
| 563 | ClientSocketHandle* handle, |
| 564 | const CompletionCallback& callback, |
| 565 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 566 | last_group_name_ = group_name; |
| 567 | return ERR_IO_PENDING; |
| 568 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 569 | void CancelRequest(const std::string& group_name, |
| 570 | ClientSocketHandle* handle) override {} |
| 571 | void ReleaseSocket(const std::string& group_name, |
| 572 | scoped_ptr<StreamSocket> socket, |
| 573 | int id) override {} |
| 574 | void CloseIdleSockets() override {} |
| 575 | int IdleSocketCount() const override { return 0; } |
| 576 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 577 | return 0; |
| 578 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 579 | LoadState GetLoadState(const std::string& group_name, |
| 580 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 581 | return LOAD_STATE_IDLE; |
| 582 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 583 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 584 | return base::TimeDelta(); |
| 585 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 586 | |
| 587 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 588 | std::string last_group_name_; |
| 589 | }; |
| 590 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 591 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 592 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 593 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 594 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 595 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 596 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 597 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 598 | CaptureGroupNameSSLSocketPool; |
| 599 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 600 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 601 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 602 | HostResolver* host_resolver, |
| 603 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 604 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 605 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 606 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 607 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 608 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 609 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 610 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 611 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 612 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 613 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 614 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 615 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 616 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 617 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 618 | : SSLClientSocketPool(0, |
| 619 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 620 | cert_verifier, |
| 621 | NULL, |
| 622 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 623 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 624 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 625 | std::string(), |
| 626 | NULL, |
| 627 | NULL, |
| 628 | NULL, |
| 629 | NULL, |
| 630 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 631 | NULL) { |
| 632 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 633 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 634 | //----------------------------------------------------------------------------- |
| 635 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 636 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 637 | // configured for common cases. |
| 638 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 639 | if (!auth_challenge) |
| 640 | return false; |
| 641 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 642 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 643 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 644 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 645 | return true; |
| 646 | } |
| 647 | |
| 648 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 649 | if (!auth_challenge) |
| 650 | return false; |
| 651 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 652 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 653 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 654 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 655 | return true; |
| 656 | } |
| 657 | |
| 658 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 659 | if (!auth_challenge) |
| 660 | return false; |
| 661 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 662 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 663 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 664 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 665 | return true; |
| 666 | } |
| 667 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 668 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 669 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 670 | if (!auth_challenge) |
| 671 | return false; |
| 672 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 673 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 674 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 675 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 676 | return true; |
| 677 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 678 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 679 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 680 | } // namespace |
| 681 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 682 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 683 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 684 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 686 | } |
| 687 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 688 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 689 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 690 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 691 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 692 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 693 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 694 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 695 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 696 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 697 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 698 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 699 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 700 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 701 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 702 | |
| 703 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 707 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 708 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 709 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 711 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 712 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 713 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 714 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 716 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 717 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 718 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 722 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 724 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 725 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 726 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 727 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 728 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 729 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 730 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 731 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 732 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 733 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 737 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 738 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 739 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 741 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 742 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 743 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 744 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 746 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 747 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 748 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | // 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] | 752 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 754 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 755 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 757 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 758 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 759 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 760 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 761 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 762 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 763 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 767 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 769 | MockRead("\n"), |
| 770 | MockRead("\n"), |
| 771 | MockRead("Q"), |
| 772 | MockRead("J"), |
| 773 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 774 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 775 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 776 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 777 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 778 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 779 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 780 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 781 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 782 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 786 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 787 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 788 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 790 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 791 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 792 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 793 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 795 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 796 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 797 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 800 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 801 | // persistent connection. The response should still terminate since a 204 |
| 802 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 803 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 804 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 805 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 806 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 807 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 808 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 809 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 810 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 811 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 812 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 813 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 814 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 815 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 816 | int64_t response_size = reads_size - strlen(junk); |
| 817 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 820 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 821 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 822 | std::string final_chunk = "0\r\n\r\n"; |
| 823 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 824 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 825 | MockRead data_reads[] = { |
| 826 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 827 | MockRead("5\r\nHello\r\n"), |
| 828 | MockRead("1\r\n"), |
| 829 | MockRead(" \r\n"), |
| 830 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 831 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 832 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 833 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 834 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 835 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 836 | EXPECT_EQ(OK, out.rv); |
| 837 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 838 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 839 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 840 | int64_t response_size = reads_size - extra_data.size(); |
| 841 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 842 | } |
| 843 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 844 | // Next tests deal with http://crbug.com/56344. |
| 845 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 846 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 847 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 848 | MockRead data_reads[] = { |
| 849 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 850 | MockRead("Content-Length: 10\r\n"), |
| 851 | MockRead("Content-Length: 5\r\n\r\n"), |
| 852 | }; |
| 853 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 854 | arraysize(data_reads)); |
| 855 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 856 | } |
| 857 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 858 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 859 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 860 | MockRead data_reads[] = { |
| 861 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 862 | MockRead("Content-Length: 5\r\n"), |
| 863 | MockRead("Content-Length: 5\r\n\r\n"), |
| 864 | MockRead("Hello"), |
| 865 | }; |
| 866 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 867 | arraysize(data_reads)); |
| 868 | EXPECT_EQ(OK, out.rv); |
| 869 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 870 | EXPECT_EQ("Hello", out.response_data); |
| 871 | } |
| 872 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 873 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 874 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 875 | // More than 2 dupes. |
| 876 | { |
| 877 | MockRead data_reads[] = { |
| 878 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 879 | MockRead("Content-Length: 5\r\n"), |
| 880 | MockRead("Content-Length: 5\r\n"), |
| 881 | MockRead("Content-Length: 5\r\n\r\n"), |
| 882 | MockRead("Hello"), |
| 883 | }; |
| 884 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 885 | arraysize(data_reads)); |
| 886 | EXPECT_EQ(OK, out.rv); |
| 887 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 888 | EXPECT_EQ("Hello", out.response_data); |
| 889 | } |
| 890 | // HTTP/1.0 |
| 891 | { |
| 892 | MockRead data_reads[] = { |
| 893 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 894 | MockRead("Content-Length: 5\r\n"), |
| 895 | MockRead("Content-Length: 5\r\n"), |
| 896 | MockRead("Content-Length: 5\r\n\r\n"), |
| 897 | MockRead("Hello"), |
| 898 | }; |
| 899 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 900 | arraysize(data_reads)); |
| 901 | EXPECT_EQ(OK, out.rv); |
| 902 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 903 | EXPECT_EQ("Hello", out.response_data); |
| 904 | } |
| 905 | // 2 dupes and one mismatched. |
| 906 | { |
| 907 | MockRead data_reads[] = { |
| 908 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 909 | MockRead("Content-Length: 10\r\n"), |
| 910 | MockRead("Content-Length: 10\r\n"), |
| 911 | MockRead("Content-Length: 5\r\n\r\n"), |
| 912 | }; |
| 913 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 914 | arraysize(data_reads)); |
| 915 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 916 | } |
| 917 | } |
| 918 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 919 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 920 | MultipleContentLengthHeadersTransferEncoding) { |
| 921 | MockRead data_reads[] = { |
| 922 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 923 | MockRead("Content-Length: 666\r\n"), |
| 924 | MockRead("Content-Length: 1337\r\n"), |
| 925 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 926 | MockRead("5\r\nHello\r\n"), |
| 927 | MockRead("1\r\n"), |
| 928 | MockRead(" \r\n"), |
| 929 | MockRead("5\r\nworld\r\n"), |
| 930 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 932 | }; |
| 933 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 934 | arraysize(data_reads)); |
| 935 | EXPECT_EQ(OK, out.rv); |
| 936 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 937 | EXPECT_EQ("Hello world", out.response_data); |
| 938 | } |
| 939 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 940 | // Next tests deal with http://crbug.com/98895. |
| 941 | |
| 942 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 943 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 944 | MockRead data_reads[] = { |
| 945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 946 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 947 | MockRead("Content-Length: 5\r\n\r\n"), |
| 948 | MockRead("Hello"), |
| 949 | }; |
| 950 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 951 | arraysize(data_reads)); |
| 952 | EXPECT_EQ(OK, out.rv); |
| 953 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 954 | EXPECT_EQ("Hello", out.response_data); |
| 955 | } |
| 956 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 957 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 958 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 959 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 960 | MockRead data_reads[] = { |
| 961 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 962 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 963 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 964 | MockRead("Content-Length: 5\r\n\r\n"), |
| 965 | MockRead("Hello"), |
| 966 | }; |
| 967 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 968 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 969 | EXPECT_EQ(OK, out.rv); |
| 970 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 971 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 975 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | MockRead data_reads[] = { |
| 977 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 978 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 979 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 980 | MockRead("Content-Length: 5\r\n\r\n"), |
| 981 | MockRead("Hello"), |
| 982 | }; |
| 983 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 984 | arraysize(data_reads)); |
| 985 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 986 | } |
| 987 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 988 | // Checks that two identical Location headers result in no error. |
| 989 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 990 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 991 | MockRead data_reads[] = { |
| 992 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 993 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 994 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 995 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 996 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 997 | }; |
| 998 | |
| 999 | HttpRequestInfo request; |
| 1000 | request.method = "GET"; |
| 1001 | request.url = GURL("http://redirect.com/"); |
| 1002 | request.load_flags = 0; |
| 1003 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1004 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1005 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1007 | |
| 1008 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1009 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1011 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1013 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1015 | |
| 1016 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1017 | |
| 1018 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1019 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1020 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1021 | std::string url; |
| 1022 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1023 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1024 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1025 | } |
| 1026 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1027 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1028 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1029 | MockRead data_reads[] = { |
| 1030 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1031 | MockRead("Location: http://good.com/\r\n"), |
| 1032 | MockRead("Location: http://evil.com/\r\n"), |
| 1033 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1034 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1035 | }; |
| 1036 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1037 | arraysize(data_reads)); |
| 1038 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1039 | } |
| 1040 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1041 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1042 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1043 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1044 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1045 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1046 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1047 | request.load_flags = 0; |
| 1048 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1049 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1050 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1051 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1052 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1053 | trans->SetBeforeProxyHeadersSentCallback( |
| 1054 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1055 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1056 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1057 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1058 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1059 | "Host: www.example.org\r\n" |
| 1060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1061 | }; |
| 1062 | MockRead data_reads1[] = { |
| 1063 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1064 | MockRead("Server: Blah\r\n"), |
| 1065 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1066 | |
| 1067 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1068 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1069 | }; |
| 1070 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1071 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1072 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1075 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1077 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1078 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1079 | |
| 1080 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1081 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1082 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1083 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1084 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1085 | |
| 1086 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1087 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1088 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1089 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1090 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1091 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1092 | |
| 1093 | std::string server_header; |
| 1094 | void* iter = NULL; |
| 1095 | bool has_server_header = response->headers->EnumerateHeader( |
| 1096 | &iter, "Server", &server_header); |
| 1097 | EXPECT_TRUE(has_server_header); |
| 1098 | EXPECT_EQ("Blah", server_header); |
| 1099 | |
| 1100 | // Reading should give EOF right away, since there is no message body |
| 1101 | // (despite non-zero content-length). |
| 1102 | std::string response_data; |
| 1103 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1104 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1105 | EXPECT_EQ("", response_data); |
| 1106 | } |
| 1107 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1108 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1109 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1110 | |
| 1111 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1112 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1113 | MockRead("hello"), |
| 1114 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1115 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1116 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1117 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1118 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1119 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1120 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1121 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1122 | "hello", "world" |
| 1123 | }; |
| 1124 | |
| 1125 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1126 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1127 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1128 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1129 | request.load_flags = 0; |
| 1130 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1131 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1132 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1134 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1136 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1137 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1138 | |
| 1139 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1140 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1141 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1142 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1143 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1145 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1146 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1147 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1148 | |
| 1149 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1150 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1151 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1152 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1156 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1157 | ScopedVector<UploadElementReader> element_readers; |
| 1158 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1159 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1160 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1161 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1162 | request.method = "POST"; |
| 1163 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1164 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1165 | request.load_flags = 0; |
| 1166 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1167 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1168 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1169 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1170 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1171 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1172 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1173 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1174 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1175 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1176 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1180 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1182 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1184 | |
| 1185 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1186 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1187 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1188 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1189 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1190 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1191 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1192 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1193 | |
| 1194 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1195 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1196 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1197 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1198 | } |
| 1199 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1200 | // This test is almost the same as Ignores100 above, but the response contains |
| 1201 | // 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] | 1202 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1203 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1204 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1205 | request.method = "GET"; |
| 1206 | request.url = GURL("http://www.foo.com/"); |
| 1207 | request.load_flags = 0; |
| 1208 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1209 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1210 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1212 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1213 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1214 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1215 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1216 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1217 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1218 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1219 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1222 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1226 | |
| 1227 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1228 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1229 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1230 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1231 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1232 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1233 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1234 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1235 | |
| 1236 | std::string response_data; |
| 1237 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1238 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1239 | EXPECT_EQ("hello world", response_data); |
| 1240 | } |
| 1241 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1242 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1243 | HttpRequestInfo request; |
| 1244 | request.method = "POST"; |
| 1245 | request.url = GURL("http://www.foo.com/"); |
| 1246 | request.load_flags = 0; |
| 1247 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1248 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1249 | scoped_ptr<HttpTransaction> trans( |
| 1250 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1251 | |
| 1252 | MockRead data_reads[] = { |
| 1253 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1254 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1255 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1258 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1259 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1260 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1261 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1263 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1264 | rv = callback.WaitForResult(); |
| 1265 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1266 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1267 | std::string response_data; |
| 1268 | rv = ReadTransaction(trans.get(), &response_data); |
| 1269 | EXPECT_EQ(OK, rv); |
| 1270 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1271 | } |
| 1272 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1273 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1274 | HttpRequestInfo request; |
| 1275 | request.method = "POST"; |
| 1276 | request.url = GURL("http://www.foo.com/"); |
| 1277 | request.load_flags = 0; |
| 1278 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1279 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1280 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1282 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1283 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1284 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1285 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1286 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1289 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1293 | |
| 1294 | rv = callback.WaitForResult(); |
| 1295 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1296 | } |
| 1297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1298 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1299 | const MockWrite* write_failure, |
| 1300 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1301 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | request.method = "GET"; |
| 1303 | request.url = GURL("http://www.foo.com/"); |
| 1304 | request.load_flags = 0; |
| 1305 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1306 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1307 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1308 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1309 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1310 | // Written data for successfully sending both requests. |
| 1311 | MockWrite data1_writes[] = { |
| 1312 | MockWrite("GET / HTTP/1.1\r\n" |
| 1313 | "Host: www.foo.com\r\n" |
| 1314 | "Connection: keep-alive\r\n\r\n"), |
| 1315 | MockWrite("GET / HTTP/1.1\r\n" |
| 1316 | "Host: www.foo.com\r\n" |
| 1317 | "Connection: keep-alive\r\n\r\n") |
| 1318 | }; |
| 1319 | |
| 1320 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1322 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1323 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1324 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1326 | |
| 1327 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1328 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1329 | data1_writes[1] = *write_failure; |
| 1330 | } else { |
| 1331 | ASSERT_TRUE(read_failure); |
| 1332 | data1_reads[2] = *read_failure; |
| 1333 | } |
| 1334 | |
| 1335 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1336 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1337 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | |
| 1339 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1340 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1341 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1342 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1344 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1345 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1347 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | "hello", "world" |
| 1349 | }; |
| 1350 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1351 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1353 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1355 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1356 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1357 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1358 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
| 1361 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1362 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1364 | LoadTimingInfo load_timing_info; |
| 1365 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1366 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1367 | if (i == 0) { |
| 1368 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1369 | } else { |
| 1370 | // The second request should be using a new socket. |
| 1371 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1372 | } |
| 1373 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1374 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1375 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1376 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1377 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1378 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1379 | |
| 1380 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1381 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1382 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1383 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1384 | } |
| 1385 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1386 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1387 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1388 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1389 | const MockRead* read_failure, |
| 1390 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1391 | HttpRequestInfo request; |
| 1392 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1393 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1394 | request.load_flags = 0; |
| 1395 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1396 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1397 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1398 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1399 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1400 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1401 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1402 | if (use_spdy) { |
| 1403 | ssl1.SetNextProto(GetParam()); |
| 1404 | ssl2.SetNextProto(GetParam()); |
| 1405 | } |
| 1406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1408 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1409 | // SPDY versions of the request and response. |
| 1410 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1411 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1412 | scoped_ptr<SpdyFrame> spdy_response( |
| 1413 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1414 | scoped_ptr<SpdyFrame> spdy_data( |
| 1415 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1416 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1417 | // HTTP/1.1 versions of the request and response. |
| 1418 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1419 | "Host: www.foo.com\r\n" |
| 1420 | "Connection: keep-alive\r\n\r\n"; |
| 1421 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1422 | const char kHttpData[] = "hello"; |
| 1423 | |
| 1424 | std::vector<MockRead> data1_reads; |
| 1425 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1426 | if (write_failure) { |
| 1427 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1428 | data1_writes.push_back(*write_failure); |
| 1429 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1430 | } else { |
| 1431 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1432 | if (use_spdy) { |
| 1433 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1434 | } else { |
| 1435 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1436 | } |
| 1437 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1438 | } |
| 1439 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1440 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1441 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1442 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1443 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1444 | std::vector<MockRead> data2_reads; |
| 1445 | std::vector<MockWrite> data2_writes; |
| 1446 | |
| 1447 | if (use_spdy) { |
| 1448 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1449 | |
| 1450 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1451 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1452 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1453 | } else { |
| 1454 | data2_writes.push_back( |
| 1455 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1456 | |
| 1457 | data2_reads.push_back( |
| 1458 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1459 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1460 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1461 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1462 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1463 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1464 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1465 | |
| 1466 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1467 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1468 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1469 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1470 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1471 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1472 | // Wait for the preconnect to complete. |
| 1473 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1474 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1475 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1476 | |
| 1477 | // Make the request. |
| 1478 | TestCompletionCallback callback; |
| 1479 | |
| 1480 | scoped_ptr<HttpTransaction> trans( |
| 1481 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1482 | |
| 1483 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1484 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1485 | |
| 1486 | rv = callback.WaitForResult(); |
| 1487 | EXPECT_EQ(OK, rv); |
| 1488 | |
| 1489 | LoadTimingInfo load_timing_info; |
| 1490 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1491 | TestLoadTimingNotReused( |
| 1492 | load_timing_info, |
| 1493 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1494 | |
| 1495 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1496 | ASSERT_TRUE(response != NULL); |
| 1497 | |
| 1498 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1499 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1500 | |
| 1501 | std::string response_data; |
| 1502 | rv = ReadTransaction(trans.get(), &response_data); |
| 1503 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1504 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1505 | } |
| 1506 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1507 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1508 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1509 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1510 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1511 | } |
| 1512 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1513 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1514 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1515 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1518 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1519 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1520 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1521 | } |
| 1522 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1523 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1524 | // if the socket was a reused keep alive socket. |
| 1525 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1526 | MockRead read_failure(SYNCHRONOUS, |
| 1527 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1528 | "Connection: Keep-Alive\r\n" |
| 1529 | "Content-Length: 6\r\n\r\n" |
| 1530 | "Pickle"); |
| 1531 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1532 | } |
| 1533 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1534 | TEST_P(HttpNetworkTransactionTest, |
| 1535 | PreconnectErrorNotConnectedOnWrite) { |
| 1536 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1537 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1541 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1542 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1546 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1547 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1548 | } |
| 1549 | |
| 1550 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1551 | MockRead read_failure(ASYNC, OK); // EOF |
| 1552 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1553 | } |
| 1554 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1555 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1556 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1557 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1558 | MockRead read_failure(SYNCHRONOUS, |
| 1559 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1560 | "Connection: Keep-Alive\r\n" |
| 1561 | "Content-Length: 6\r\n\r\n" |
| 1562 | "Pickle"); |
| 1563 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1564 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1565 | } |
| 1566 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1567 | TEST_P(HttpNetworkTransactionTest, |
| 1568 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1569 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1570 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1571 | } |
| 1572 | |
| 1573 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1574 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1575 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1576 | } |
| 1577 | |
| 1578 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1579 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1580 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1581 | } |
| 1582 | |
| 1583 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1584 | MockRead read_failure(ASYNC, OK); // EOF |
| 1585 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1586 | } |
| 1587 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1588 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1589 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1590 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1591 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1592 | request.load_flags = 0; |
| 1593 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1594 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1595 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1597 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1598 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1599 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1600 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1601 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1603 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1604 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1607 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1609 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1610 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1611 | |
| 1612 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1613 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1614 | |
| 1615 | IPEndPoint endpoint; |
| 1616 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1617 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | // What do various browsers do when the server closes a non-keepalive |
| 1621 | // connection without sending any response header or body? |
| 1622 | // |
| 1623 | // IE7: error page |
| 1624 | // Safari 3.1.2 (Windows): error page |
| 1625 | // Firefox 3.0.1: blank page |
| 1626 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1627 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1628 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1629 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1630 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1631 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1632 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1633 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1634 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1635 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1636 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1637 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1638 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1639 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1640 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1641 | // Test that network access can be deferred and resumed. |
| 1642 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1643 | HttpRequestInfo request; |
| 1644 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1645 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1646 | request.load_flags = 0; |
| 1647 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1648 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1649 | scoped_ptr<HttpTransaction> trans( |
| 1650 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1651 | |
| 1652 | // Defer on OnBeforeNetworkStart. |
| 1653 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1654 | trans->SetBeforeNetworkStartCallback( |
| 1655 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1656 | base::Unretained(&net_start_handler))); |
| 1657 | |
| 1658 | MockRead data_reads[] = { |
| 1659 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1660 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1661 | MockRead("hello"), |
| 1662 | MockRead(SYNCHRONOUS, 0), |
| 1663 | }; |
| 1664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1666 | |
| 1667 | TestCompletionCallback callback; |
| 1668 | |
| 1669 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1671 | base::MessageLoop::current()->RunUntilIdle(); |
| 1672 | |
| 1673 | // Should have deferred for network start. |
| 1674 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1675 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1676 | |
| 1677 | trans->ResumeNetworkStart(); |
| 1678 | rv = callback.WaitForResult(); |
| 1679 | EXPECT_EQ(OK, rv); |
| 1680 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1681 | |
| 1682 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1683 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1684 | if (rv == ERR_IO_PENDING) |
| 1685 | rv = callback.WaitForResult(); |
| 1686 | EXPECT_EQ(5, rv); |
| 1687 | trans.reset(); |
| 1688 | } |
| 1689 | |
| 1690 | // Test that network use can be deferred and canceled. |
| 1691 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1692 | HttpRequestInfo request; |
| 1693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1695 | request.load_flags = 0; |
| 1696 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1697 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1698 | scoped_ptr<HttpTransaction> trans( |
| 1699 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1700 | |
| 1701 | // Defer on OnBeforeNetworkStart. |
| 1702 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1703 | trans->SetBeforeNetworkStartCallback( |
| 1704 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1705 | base::Unretained(&net_start_handler))); |
| 1706 | |
| 1707 | TestCompletionCallback callback; |
| 1708 | |
| 1709 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1711 | base::MessageLoop::current()->RunUntilIdle(); |
| 1712 | |
| 1713 | // Should have deferred for network start. |
| 1714 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1715 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1716 | } |
| 1717 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1718 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1719 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1720 | // destructor in such situations. |
| 1721 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1722 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1723 | HttpRequestInfo request; |
| 1724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1725 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1726 | request.load_flags = 0; |
| 1727 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1728 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1729 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1730 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1731 | |
| 1732 | MockRead data_reads[] = { |
| 1733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1734 | MockRead("Connection: keep-alive\r\n"), |
| 1735 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1736 | MockRead("hello"), |
| 1737 | MockRead(SYNCHRONOUS, 0), |
| 1738 | }; |
| 1739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1740 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1741 | |
| 1742 | TestCompletionCallback callback; |
| 1743 | |
| 1744 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1746 | |
| 1747 | rv = callback.WaitForResult(); |
| 1748 | EXPECT_EQ(OK, rv); |
| 1749 | |
| 1750 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1751 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1752 | if (rv == ERR_IO_PENDING) |
| 1753 | rv = callback.WaitForResult(); |
| 1754 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1755 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1756 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1757 | |
| 1758 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1759 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1760 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1761 | } |
| 1762 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1763 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1764 | HttpRequestInfo request; |
| 1765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1766 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1767 | request.load_flags = 0; |
| 1768 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1769 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1770 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1771 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1772 | |
| 1773 | MockRead data_reads[] = { |
| 1774 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1775 | MockRead("Connection: keep-alive\r\n"), |
| 1776 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1777 | MockRead(SYNCHRONOUS, 0), |
| 1778 | }; |
| 1779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1780 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1781 | |
| 1782 | TestCompletionCallback callback; |
| 1783 | |
| 1784 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1786 | |
| 1787 | rv = callback.WaitForResult(); |
| 1788 | EXPECT_EQ(OK, rv); |
| 1789 | |
| 1790 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1791 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1792 | if (rv == ERR_IO_PENDING) |
| 1793 | rv = callback.WaitForResult(); |
| 1794 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1795 | |
| 1796 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1797 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1798 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1799 | } |
| 1800 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1801 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1802 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1803 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1804 | HttpRequestInfo request; |
| 1805 | request.method = "GET"; |
| 1806 | request.url = GURL("http://www.foo.com/"); |
| 1807 | request.load_flags = 0; |
| 1808 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1809 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1810 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1811 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1812 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1813 | // Note that because all these reads happen in the same |
| 1814 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1815 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1816 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1817 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1818 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1819 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1820 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1821 | "Content-Length: 0\r\n\r\n"), |
| 1822 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1823 | "Content-Length: 5\r\n\r\n" |
| 1824 | "hello"), |
| 1825 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1826 | "Content-Length: 0\r\n\r\n"), |
| 1827 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1828 | "Content-Length: 5\r\n\r\n" |
| 1829 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1830 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1831 | MockRead("hello"), |
| 1832 | }; |
| 1833 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1834 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1835 | |
| 1836 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1837 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1838 | }; |
| 1839 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1840 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1841 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1842 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1843 | std::string response_lines[kNumUnreadBodies]; |
| 1844 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1845 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1846 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1847 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1848 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1849 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1850 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1852 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1854 | |
| 1855 | rv = callback.WaitForResult(); |
| 1856 | EXPECT_EQ(OK, rv); |
| 1857 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1858 | LoadTimingInfo load_timing_info; |
| 1859 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1860 | if (i == 0) { |
| 1861 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1862 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1863 | } else { |
| 1864 | TestLoadTimingReused(load_timing_info); |
| 1865 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1866 | } |
| 1867 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1868 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1869 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1870 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1871 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1872 | response_lines[i] = response->headers->GetStatusLine(); |
| 1873 | |
| 1874 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1875 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1876 | |
| 1877 | const char* const kStatusLines[] = { |
| 1878 | "HTTP/1.1 204 No Content", |
| 1879 | "HTTP/1.1 205 Reset Content", |
| 1880 | "HTTP/1.1 304 Not Modified", |
| 1881 | "HTTP/1.1 302 Found", |
| 1882 | "HTTP/1.1 302 Found", |
| 1883 | "HTTP/1.1 301 Moved Permanently", |
| 1884 | "HTTP/1.1 301 Moved Permanently", |
| 1885 | }; |
| 1886 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1887 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1888 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1889 | |
| 1890 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1891 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1893 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1894 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1896 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1897 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1898 | rv = callback.WaitForResult(); |
| 1899 | EXPECT_EQ(OK, rv); |
| 1900 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1901 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1902 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1903 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1904 | std::string response_data; |
| 1905 | rv = ReadTransaction(trans.get(), &response_data); |
| 1906 | EXPECT_EQ(OK, rv); |
| 1907 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1910 | // Test the request-challenge-retry sequence for basic auth. |
| 1911 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1912 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1913 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1915 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1916 | request.load_flags = 0; |
| 1917 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1918 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1919 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1920 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1921 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1922 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1923 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1924 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1925 | MockWrite( |
| 1926 | "GET / HTTP/1.1\r\n" |
| 1927 | "Host: www.example.org\r\n" |
| 1928 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1929 | }; |
| 1930 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1931 | MockRead data_reads1[] = { |
| 1932 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1933 | // Give a couple authenticate options (only the middle one is actually |
| 1934 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1935 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1936 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1937 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1938 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1939 | // Large content-length -- won't matter, as connection will be reset. |
| 1940 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1941 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1942 | }; |
| 1943 | |
| 1944 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1945 | // be issuing -- the final header line contains the credentials. |
| 1946 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1947 | MockWrite( |
| 1948 | "GET / HTTP/1.1\r\n" |
| 1949 | "Host: www.example.org\r\n" |
| 1950 | "Connection: keep-alive\r\n" |
| 1951 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1952 | }; |
| 1953 | |
| 1954 | // Lastly, the server responds with the actual content. |
| 1955 | MockRead data_reads2[] = { |
| 1956 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1957 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1958 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1959 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1960 | }; |
| 1961 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1962 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1963 | data_writes1, arraysize(data_writes1)); |
| 1964 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1965 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1966 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1967 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1969 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1971 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1972 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1973 | |
| 1974 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1975 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1976 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1977 | LoadTimingInfo load_timing_info1; |
| 1978 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1979 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1980 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1981 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 1982 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 1983 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1984 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1985 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1986 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1987 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1988 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1990 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1992 | rv = trans->RestartWithAuth( |
| 1993 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1994 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1995 | |
| 1996 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1997 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1998 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1999 | LoadTimingInfo load_timing_info2; |
| 2000 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2001 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2002 | // The load timing after restart should have a new socket ID, and times after |
| 2003 | // those of the first load timing. |
| 2004 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2005 | load_timing_info2.connect_timing.connect_start); |
| 2006 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2007 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2008 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2009 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2010 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2011 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2012 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2013 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2014 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2015 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2016 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2017 | } |
| 2018 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2019 | // Test the request-challenge-retry sequence for basic auth. |
| 2020 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2021 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2022 | HttpRequestInfo request; |
| 2023 | request.method = "GET"; |
| 2024 | request.url = GURL("http://www.example.org/"); |
| 2025 | request.load_flags = 0; |
| 2026 | |
| 2027 | TestNetLog log; |
| 2028 | MockHostResolver* resolver = new MockHostResolver(); |
| 2029 | session_deps_.net_log = &log; |
| 2030 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2031 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2032 | scoped_ptr<HttpTransaction> trans( |
| 2033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2034 | |
| 2035 | resolver->rules()->ClearRules(); |
| 2036 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2037 | |
| 2038 | MockWrite data_writes1[] = { |
| 2039 | MockWrite("GET / HTTP/1.1\r\n" |
| 2040 | "Host: www.example.org\r\n" |
| 2041 | "Connection: keep-alive\r\n\r\n"), |
| 2042 | }; |
| 2043 | |
| 2044 | MockRead data_reads1[] = { |
| 2045 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2046 | // Give a couple authenticate options (only the middle one is actually |
| 2047 | // supported). |
| 2048 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2049 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2050 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2051 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2052 | // Large content-length -- won't matter, as connection will be reset. |
| 2053 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2054 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2055 | }; |
| 2056 | |
| 2057 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2058 | // be issuing -- the final header line contains the credentials. |
| 2059 | MockWrite data_writes2[] = { |
| 2060 | MockWrite("GET / HTTP/1.1\r\n" |
| 2061 | "Host: www.example.org\r\n" |
| 2062 | "Connection: keep-alive\r\n" |
| 2063 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2064 | }; |
| 2065 | |
| 2066 | // Lastly, the server responds with the actual content. |
| 2067 | MockRead data_reads2[] = { |
| 2068 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2069 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2070 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2071 | }; |
| 2072 | |
| 2073 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2074 | data_writes1, arraysize(data_writes1)); |
| 2075 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2076 | data_writes2, arraysize(data_writes2)); |
| 2077 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2079 | |
| 2080 | TestCompletionCallback callback1; |
| 2081 | |
| 2082 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2083 | BoundNetLog()))); |
| 2084 | |
| 2085 | LoadTimingInfo load_timing_info1; |
| 2086 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2087 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2088 | |
| 2089 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2090 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2091 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2092 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2093 | |
| 2094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2095 | ASSERT_TRUE(response); |
| 2096 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2097 | |
| 2098 | IPEndPoint endpoint; |
| 2099 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2100 | ASSERT_FALSE(endpoint.address().empty()); |
| 2101 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2102 | |
| 2103 | resolver->rules()->ClearRules(); |
| 2104 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2105 | |
| 2106 | TestCompletionCallback callback2; |
| 2107 | |
| 2108 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2109 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2110 | |
| 2111 | LoadTimingInfo load_timing_info2; |
| 2112 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2113 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2114 | // The load timing after restart should have a new socket ID, and times after |
| 2115 | // those of the first load timing. |
| 2116 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2117 | load_timing_info2.connect_timing.connect_start); |
| 2118 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2119 | |
| 2120 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2121 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2122 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2123 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2124 | |
| 2125 | response = trans->GetResponseInfo(); |
| 2126 | ASSERT_TRUE(response); |
| 2127 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2128 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2129 | |
| 2130 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2131 | ASSERT_FALSE(endpoint.address().empty()); |
| 2132 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2133 | } |
| 2134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2135 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2136 | HttpRequestInfo request; |
| 2137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2138 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2139 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2140 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2141 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2142 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2144 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2145 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2146 | MockWrite( |
| 2147 | "GET / HTTP/1.1\r\n" |
| 2148 | "Host: www.example.org\r\n" |
| 2149 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2150 | }; |
| 2151 | |
| 2152 | MockRead data_reads[] = { |
| 2153 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2154 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2155 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2156 | // Large content-length -- won't matter, as connection will be reset. |
| 2157 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2158 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2159 | }; |
| 2160 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2161 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2162 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2164 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2166 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2167 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2168 | |
| 2169 | rv = callback.WaitForResult(); |
| 2170 | EXPECT_EQ(0, rv); |
| 2171 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2172 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2173 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2174 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2175 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2176 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2177 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2178 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2179 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2180 | } |
| 2181 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2182 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2183 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2184 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2185 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2187 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2188 | request.load_flags = 0; |
| 2189 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2190 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2191 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2192 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2193 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2194 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2195 | MockWrite( |
| 2196 | "GET / HTTP/1.1\r\n" |
| 2197 | "Host: www.example.org\r\n" |
| 2198 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2199 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2200 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2201 | // be issuing -- the final header line contains the credentials. |
| 2202 | MockWrite( |
| 2203 | "GET / HTTP/1.1\r\n" |
| 2204 | "Host: www.example.org\r\n" |
| 2205 | "Connection: keep-alive\r\n" |
| 2206 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2207 | }; |
| 2208 | |
| 2209 | MockRead data_reads1[] = { |
| 2210 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2211 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2212 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2213 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2214 | MockRead("Unauthorized\r\n"), |
| 2215 | |
| 2216 | // Lastly, the server responds with the actual content. |
| 2217 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2218 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2219 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2220 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2221 | }; |
| 2222 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2223 | // If there is a regression where we disconnect a Keep-Alive |
| 2224 | // connection during an auth roundtrip, we'll end up reading this. |
| 2225 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2226 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2227 | }; |
| 2228 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2229 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2230 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2231 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2232 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2233 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2234 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2236 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2237 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2238 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2240 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2242 | |
| 2243 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2244 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2245 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2246 | LoadTimingInfo load_timing_info1; |
| 2247 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2248 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2249 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2250 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2251 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2252 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2254 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2256 | rv = trans->RestartWithAuth( |
| 2257 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2259 | |
| 2260 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2261 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2262 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2263 | LoadTimingInfo load_timing_info2; |
| 2264 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2265 | TestLoadTimingReused(load_timing_info2); |
| 2266 | // The load timing after restart should have the same socket ID, and times |
| 2267 | // those of the first load timing. |
| 2268 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2269 | load_timing_info2.send_start); |
| 2270 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2271 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2272 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2273 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2274 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2275 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2276 | |
| 2277 | std::string response_data; |
| 2278 | rv = ReadTransaction(trans.get(), &response_data); |
| 2279 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2280 | |
| 2281 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2282 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2283 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2284 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2288 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2289 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2290 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2291 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2292 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2293 | request.load_flags = 0; |
| 2294 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2295 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2296 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2297 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2298 | MockWrite( |
| 2299 | "GET / HTTP/1.1\r\n" |
| 2300 | "Host: www.example.org\r\n" |
| 2301 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2302 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2303 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2304 | // be issuing -- the final header line contains the credentials. |
| 2305 | MockWrite( |
| 2306 | "GET / HTTP/1.1\r\n" |
| 2307 | "Host: www.example.org\r\n" |
| 2308 | "Connection: keep-alive\r\n" |
| 2309 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2310 | }; |
| 2311 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2312 | MockRead data_reads1[] = { |
| 2313 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2314 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2315 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2316 | |
| 2317 | // Lastly, the server responds with the actual content. |
| 2318 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2319 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2320 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2321 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2322 | }; |
| 2323 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2324 | // An incorrect reconnect would cause this to be read. |
| 2325 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2326 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2327 | }; |
| 2328 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2329 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2330 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2331 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2332 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2334 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2336 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2337 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2338 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2339 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2340 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2342 | |
| 2343 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2344 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2345 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2347 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2348 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2350 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2352 | rv = trans->RestartWithAuth( |
| 2353 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2354 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2355 | |
| 2356 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2357 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2358 | |
| 2359 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2360 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2361 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2362 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2366 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2367 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2368 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2370 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2371 | request.load_flags = 0; |
| 2372 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2373 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2374 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2375 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2376 | MockWrite( |
| 2377 | "GET / HTTP/1.1\r\n" |
| 2378 | "Host: www.example.org\r\n" |
| 2379 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2380 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2381 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2382 | // be issuing -- the final header line contains the credentials. |
| 2383 | MockWrite( |
| 2384 | "GET / HTTP/1.1\r\n" |
| 2385 | "Host: www.example.org\r\n" |
| 2386 | "Connection: keep-alive\r\n" |
| 2387 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2388 | }; |
| 2389 | |
| 2390 | // Respond with 5 kb of response body. |
| 2391 | std::string large_body_string("Unauthorized"); |
| 2392 | large_body_string.append(5 * 1024, ' '); |
| 2393 | large_body_string.append("\r\n"); |
| 2394 | |
| 2395 | MockRead data_reads1[] = { |
| 2396 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2397 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2398 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2399 | // 5134 = 12 + 5 * 1024 + 2 |
| 2400 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2401 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2402 | |
| 2403 | // Lastly, the server responds with the actual content. |
| 2404 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2406 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2407 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2408 | }; |
| 2409 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2410 | // An incorrect reconnect would cause this to be read. |
| 2411 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2412 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2413 | }; |
| 2414 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2415 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2416 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2417 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2418 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2422 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2423 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2424 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2425 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2426 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2427 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2428 | |
| 2429 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2430 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2431 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2432 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2433 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2434 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2436 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2438 | rv = trans->RestartWithAuth( |
| 2439 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2441 | |
| 2442 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2443 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2444 | |
| 2445 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2446 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2447 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2448 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2452 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2453 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2454 | HttpRequestInfo request; |
| 2455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2456 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2457 | request.load_flags = 0; |
| 2458 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2459 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2460 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2461 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2462 | MockWrite( |
| 2463 | "GET / HTTP/1.1\r\n" |
| 2464 | "Host: www.example.org\r\n" |
| 2465 | "Connection: keep-alive\r\n\r\n"), |
| 2466 | // This simulates the seemingly successful write to a closed connection |
| 2467 | // if the bug is not fixed. |
| 2468 | MockWrite( |
| 2469 | "GET / HTTP/1.1\r\n" |
| 2470 | "Host: www.example.org\r\n" |
| 2471 | "Connection: keep-alive\r\n" |
| 2472 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2473 | }; |
| 2474 | |
| 2475 | MockRead data_reads1[] = { |
| 2476 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2477 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2478 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2479 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2480 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2481 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2482 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2483 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2484 | }; |
| 2485 | |
| 2486 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2487 | // be issuing -- the final header line contains the credentials. |
| 2488 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2489 | MockWrite( |
| 2490 | "GET / HTTP/1.1\r\n" |
| 2491 | "Host: www.example.org\r\n" |
| 2492 | "Connection: keep-alive\r\n" |
| 2493 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2494 | }; |
| 2495 | |
| 2496 | // Lastly, the server responds with the actual content. |
| 2497 | MockRead data_reads2[] = { |
| 2498 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2499 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2500 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2501 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2502 | }; |
| 2503 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2504 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2505 | data_writes1, arraysize(data_writes1)); |
| 2506 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2507 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2508 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2509 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2511 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2512 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2513 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2514 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2515 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2517 | |
| 2518 | rv = callback1.WaitForResult(); |
| 2519 | EXPECT_EQ(OK, rv); |
| 2520 | |
| 2521 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2522 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2523 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2524 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2525 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2527 | rv = trans->RestartWithAuth( |
| 2528 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2530 | |
| 2531 | rv = callback2.WaitForResult(); |
| 2532 | EXPECT_EQ(OK, rv); |
| 2533 | |
| 2534 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2535 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2536 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2537 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2538 | } |
| 2539 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2540 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2541 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2542 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2543 | HttpRequestInfo request; |
| 2544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2545 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2546 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2547 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2548 | |
| 2549 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2550 | session_deps_.proxy_service = |
| 2551 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2552 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2553 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2554 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2555 | |
| 2556 | // Since we have proxy, should try to establish tunnel. |
| 2557 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2558 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2559 | "Host: www.example.org\r\n" |
| 2560 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2561 | }; |
| 2562 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2563 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2564 | // connection. |
| 2565 | MockRead data_reads1[] = { |
| 2566 | // No credentials. |
| 2567 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2568 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2569 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2570 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2571 | // Since the first connection couldn't be reused, need to establish another |
| 2572 | // once given credentials. |
| 2573 | MockWrite data_writes2[] = { |
| 2574 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2575 | // be issuing -- the final header line contains the credentials. |
| 2576 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2577 | "Host: www.example.org\r\n" |
| 2578 | "Proxy-Connection: keep-alive\r\n" |
| 2579 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2580 | |
| 2581 | MockWrite("GET / HTTP/1.1\r\n" |
| 2582 | "Host: www.example.org\r\n" |
| 2583 | "Connection: keep-alive\r\n\r\n"), |
| 2584 | }; |
| 2585 | |
| 2586 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2587 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2588 | |
| 2589 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2590 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2591 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2592 | MockRead(SYNCHRONOUS, "hello"), |
| 2593 | }; |
| 2594 | |
| 2595 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2596 | data_writes1, arraysize(data_writes1)); |
| 2597 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2598 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2599 | data_writes2, arraysize(data_writes2)); |
| 2600 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2601 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2603 | |
| 2604 | TestCompletionCallback callback1; |
| 2605 | |
| 2606 | scoped_ptr<HttpTransaction> trans( |
| 2607 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2608 | |
| 2609 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2610 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2611 | |
| 2612 | rv = callback1.WaitForResult(); |
| 2613 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2614 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2615 | log.GetEntries(&entries); |
| 2616 | size_t pos = ExpectLogContainsSomewhere( |
| 2617 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2618 | NetLog::PHASE_NONE); |
| 2619 | ExpectLogContainsSomewhere( |
| 2620 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2621 | NetLog::PHASE_NONE); |
| 2622 | |
| 2623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2624 | ASSERT_TRUE(response != NULL); |
| 2625 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2626 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2627 | EXPECT_EQ(407, response->headers->response_code()); |
| 2628 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2629 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2630 | |
| 2631 | LoadTimingInfo load_timing_info; |
| 2632 | // CONNECT requests and responses are handled at the connect job level, so |
| 2633 | // the transaction does not yet have a connection. |
| 2634 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2635 | |
| 2636 | TestCompletionCallback callback2; |
| 2637 | |
| 2638 | rv = |
| 2639 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2641 | |
| 2642 | rv = callback2.WaitForResult(); |
| 2643 | EXPECT_EQ(OK, rv); |
| 2644 | |
| 2645 | response = trans->GetResponseInfo(); |
| 2646 | ASSERT_TRUE(response != NULL); |
| 2647 | |
| 2648 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2649 | EXPECT_EQ(200, response->headers->response_code()); |
| 2650 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2651 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2652 | |
| 2653 | // The password prompt info should not be set. |
| 2654 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2655 | |
| 2656 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2657 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2658 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2659 | |
| 2660 | trans.reset(); |
| 2661 | session->CloseAllConnections(); |
| 2662 | } |
| 2663 | |
| 2664 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2665 | // that requires a restart when setting up an SSL tunnel. |
| 2666 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2667 | HttpRequestInfo request; |
| 2668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2669 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2670 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2671 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2672 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2673 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2674 | session_deps_.proxy_service = |
| 2675 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2676 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2677 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2678 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2679 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2680 | // Since we have proxy, should try to establish tunnel. |
| 2681 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2682 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2683 | "Host: www.example.org\r\n" |
| 2684 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2685 | }; |
| 2686 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2687 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2688 | // connection. |
| 2689 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2690 | // No credentials. |
| 2691 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2692 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2693 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2694 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2695 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2696 | MockWrite data_writes2[] = { |
| 2697 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2698 | // be issuing -- the final header line contains the credentials. |
| 2699 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2700 | "Host: www.example.org\r\n" |
| 2701 | "Proxy-Connection: keep-alive\r\n" |
| 2702 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2703 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2704 | MockWrite("GET / HTTP/1.1\r\n" |
| 2705 | "Host: www.example.org\r\n" |
| 2706 | "Connection: keep-alive\r\n\r\n"), |
| 2707 | }; |
| 2708 | |
| 2709 | MockRead data_reads2[] = { |
| 2710 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2711 | |
| 2712 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2713 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2714 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2715 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2716 | }; |
| 2717 | |
| 2718 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2719 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2720 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2721 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2722 | data_writes2, arraysize(data_writes2)); |
| 2723 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2724 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2727 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2728 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2729 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2730 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2732 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2734 | |
| 2735 | rv = callback1.WaitForResult(); |
| 2736 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2737 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2738 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2739 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2740 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2741 | NetLog::PHASE_NONE); |
| 2742 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2743 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2744 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2745 | NetLog::PHASE_NONE); |
| 2746 | |
| 2747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2748 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2749 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2750 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2751 | EXPECT_EQ(407, response->headers->response_code()); |
| 2752 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2753 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2754 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2755 | LoadTimingInfo load_timing_info; |
| 2756 | // CONNECT requests and responses are handled at the connect job level, so |
| 2757 | // the transaction does not yet have a connection. |
| 2758 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2760 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2762 | rv = trans->RestartWithAuth( |
| 2763 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2764 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2765 | |
| 2766 | rv = callback2.WaitForResult(); |
| 2767 | EXPECT_EQ(OK, rv); |
| 2768 | |
| 2769 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2770 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2771 | |
| 2772 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2773 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2774 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2775 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2776 | |
| 2777 | // The password prompt info should not be set. |
| 2778 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2779 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2780 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2781 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2782 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2783 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2784 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2785 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2786 | } |
| 2787 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2788 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2789 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2790 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2791 | HttpRequestInfo request; |
| 2792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2793 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2794 | // Ensure that proxy authentication is attempted even |
| 2795 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2796 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2797 | |
| 2798 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2799 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2800 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2801 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2802 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2803 | |
| 2804 | scoped_ptr<HttpTransaction> trans( |
| 2805 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2806 | |
| 2807 | // Since we have proxy, should try to establish tunnel. |
| 2808 | MockWrite data_writes1[] = { |
| 2809 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2810 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2811 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2812 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2813 | |
| 2814 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2815 | // be issuing -- the final header line contains the credentials. |
| 2816 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2817 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2818 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2819 | "Proxy-Connection: keep-alive\r\n" |
| 2820 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2821 | }; |
| 2822 | |
| 2823 | // The proxy responds to the connect with a 407, using a persistent |
| 2824 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2825 | MockRead data_reads1[] = { |
| 2826 | // No credentials. |
| 2827 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2828 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2829 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2830 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2831 | MockRead("0123456789"), |
| 2832 | |
| 2833 | // Wrong credentials (wrong password). |
| 2834 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2835 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2836 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2837 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2838 | // No response body because the test stops reading here. |
| 2839 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2840 | }; |
| 2841 | |
| 2842 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2843 | data_writes1, arraysize(data_writes1)); |
| 2844 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2845 | |
| 2846 | TestCompletionCallback callback1; |
| 2847 | |
| 2848 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2849 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2850 | |
| 2851 | rv = callback1.WaitForResult(); |
| 2852 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2853 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2854 | log.GetEntries(&entries); |
| 2855 | size_t pos = ExpectLogContainsSomewhere( |
| 2856 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2857 | NetLog::PHASE_NONE); |
| 2858 | ExpectLogContainsSomewhere( |
| 2859 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2860 | NetLog::PHASE_NONE); |
| 2861 | |
| 2862 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2863 | ASSERT_TRUE(response); |
| 2864 | ASSERT_TRUE(response->headers); |
| 2865 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2866 | EXPECT_EQ(407, response->headers->response_code()); |
| 2867 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2868 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2869 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2870 | |
| 2871 | TestCompletionCallback callback2; |
| 2872 | |
| 2873 | // Wrong password (should be "bar"). |
| 2874 | rv = |
| 2875 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2877 | |
| 2878 | rv = callback2.WaitForResult(); |
| 2879 | EXPECT_EQ(OK, rv); |
| 2880 | |
| 2881 | response = trans->GetResponseInfo(); |
| 2882 | ASSERT_TRUE(response); |
| 2883 | ASSERT_TRUE(response->headers); |
| 2884 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2885 | EXPECT_EQ(407, response->headers->response_code()); |
| 2886 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2887 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2888 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2889 | |
| 2890 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2891 | // out of scope. |
| 2892 | session->CloseAllConnections(); |
| 2893 | } |
| 2894 | |
| 2895 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2896 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2897 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2898 | HttpRequestInfo request; |
| 2899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2900 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2901 | // Ensure that proxy authentication is attempted even |
| 2902 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2903 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2904 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2905 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2906 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2907 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2908 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2909 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2911 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2912 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2913 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2914 | // Since we have proxy, should try to establish tunnel. |
| 2915 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2916 | MockWrite( |
| 2917 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2918 | "Host: www.example.org\r\n" |
| 2919 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2920 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2921 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2922 | // be issuing -- the final header line contains the credentials. |
| 2923 | MockWrite( |
| 2924 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2925 | "Host: www.example.org\r\n" |
| 2926 | "Proxy-Connection: keep-alive\r\n" |
| 2927 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2928 | }; |
| 2929 | |
| 2930 | // The proxy responds to the connect with a 407, using a persistent |
| 2931 | // connection. |
| 2932 | MockRead data_reads1[] = { |
| 2933 | // No credentials. |
| 2934 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2935 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2936 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2937 | MockRead("0123456789"), |
| 2938 | |
| 2939 | // Wrong credentials (wrong password). |
| 2940 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2941 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2942 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2943 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2944 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2945 | }; |
| 2946 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2947 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2948 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2951 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2953 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2954 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2955 | |
| 2956 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2957 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2958 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2959 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2960 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2961 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2962 | NetLog::PHASE_NONE); |
| 2963 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2964 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2965 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2966 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2968 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2969 | ASSERT_TRUE(response); |
| 2970 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2971 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2972 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2973 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2974 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2975 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2977 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
| 2979 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2980 | rv = trans->RestartWithAuth( |
| 2981 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2983 | |
| 2984 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2985 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | |
| 2987 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2988 | ASSERT_TRUE(response); |
| 2989 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2991 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2992 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2994 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2995 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2996 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2997 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2998 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2999 | } |
| 3000 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3001 | // Test the case a proxy closes a socket while the challenge body is being |
| 3002 | // drained. |
| 3003 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3004 | HttpRequestInfo request; |
| 3005 | request.method = "GET"; |
| 3006 | request.url = GURL("https://www.example.org/"); |
| 3007 | // Ensure that proxy authentication is attempted even |
| 3008 | // when the no authentication data flag is set. |
| 3009 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3010 | |
| 3011 | // Configure against proxy server "myproxy:70". |
| 3012 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3013 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3014 | |
| 3015 | scoped_ptr<HttpTransaction> trans( |
| 3016 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3017 | |
| 3018 | // Since we have proxy, should try to establish tunnel. |
| 3019 | MockWrite data_writes1[] = { |
| 3020 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3021 | "Host: www.example.org\r\n" |
| 3022 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3023 | }; |
| 3024 | |
| 3025 | // The proxy responds to the connect with a 407, using a persistent |
| 3026 | // connection. |
| 3027 | MockRead data_reads1[] = { |
| 3028 | // No credentials. |
| 3029 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3030 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3031 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3032 | // Server hands up in the middle of the body. |
| 3033 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3034 | }; |
| 3035 | |
| 3036 | MockWrite data_writes2[] = { |
| 3037 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3038 | // be issuing -- the final header line contains the credentials. |
| 3039 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3040 | "Host: www.example.org\r\n" |
| 3041 | "Proxy-Connection: keep-alive\r\n" |
| 3042 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3043 | |
| 3044 | MockWrite("GET / HTTP/1.1\r\n" |
| 3045 | "Host: www.example.org\r\n" |
| 3046 | "Connection: keep-alive\r\n\r\n"), |
| 3047 | }; |
| 3048 | |
| 3049 | MockRead data_reads2[] = { |
| 3050 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3051 | |
| 3052 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3054 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3055 | MockRead(SYNCHRONOUS, "hello"), |
| 3056 | }; |
| 3057 | |
| 3058 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3059 | data_writes1, arraysize(data_writes1)); |
| 3060 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3061 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3062 | data_writes2, arraysize(data_writes2)); |
| 3063 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3064 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3066 | |
| 3067 | TestCompletionCallback callback; |
| 3068 | |
| 3069 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3070 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3071 | |
| 3072 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3073 | ASSERT_TRUE(response); |
| 3074 | ASSERT_TRUE(response->headers); |
| 3075 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3076 | EXPECT_EQ(407, response->headers->response_code()); |
| 3077 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3078 | |
| 3079 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3080 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3081 | |
| 3082 | response = trans->GetResponseInfo(); |
| 3083 | ASSERT_TRUE(response); |
| 3084 | ASSERT_TRUE(response->headers); |
| 3085 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3086 | EXPECT_EQ(200, response->headers->response_code()); |
| 3087 | std::string body; |
| 3088 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3089 | EXPECT_EQ("hello", body); |
| 3090 | } |
| 3091 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3092 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3093 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3094 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3095 | HttpRequestInfo request; |
| 3096 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3097 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3098 | request.load_flags = 0; |
| 3099 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3100 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3101 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3102 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3103 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3104 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3105 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3106 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3107 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3108 | // Since we have proxy, should try to establish tunnel. |
| 3109 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3110 | MockWrite( |
| 3111 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3112 | "Host: www.example.org\r\n" |
| 3113 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3114 | }; |
| 3115 | |
| 3116 | // The proxy responds to the connect with a 407. |
| 3117 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3118 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3119 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3120 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3121 | MockRead("0123456789"), // Should not be reached. |
| 3122 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3123 | }; |
| 3124 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3125 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3126 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3129 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3131 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3132 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3133 | |
| 3134 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3135 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3136 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3137 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3138 | ASSERT_TRUE(response); |
| 3139 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3140 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3141 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3142 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3143 | |
| 3144 | std::string response_data; |
| 3145 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3146 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3147 | |
| 3148 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3149 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3150 | } |
| 3151 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3152 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3153 | // caller when the proxy responds to CONNECT with 407. |
| 3154 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3155 | HttpRequestInfo request; |
| 3156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3157 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3158 | request.load_flags = 0; |
| 3159 | |
| 3160 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3161 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3162 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3163 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3164 | |
| 3165 | scoped_ptr<HttpTransaction> trans( |
| 3166 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3167 | |
| 3168 | // Since we have proxy, should try to establish tunnel. |
| 3169 | MockWrite data_writes[] = { |
| 3170 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3171 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3172 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3174 | }; |
| 3175 | |
| 3176 | // The proxy responds to the connect with a 407. |
| 3177 | MockRead data_reads[] = { |
| 3178 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3179 | MockRead("X-Foo: bar\r\n"), |
| 3180 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3181 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3182 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3183 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3184 | }; |
| 3185 | |
| 3186 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3187 | arraysize(data_writes)); |
| 3188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3189 | |
| 3190 | TestCompletionCallback callback; |
| 3191 | |
| 3192 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3193 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3194 | |
| 3195 | rv = callback.WaitForResult(); |
| 3196 | EXPECT_EQ(OK, rv); |
| 3197 | |
| 3198 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3199 | ASSERT_TRUE(response); |
| 3200 | ASSERT_TRUE(response->headers); |
| 3201 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3202 | EXPECT_EQ(407, response->headers->response_code()); |
| 3203 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3204 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3205 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3206 | |
| 3207 | std::string response_data; |
| 3208 | rv = ReadTransaction(trans.get(), &response_data); |
| 3209 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3210 | |
| 3211 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3212 | session->CloseAllConnections(); |
| 3213 | } |
| 3214 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3215 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3216 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3217 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3218 | HttpRequestInfo request; |
| 3219 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3220 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3221 | request.load_flags = 0; |
| 3222 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3223 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3224 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3225 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3226 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3227 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3228 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3229 | MockWrite( |
| 3230 | "GET / HTTP/1.1\r\n" |
| 3231 | "Host: www.example.org\r\n" |
| 3232 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3233 | }; |
| 3234 | |
| 3235 | MockRead data_reads1[] = { |
| 3236 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3237 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3238 | // Large content-length -- won't matter, as connection will be reset. |
| 3239 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3240 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3241 | }; |
| 3242 | |
| 3243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3244 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3247 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3249 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3250 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3251 | |
| 3252 | rv = callback.WaitForResult(); |
| 3253 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3254 | } |
| 3255 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3256 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3257 | // through a non-authenticating proxy. The request should fail with |
| 3258 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3259 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3260 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3261 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3262 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3263 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3264 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3265 | HttpRequestInfo request; |
| 3266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3267 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3268 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3269 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3270 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3271 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3272 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3273 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3274 | // Since we have proxy, should try to establish tunnel. |
| 3275 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3276 | MockWrite( |
| 3277 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3278 | "Host: www.example.org\r\n" |
| 3279 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3280 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3281 | MockWrite( |
| 3282 | "GET / HTTP/1.1\r\n" |
| 3283 | "Host: www.example.org\r\n" |
| 3284 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3285 | }; |
| 3286 | |
| 3287 | MockRead data_reads1[] = { |
| 3288 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3289 | |
| 3290 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3291 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3292 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3293 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3294 | }; |
| 3295 | |
| 3296 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3297 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3298 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3299 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3300 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3302 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3303 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3304 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3307 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3308 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3309 | |
| 3310 | rv = callback1.WaitForResult(); |
| 3311 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3312 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3313 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3314 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3315 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3316 | NetLog::PHASE_NONE); |
| 3317 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3318 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3319 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3320 | NetLog::PHASE_NONE); |
| 3321 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3322 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3323 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3324 | // that uses non-persistent connections. |
| 3325 | TEST_P(HttpNetworkTransactionTest, |
| 3326 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3327 | HttpRequestInfo request; |
| 3328 | request.method = "GET"; |
| 3329 | request.url = GURL("https://www.example.org/"); |
| 3330 | |
| 3331 | // Configure against proxy server "myproxy:70". |
| 3332 | session_deps_.proxy_service = |
| 3333 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3334 | |
| 3335 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3336 | new HttpAuthHandlerMock::Factory()); |
| 3337 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3338 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3339 | mock_handler->set_allows_default_credentials(true); |
| 3340 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3341 | HttpAuth::AUTH_PROXY); |
| 3342 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3343 | |
| 3344 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3345 | NetLog net_log; |
| 3346 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3347 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3348 | |
| 3349 | // Since we have proxy, should try to establish tunnel. |
| 3350 | MockWrite data_writes1[] = { |
| 3351 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3352 | "Host: www.example.org\r\n" |
| 3353 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3354 | }; |
| 3355 | |
| 3356 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3357 | // connection. |
| 3358 | MockRead data_reads1[] = { |
| 3359 | // No credentials. |
| 3360 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3361 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3362 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3363 | }; |
| 3364 | |
| 3365 | // Since the first connection couldn't be reused, need to establish another |
| 3366 | // once given credentials. |
| 3367 | MockWrite data_writes2[] = { |
| 3368 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3369 | // be issuing -- the final header line contains the credentials. |
| 3370 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3371 | "Host: www.example.org\r\n" |
| 3372 | "Proxy-Connection: keep-alive\r\n" |
| 3373 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3374 | |
| 3375 | MockWrite("GET / HTTP/1.1\r\n" |
| 3376 | "Host: www.example.org\r\n" |
| 3377 | "Connection: keep-alive\r\n\r\n"), |
| 3378 | }; |
| 3379 | |
| 3380 | MockRead data_reads2[] = { |
| 3381 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3382 | |
| 3383 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3384 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3385 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3386 | MockRead(SYNCHRONOUS, "hello"), |
| 3387 | }; |
| 3388 | |
| 3389 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3390 | data_writes1, arraysize(data_writes1)); |
| 3391 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3392 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3393 | data_writes2, arraysize(data_writes2)); |
| 3394 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3395 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3397 | |
| 3398 | scoped_ptr<HttpTransaction> trans( |
| 3399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3400 | |
| 3401 | TestCompletionCallback callback; |
| 3402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3403 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3404 | |
| 3405 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3406 | ASSERT_TRUE(response); |
| 3407 | ASSERT_TRUE(response->headers); |
| 3408 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3409 | EXPECT_EQ(407, response->headers->response_code()); |
| 3410 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3411 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3412 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3413 | |
| 3414 | LoadTimingInfo load_timing_info; |
| 3415 | // CONNECT requests and responses are handled at the connect job level, so |
| 3416 | // the transaction does not yet have a connection. |
| 3417 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3418 | |
| 3419 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3420 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3421 | response = trans->GetResponseInfo(); |
| 3422 | ASSERT_TRUE(response); |
| 3423 | ASSERT_TRUE(response->headers); |
| 3424 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3425 | EXPECT_EQ(200, response->headers->response_code()); |
| 3426 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3427 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3428 | |
| 3429 | // The password prompt info should not be set. |
| 3430 | EXPECT_FALSE(response->auth_challenge); |
| 3431 | |
| 3432 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3433 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3434 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3435 | |
| 3436 | trans.reset(); |
| 3437 | session->CloseAllConnections(); |
| 3438 | } |
| 3439 | |
| 3440 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3441 | // that hangs up when credentials are initially sent. |
| 3442 | TEST_P(HttpNetworkTransactionTest, |
| 3443 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3444 | HttpRequestInfo request; |
| 3445 | request.method = "GET"; |
| 3446 | request.url = GURL("https://www.example.org/"); |
| 3447 | |
| 3448 | // Configure against proxy server "myproxy:70". |
| 3449 | session_deps_.proxy_service = |
| 3450 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3451 | |
| 3452 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3453 | new HttpAuthHandlerMock::Factory()); |
| 3454 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3455 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3456 | mock_handler->set_allows_default_credentials(true); |
| 3457 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3458 | HttpAuth::AUTH_PROXY); |
| 3459 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3460 | |
| 3461 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3462 | NetLog net_log; |
| 3463 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3464 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3465 | |
| 3466 | // Should try to establish tunnel. |
| 3467 | MockWrite data_writes1[] = { |
| 3468 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3469 | "Host: www.example.org\r\n" |
| 3470 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3471 | |
| 3472 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3473 | "Host: www.example.org\r\n" |
| 3474 | "Proxy-Connection: keep-alive\r\n" |
| 3475 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3476 | }; |
| 3477 | |
| 3478 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3479 | // connection. |
| 3480 | MockRead data_reads1[] = { |
| 3481 | // No credentials. |
| 3482 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3483 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3484 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3485 | }; |
| 3486 | |
| 3487 | // Since the first connection was closed, need to establish another once given |
| 3488 | // credentials. |
| 3489 | MockWrite data_writes2[] = { |
| 3490 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3491 | "Host: www.example.org\r\n" |
| 3492 | "Proxy-Connection: keep-alive\r\n" |
| 3493 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3494 | |
| 3495 | MockWrite("GET / HTTP/1.1\r\n" |
| 3496 | "Host: www.example.org\r\n" |
| 3497 | "Connection: keep-alive\r\n\r\n"), |
| 3498 | }; |
| 3499 | |
| 3500 | MockRead data_reads2[] = { |
| 3501 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3502 | |
| 3503 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3504 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3505 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3506 | MockRead(SYNCHRONOUS, "hello"), |
| 3507 | }; |
| 3508 | |
| 3509 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3510 | data_writes1, arraysize(data_writes1)); |
| 3511 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3512 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3513 | data_writes2, arraysize(data_writes2)); |
| 3514 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3515 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3517 | |
| 3518 | scoped_ptr<HttpTransaction> trans( |
| 3519 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3520 | |
| 3521 | TestCompletionCallback callback; |
| 3522 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3523 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3524 | |
| 3525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3526 | ASSERT_TRUE(response); |
| 3527 | ASSERT_TRUE(response->headers); |
| 3528 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3529 | EXPECT_EQ(407, response->headers->response_code()); |
| 3530 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3531 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3532 | EXPECT_FALSE(response->auth_challenge); |
| 3533 | |
| 3534 | LoadTimingInfo load_timing_info; |
| 3535 | // CONNECT requests and responses are handled at the connect job level, so |
| 3536 | // the transaction does not yet have a connection. |
| 3537 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3538 | |
| 3539 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3540 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3541 | |
| 3542 | response = trans->GetResponseInfo(); |
| 3543 | ASSERT_TRUE(response); |
| 3544 | ASSERT_TRUE(response->headers); |
| 3545 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3546 | EXPECT_EQ(200, response->headers->response_code()); |
| 3547 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3548 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3549 | |
| 3550 | // The password prompt info should not be set. |
| 3551 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3552 | |
| 3553 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3554 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3555 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3556 | |
| 3557 | trans.reset(); |
| 3558 | session->CloseAllConnections(); |
| 3559 | } |
| 3560 | |
| 3561 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3562 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3563 | // they are retried. |
| 3564 | TEST_P(HttpNetworkTransactionTest, |
| 3565 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3566 | HttpRequestInfo request; |
| 3567 | request.method = "GET"; |
| 3568 | request.url = GURL("https://www.example.org/"); |
| 3569 | |
| 3570 | // Configure against proxy server "myproxy:70". |
| 3571 | session_deps_.proxy_service = |
| 3572 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3573 | |
| 3574 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3575 | new HttpAuthHandlerMock::Factory()); |
| 3576 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3577 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3578 | mock_handler->set_allows_default_credentials(true); |
| 3579 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3580 | HttpAuth::AUTH_PROXY); |
| 3581 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3582 | |
| 3583 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3584 | NetLog net_log; |
| 3585 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3586 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3587 | |
| 3588 | // Should try to establish tunnel. |
| 3589 | MockWrite data_writes1[] = { |
| 3590 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3591 | "Host: www.example.org\r\n" |
| 3592 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3593 | |
| 3594 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3595 | "Host: www.example.org\r\n" |
| 3596 | "Proxy-Connection: keep-alive\r\n" |
| 3597 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3598 | }; |
| 3599 | |
| 3600 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3601 | // second request is sent. |
| 3602 | MockRead data_reads1[] = { |
| 3603 | // No credentials. |
| 3604 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3605 | MockRead("Content-Length: 0\r\n"), |
| 3606 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3607 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3608 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3609 | }; |
| 3610 | |
| 3611 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3612 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3613 | // request. |
| 3614 | MockWrite data_writes2[] = { |
| 3615 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3616 | "Host: www.example.org\r\n" |
| 3617 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3618 | }; |
| 3619 | |
| 3620 | // The proxy, having had more than enough of us, just hangs up. |
| 3621 | MockRead data_reads2[] = { |
| 3622 | // No credentials. |
| 3623 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3624 | }; |
| 3625 | |
| 3626 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3627 | data_writes1, arraysize(data_writes1)); |
| 3628 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3629 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3630 | data_writes2, arraysize(data_writes2)); |
| 3631 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3632 | |
| 3633 | scoped_ptr<HttpTransaction> trans( |
| 3634 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3635 | |
| 3636 | TestCompletionCallback callback; |
| 3637 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3638 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3639 | |
| 3640 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3641 | ASSERT_TRUE(response); |
| 3642 | ASSERT_TRUE(response->headers); |
| 3643 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3644 | EXPECT_EQ(407, response->headers->response_code()); |
| 3645 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3646 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3647 | EXPECT_FALSE(response->auth_challenge); |
| 3648 | |
| 3649 | LoadTimingInfo load_timing_info; |
| 3650 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3651 | |
| 3652 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3653 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3654 | |
| 3655 | trans.reset(); |
| 3656 | session->CloseAllConnections(); |
| 3657 | } |
| 3658 | |
| 3659 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3660 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3661 | // again they are retried. |
| 3662 | TEST_P(HttpNetworkTransactionTest, |
| 3663 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3664 | HttpRequestInfo request; |
| 3665 | request.method = "GET"; |
| 3666 | request.url = GURL("https://www.example.org/"); |
| 3667 | |
| 3668 | // Configure against proxy server "myproxy:70". |
| 3669 | session_deps_.proxy_service = |
| 3670 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3671 | |
| 3672 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3673 | new HttpAuthHandlerMock::Factory()); |
| 3674 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3675 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3676 | mock_handler->set_allows_default_credentials(true); |
| 3677 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3678 | HttpAuth::AUTH_PROXY); |
| 3679 | // Add another handler for the second challenge. It supports default |
| 3680 | // credentials, but they shouldn't be used, since they were already tried. |
| 3681 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3682 | mock_handler->set_allows_default_credentials(true); |
| 3683 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3684 | HttpAuth::AUTH_PROXY); |
| 3685 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3686 | |
| 3687 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3688 | NetLog net_log; |
| 3689 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3690 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3691 | |
| 3692 | // Should try to establish tunnel. |
| 3693 | MockWrite data_writes1[] = { |
| 3694 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3695 | "Host: www.example.org\r\n" |
| 3696 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3697 | }; |
| 3698 | |
| 3699 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3700 | // connection. |
| 3701 | MockRead data_reads1[] = { |
| 3702 | // No credentials. |
| 3703 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3704 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3705 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3706 | }; |
| 3707 | |
| 3708 | // Since the first connection was closed, need to establish another once given |
| 3709 | // credentials. |
| 3710 | MockWrite data_writes2[] = { |
| 3711 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3712 | "Host: www.example.org\r\n" |
| 3713 | "Proxy-Connection: keep-alive\r\n" |
| 3714 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3715 | }; |
| 3716 | |
| 3717 | MockRead data_reads2[] = { |
| 3718 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3719 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3720 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3721 | }; |
| 3722 | |
| 3723 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3724 | data_writes1, arraysize(data_writes1)); |
| 3725 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3726 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3727 | data_writes2, arraysize(data_writes2)); |
| 3728 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3729 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3731 | |
| 3732 | scoped_ptr<HttpTransaction> trans( |
| 3733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3734 | |
| 3735 | TestCompletionCallback callback; |
| 3736 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3737 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3738 | |
| 3739 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3740 | ASSERT_TRUE(response); |
| 3741 | ASSERT_TRUE(response->headers); |
| 3742 | EXPECT_EQ(407, response->headers->response_code()); |
| 3743 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3744 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3745 | EXPECT_FALSE(response->auth_challenge); |
| 3746 | |
| 3747 | LoadTimingInfo load_timing_info; |
| 3748 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3749 | |
| 3750 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3751 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3752 | response = trans->GetResponseInfo(); |
| 3753 | ASSERT_TRUE(response); |
| 3754 | ASSERT_TRUE(response->headers); |
| 3755 | EXPECT_EQ(407, response->headers->response_code()); |
| 3756 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3757 | EXPECT_TRUE(response->auth_challenge); |
| 3758 | |
| 3759 | trans.reset(); |
| 3760 | session->CloseAllConnections(); |
| 3761 | } |
| 3762 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3763 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3764 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3765 | HttpRequestInfo request1; |
| 3766 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3767 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3768 | |
| 3769 | HttpRequestInfo request2; |
| 3770 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3771 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3772 | |
| 3773 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3774 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3775 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3776 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3777 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3778 | |
| 3779 | // Since we have proxy, should try to establish tunnel. |
| 3780 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3781 | MockWrite( |
| 3782 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3783 | "Host: www.example.org\r\n" |
| 3784 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3785 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3786 | MockWrite( |
| 3787 | "GET /1 HTTP/1.1\r\n" |
| 3788 | "Host: www.example.org\r\n" |
| 3789 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3790 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3791 | MockWrite( |
| 3792 | "GET /2 HTTP/1.1\r\n" |
| 3793 | "Host: www.example.org\r\n" |
| 3794 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3795 | }; |
| 3796 | |
| 3797 | // The proxy responds to the connect with a 407, using a persistent |
| 3798 | // connection. |
| 3799 | MockRead data_reads1[] = { |
| 3800 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3801 | |
| 3802 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3803 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3804 | MockRead(SYNCHRONOUS, "1"), |
| 3805 | |
| 3806 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3807 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3808 | MockRead(SYNCHRONOUS, "22"), |
| 3809 | }; |
| 3810 | |
| 3811 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3812 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3814 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3815 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3816 | |
| 3817 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3818 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3819 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3820 | |
| 3821 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3822 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3823 | |
| 3824 | rv = callback1.WaitForResult(); |
| 3825 | EXPECT_EQ(OK, rv); |
| 3826 | |
| 3827 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3828 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3829 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3830 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3831 | |
| 3832 | LoadTimingInfo load_timing_info1; |
| 3833 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3834 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3835 | |
| 3836 | trans1.reset(); |
| 3837 | |
| 3838 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3839 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3841 | |
| 3842 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3844 | |
| 3845 | rv = callback2.WaitForResult(); |
| 3846 | EXPECT_EQ(OK, rv); |
| 3847 | |
| 3848 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3849 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3850 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3851 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3852 | |
| 3853 | LoadTimingInfo load_timing_info2; |
| 3854 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3855 | TestLoadTimingReused(load_timing_info2); |
| 3856 | |
| 3857 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3858 | |
| 3859 | trans2.reset(); |
| 3860 | session->CloseAllConnections(); |
| 3861 | } |
| 3862 | |
| 3863 | // 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] | 3864 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3865 | HttpRequestInfo request1; |
| 3866 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3867 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3868 | |
| 3869 | HttpRequestInfo request2; |
| 3870 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3871 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3872 | |
| 3873 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3874 | session_deps_.proxy_service = |
| 3875 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3876 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3877 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3878 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3879 | |
| 3880 | // Since we have proxy, should try to establish tunnel. |
| 3881 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3882 | MockWrite( |
| 3883 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3884 | "Host: www.example.org\r\n" |
| 3885 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3886 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3887 | MockWrite( |
| 3888 | "GET /1 HTTP/1.1\r\n" |
| 3889 | "Host: www.example.org\r\n" |
| 3890 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3891 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3892 | MockWrite( |
| 3893 | "GET /2 HTTP/1.1\r\n" |
| 3894 | "Host: www.example.org\r\n" |
| 3895 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3896 | }; |
| 3897 | |
| 3898 | // The proxy responds to the connect with a 407, using a persistent |
| 3899 | // connection. |
| 3900 | MockRead data_reads1[] = { |
| 3901 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3902 | |
| 3903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3904 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3905 | MockRead(SYNCHRONOUS, "1"), |
| 3906 | |
| 3907 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3908 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3909 | MockRead(SYNCHRONOUS, "22"), |
| 3910 | }; |
| 3911 | |
| 3912 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3913 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3914 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3915 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3916 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3917 | |
| 3918 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3919 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3920 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3921 | |
| 3922 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3924 | |
| 3925 | rv = callback1.WaitForResult(); |
| 3926 | EXPECT_EQ(OK, rv); |
| 3927 | |
| 3928 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3929 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3930 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3931 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3932 | |
| 3933 | LoadTimingInfo load_timing_info1; |
| 3934 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3935 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3936 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3937 | |
| 3938 | trans1.reset(); |
| 3939 | |
| 3940 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3941 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3942 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3943 | |
| 3944 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3945 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3946 | |
| 3947 | rv = callback2.WaitForResult(); |
| 3948 | EXPECT_EQ(OK, rv); |
| 3949 | |
| 3950 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3951 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3952 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3953 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3954 | |
| 3955 | LoadTimingInfo load_timing_info2; |
| 3956 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3957 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3958 | |
| 3959 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3960 | |
| 3961 | trans2.reset(); |
| 3962 | session->CloseAllConnections(); |
| 3963 | } |
| 3964 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3965 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3966 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3967 | HttpRequestInfo request; |
| 3968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3969 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3970 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3971 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3972 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3973 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3974 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3975 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3976 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3977 | // Since we have proxy, should use full url |
| 3978 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3979 | MockWrite( |
| 3980 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3981 | "Host: www.example.org\r\n" |
| 3982 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3983 | }; |
| 3984 | |
| 3985 | MockRead data_reads1[] = { |
| 3986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3987 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3988 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3990 | }; |
| 3991 | |
| 3992 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3993 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3995 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3998 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3999 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4000 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4001 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4003 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4005 | |
| 4006 | rv = callback1.WaitForResult(); |
| 4007 | EXPECT_EQ(OK, rv); |
| 4008 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4009 | LoadTimingInfo load_timing_info; |
| 4010 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4011 | TestLoadTimingNotReused(load_timing_info, |
| 4012 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4013 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4014 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4015 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4016 | |
| 4017 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4018 | EXPECT_EQ(200, response->headers->response_code()); |
| 4019 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4020 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4021 | |
| 4022 | // The password prompt info should not be set. |
| 4023 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4024 | } |
| 4025 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4026 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4027 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4028 | HttpRequestInfo request; |
| 4029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4030 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4031 | request.load_flags = 0; |
| 4032 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4033 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4034 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4035 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4036 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4037 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4038 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4039 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4040 | scoped_ptr<SpdyFrame> req( |
| 4041 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4042 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4043 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4044 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4045 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4046 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4047 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4048 | }; |
| 4049 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4050 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4051 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4052 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4053 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4054 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4055 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4058 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4059 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4060 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4063 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4064 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4065 | |
| 4066 | rv = callback1.WaitForResult(); |
| 4067 | EXPECT_EQ(OK, rv); |
| 4068 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4069 | LoadTimingInfo load_timing_info; |
| 4070 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4071 | TestLoadTimingNotReused(load_timing_info, |
| 4072 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4073 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4075 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4076 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4077 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4078 | |
| 4079 | std::string response_data; |
| 4080 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4081 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4082 | } |
| 4083 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4084 | // Verifies that a session which races and wins against the owning transaction |
| 4085 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4086 | // Regression test for crbug.com/334413. |
| 4087 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4088 | HttpRequestInfo request; |
| 4089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4090 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4091 | request.load_flags = 0; |
| 4092 | |
| 4093 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4094 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4095 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4096 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4097 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4098 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4099 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4100 | scoped_ptr<SpdyFrame> req( |
| 4101 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4102 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4103 | |
| 4104 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4105 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4106 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4107 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4108 | }; |
| 4109 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4110 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4111 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4112 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4113 | |
| 4114 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4115 | ssl.SetNextProto(GetParam()); |
| 4116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4117 | |
| 4118 | TestCompletionCallback callback1; |
| 4119 | |
| 4120 | scoped_ptr<HttpTransaction> trans( |
| 4121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4122 | |
| 4123 | // Stall the hostname resolution begun by the transaction. |
| 4124 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4125 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4126 | |
| 4127 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4129 | |
| 4130 | // Race a session to the proxy, which completes first. |
| 4131 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4132 | SpdySessionKey key( |
| 4133 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4134 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4135 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4136 | |
| 4137 | // Unstall the resolution begun by the transaction. |
| 4138 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4139 | session_deps_.host_resolver->ResolveAllPending(); |
| 4140 | |
| 4141 | EXPECT_FALSE(callback1.have_result()); |
| 4142 | rv = callback1.WaitForResult(); |
| 4143 | EXPECT_EQ(OK, rv); |
| 4144 | |
| 4145 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4146 | ASSERT_TRUE(response != NULL); |
| 4147 | ASSERT_TRUE(response->headers.get() != NULL); |
| 4148 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4149 | |
| 4150 | std::string response_data; |
| 4151 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4152 | EXPECT_EQ(kUploadData, response_data); |
| 4153 | } |
| 4154 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4155 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4156 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4157 | HttpRequestInfo request; |
| 4158 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4159 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4160 | request.load_flags = 0; |
| 4161 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4162 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4163 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4164 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4165 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4166 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4167 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4168 | // The first request will be a bare GET, the second request will be a |
| 4169 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4170 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4171 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4172 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4173 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4174 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4175 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4176 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4177 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4178 | false, |
| 4179 | 3, |
| 4180 | LOWEST, |
| 4181 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4182 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4183 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4184 | }; |
| 4185 | |
| 4186 | // The first response is a 407 proxy authentication challenge, and the second |
| 4187 | // response will be a 200 response since the second request includes a valid |
| 4188 | // Authorization header. |
| 4189 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4190 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4191 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4192 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4193 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4194 | "407 Proxy Authentication Required", |
| 4195 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4196 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4197 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4198 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4199 | scoped_ptr<SpdyFrame> resp_data( |
| 4200 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4201 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4202 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4203 | CreateMockRead(*resp_authentication, 1), |
| 4204 | CreateMockRead(*body_authentication, 2), |
| 4205 | CreateMockRead(*resp_data, 4), |
| 4206 | CreateMockRead(*body_data, 5), |
| 4207 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4208 | }; |
| 4209 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4210 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4211 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4212 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4213 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4214 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4215 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4218 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4219 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4220 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4221 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4223 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4225 | |
| 4226 | rv = callback1.WaitForResult(); |
| 4227 | EXPECT_EQ(OK, rv); |
| 4228 | |
| 4229 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4230 | |
| 4231 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4232 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4233 | EXPECT_EQ(407, response->headers->response_code()); |
| 4234 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4235 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4237 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4239 | rv = trans->RestartWithAuth( |
| 4240 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4242 | |
| 4243 | rv = callback2.WaitForResult(); |
| 4244 | EXPECT_EQ(OK, rv); |
| 4245 | |
| 4246 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4247 | |
| 4248 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4249 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4250 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4251 | // The password prompt info should not be set. |
| 4252 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4253 | } |
| 4254 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4255 | // 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] | 4256 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4257 | HttpRequestInfo request; |
| 4258 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4259 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4260 | request.load_flags = 0; |
| 4261 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4262 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4263 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4264 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4265 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4266 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4267 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4268 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4270 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4271 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4272 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4273 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4274 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4275 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4276 | const char get[] = |
| 4277 | "GET / HTTP/1.1\r\n" |
| 4278 | "Host: www.example.org\r\n" |
| 4279 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4280 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4281 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4282 | scoped_ptr<SpdyFrame> conn_resp( |
| 4283 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4284 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4285 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4286 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4287 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4288 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4289 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4290 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4291 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4292 | |
| 4293 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4294 | CreateMockWrite(*connect, 0), |
| 4295 | CreateMockWrite(*wrapped_get, 2), |
| 4296 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4297 | }; |
| 4298 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4299 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4300 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4301 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4302 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4303 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4304 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4305 | }; |
| 4306 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4307 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4308 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4309 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4310 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4311 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4312 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4314 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4317 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4319 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4321 | |
| 4322 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4323 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4324 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4325 | LoadTimingInfo load_timing_info; |
| 4326 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4327 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4328 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4329 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4330 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4331 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4332 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4333 | |
| 4334 | std::string response_data; |
| 4335 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4336 | EXPECT_EQ("1234567890", response_data); |
| 4337 | } |
| 4338 | |
| 4339 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4340 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4341 | HttpRequestInfo request; |
| 4342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4343 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4344 | request.load_flags = 0; |
| 4345 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4346 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4347 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4348 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4349 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4350 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4351 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4352 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4354 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4355 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4356 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4357 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4358 | // fetch https://www.example.org/ via SPDY |
| 4359 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4360 | scoped_ptr<SpdyFrame> get( |
| 4361 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4362 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4363 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4364 | scoped_ptr<SpdyFrame> conn_resp( |
| 4365 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4366 | scoped_ptr<SpdyFrame> get_resp( |
| 4367 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4368 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4369 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 4370 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4371 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4372 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4373 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4374 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4375 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4376 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4377 | |
| 4378 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4379 | CreateMockWrite(*connect, 0), |
| 4380 | CreateMockWrite(*wrapped_get, 2), |
| 4381 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4382 | CreateMockWrite(*window_update_body, 7), |
| 4383 | }; |
| 4384 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4385 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4386 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4387 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4388 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4389 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4390 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4391 | }; |
| 4392 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4393 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4394 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4395 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4396 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4397 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4398 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4400 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4401 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4404 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4406 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4407 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4408 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4409 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4410 | base::MessageLoop::current()->RunUntilIdle(); |
| 4411 | // Now allow the read of the response to complete. |
| 4412 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4413 | rv = callback1.WaitForResult(); |
| 4414 | EXPECT_EQ(OK, rv); |
| 4415 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4416 | LoadTimingInfo load_timing_info; |
| 4417 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4418 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4419 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4420 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4421 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4422 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4423 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4424 | |
| 4425 | std::string response_data; |
| 4426 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4427 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4431 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4432 | HttpRequestInfo request; |
| 4433 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4434 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4435 | request.load_flags = 0; |
| 4436 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4437 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4438 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4439 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4440 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4441 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4442 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4443 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4445 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4446 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4447 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4448 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4449 | scoped_ptr<SpdyFrame> get( |
| 4450 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4451 | |
| 4452 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4453 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4454 | }; |
| 4455 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4456 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4457 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4458 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4459 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4460 | }; |
| 4461 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4462 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4463 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4465 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4466 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4467 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4469 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4470 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4473 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4475 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4476 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4477 | |
| 4478 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4479 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4480 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4481 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4482 | } |
| 4483 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4484 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4485 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4486 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4487 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4488 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4489 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4490 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4491 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4492 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4493 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4494 | |
| 4495 | HttpRequestInfo request1; |
| 4496 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4497 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4498 | request1.load_flags = 0; |
| 4499 | |
| 4500 | HttpRequestInfo request2; |
| 4501 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4502 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4503 | request2.load_flags = 0; |
| 4504 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4505 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4506 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4507 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4508 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4509 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4510 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4511 | // Fetch https://www.example.org/ via HTTP. |
| 4512 | const char get1[] = |
| 4513 | "GET / HTTP/1.1\r\n" |
| 4514 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4515 | "Connection: keep-alive\r\n\r\n"; |
| 4516 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4517 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4518 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4519 | "Content-Length: 1\r\n\r\n"; |
| 4520 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4521 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4522 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4523 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4524 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4525 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4526 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4527 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4528 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4529 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4530 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 4531 | if (GetParam() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4532 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4533 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4534 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4535 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4536 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4537 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4538 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4539 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4540 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4541 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4542 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4543 | // Fetch https://mail.example.org/ via HTTP. |
| 4544 | const char get2[] = |
| 4545 | "GET / HTTP/1.1\r\n" |
| 4546 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4547 | "Connection: keep-alive\r\n\r\n"; |
| 4548 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4549 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4550 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4551 | "Content-Length: 2\r\n\r\n"; |
| 4552 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4553 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4554 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4555 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4556 | |
| 4557 | MockWrite spdy_writes[] = { |
| 4558 | CreateMockWrite(*connect1, 0), |
| 4559 | CreateMockWrite(*wrapped_get1, 2), |
| 4560 | CreateMockWrite(*connect2, 5), |
| 4561 | CreateMockWrite(*wrapped_get2, 7), |
| 4562 | }; |
| 4563 | |
| 4564 | MockRead spdy_reads[] = { |
| 4565 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4566 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4567 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4568 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4569 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4570 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4571 | MockRead(ASYNC, 0, 10), |
| 4572 | }; |
| 4573 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4574 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4575 | arraysize(spdy_writes)); |
| 4576 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4577 | |
| 4578 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4579 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4581 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4583 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4585 | |
| 4586 | TestCompletionCallback callback; |
| 4587 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4588 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4589 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4590 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4591 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4592 | |
| 4593 | LoadTimingInfo load_timing_info; |
| 4594 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4595 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4596 | |
| 4597 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4598 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4599 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4600 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4601 | |
| 4602 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4603 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4604 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4605 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4606 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4607 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4609 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4610 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4611 | |
| 4612 | LoadTimingInfo load_timing_info2; |
| 4613 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4614 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4615 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4616 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4617 | |
| 4618 | // The requests should have different IDs, since they each are using their own |
| 4619 | // separate stream. |
| 4620 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4621 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4622 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4623 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4627 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4628 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4629 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4630 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4631 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4632 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4633 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4634 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4635 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4636 | |
| 4637 | HttpRequestInfo request1; |
| 4638 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4639 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4640 | request1.load_flags = 0; |
| 4641 | |
| 4642 | HttpRequestInfo request2; |
| 4643 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4644 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4645 | request2.load_flags = 0; |
| 4646 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4647 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4648 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4649 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4650 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4651 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4652 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4653 | // Fetch https://www.example.org/ via HTTP. |
| 4654 | const char get1[] = |
| 4655 | "GET / HTTP/1.1\r\n" |
| 4656 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4657 | "Connection: keep-alive\r\n\r\n"; |
| 4658 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4659 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4660 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4661 | "Content-Length: 1\r\n\r\n"; |
| 4662 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4663 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4664 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4665 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4666 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4667 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4668 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4669 | // Fetch https://www.example.org/2 via HTTP. |
| 4670 | const char get2[] = |
| 4671 | "GET /2 HTTP/1.1\r\n" |
| 4672 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4673 | "Connection: keep-alive\r\n\r\n"; |
| 4674 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4675 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4676 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4677 | "Content-Length: 2\r\n\r\n"; |
| 4678 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4679 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4680 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4681 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4682 | |
| 4683 | MockWrite spdy_writes[] = { |
| 4684 | CreateMockWrite(*connect1, 0), |
| 4685 | CreateMockWrite(*wrapped_get1, 2), |
| 4686 | CreateMockWrite(*wrapped_get2, 5), |
| 4687 | }; |
| 4688 | |
| 4689 | MockRead spdy_reads[] = { |
| 4690 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4691 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4692 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4693 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4694 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4695 | MockRead(ASYNC, 0, 8), |
| 4696 | }; |
| 4697 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4698 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4699 | arraysize(spdy_writes)); |
| 4700 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4701 | |
| 4702 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4703 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4705 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4706 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4707 | |
| 4708 | TestCompletionCallback callback; |
| 4709 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4710 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4711 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4712 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4713 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4714 | |
| 4715 | rv = callback.WaitForResult(); |
| 4716 | EXPECT_EQ(OK, rv); |
| 4717 | |
| 4718 | LoadTimingInfo load_timing_info; |
| 4719 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4720 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4721 | |
| 4722 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4723 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4724 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4725 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4726 | |
| 4727 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4728 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4729 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4730 | trans.reset(); |
| 4731 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4732 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4734 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4735 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4736 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4737 | rv = callback.WaitForResult(); |
| 4738 | EXPECT_EQ(OK, rv); |
| 4739 | |
| 4740 | LoadTimingInfo load_timing_info2; |
| 4741 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4742 | TestLoadTimingReused(load_timing_info2); |
| 4743 | |
| 4744 | // The requests should have the same ID. |
| 4745 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4746 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4747 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4751 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4752 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4753 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4754 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4755 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4756 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4757 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4758 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4759 | |
| 4760 | HttpRequestInfo request1; |
| 4761 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4762 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4763 | request1.load_flags = 0; |
| 4764 | |
| 4765 | HttpRequestInfo request2; |
| 4766 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4767 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4768 | request2.load_flags = 0; |
| 4769 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4770 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4771 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4772 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4773 | scoped_ptr<SpdyFrame> get1( |
| 4774 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4775 | scoped_ptr<SpdyFrame> get_resp1( |
| 4776 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4777 | scoped_ptr<SpdyFrame> body1( |
| 4778 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4779 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4780 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4781 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4782 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4783 | scoped_ptr<SpdyFrame> get2( |
| 4784 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4785 | scoped_ptr<SpdyFrame> get_resp2( |
| 4786 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4787 | scoped_ptr<SpdyFrame> body2( |
| 4788 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4789 | |
| 4790 | MockWrite spdy_writes[] = { |
| 4791 | CreateMockWrite(*get1, 0), |
| 4792 | CreateMockWrite(*get2, 3), |
| 4793 | }; |
| 4794 | |
| 4795 | MockRead spdy_reads[] = { |
| 4796 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4797 | CreateMockRead(*body1, 2, ASYNC), |
| 4798 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4799 | CreateMockRead(*body2, 5, ASYNC), |
| 4800 | MockRead(ASYNC, 0, 6), |
| 4801 | }; |
| 4802 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4803 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4804 | arraysize(spdy_writes)); |
| 4805 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4806 | |
| 4807 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4808 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4810 | |
| 4811 | TestCompletionCallback callback; |
| 4812 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4813 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4814 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4815 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4816 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4817 | |
| 4818 | LoadTimingInfo load_timing_info; |
| 4819 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4820 | TestLoadTimingNotReused(load_timing_info, |
| 4821 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4822 | |
| 4823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4824 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4825 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4826 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4827 | |
| 4828 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4829 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4830 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4831 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4832 | // Delete the first request, so the second one can reuse the socket. |
| 4833 | trans.reset(); |
| 4834 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4835 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4836 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4838 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4839 | |
| 4840 | LoadTimingInfo load_timing_info2; |
| 4841 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4842 | TestLoadTimingReused(load_timing_info2); |
| 4843 | |
| 4844 | // The requests should have the same ID. |
| 4845 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4846 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4847 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4848 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4849 | } |
| 4850 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4851 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4852 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4853 | HttpRequestInfo request; |
| 4854 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4855 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4856 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4857 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4858 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4859 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4860 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4861 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4862 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4863 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4864 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4865 | // Since we have proxy, should use full url |
| 4866 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4867 | MockWrite( |
| 4868 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4869 | "Host: www.example.org\r\n" |
| 4870 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4871 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4872 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4873 | // be issuing -- the final header line contains the credentials. |
| 4874 | MockWrite( |
| 4875 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4876 | "Host: www.example.org\r\n" |
| 4877 | "Proxy-Connection: keep-alive\r\n" |
| 4878 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4879 | }; |
| 4880 | |
| 4881 | // The proxy responds to the GET with a 407, using a persistent |
| 4882 | // connection. |
| 4883 | MockRead data_reads1[] = { |
| 4884 | // No credentials. |
| 4885 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4886 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4887 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4888 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4889 | |
| 4890 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4891 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4892 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4893 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4894 | }; |
| 4895 | |
| 4896 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4897 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4899 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4902 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4903 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4904 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4905 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4907 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4908 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4909 | |
| 4910 | rv = callback1.WaitForResult(); |
| 4911 | EXPECT_EQ(OK, rv); |
| 4912 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4913 | LoadTimingInfo load_timing_info; |
| 4914 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4915 | TestLoadTimingNotReused(load_timing_info, |
| 4916 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4917 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4918 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4919 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4920 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4921 | EXPECT_EQ(407, response->headers->response_code()); |
| 4922 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4923 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4925 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4927 | rv = trans->RestartWithAuth( |
| 4928 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4930 | |
| 4931 | rv = callback2.WaitForResult(); |
| 4932 | EXPECT_EQ(OK, rv); |
| 4933 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4934 | load_timing_info = LoadTimingInfo(); |
| 4935 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4936 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4937 | TestLoadTimingReused(load_timing_info); |
| 4938 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4939 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4940 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4941 | |
| 4942 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4943 | EXPECT_EQ(200, response->headers->response_code()); |
| 4944 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4945 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4946 | |
| 4947 | // The password prompt info should not be set. |
| 4948 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4949 | } |
| 4950 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4951 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4952 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4953 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4955 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4956 | request.load_flags = 0; |
| 4957 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4958 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4959 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4960 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4961 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4962 | // Since we have proxy, should try to establish tunnel. |
| 4963 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4964 | MockWrite( |
| 4965 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4966 | "Host: www.example.org\r\n" |
| 4967 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4968 | }; |
| 4969 | |
| 4970 | MockRead data_reads[] = { |
| 4971 | status, |
| 4972 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4973 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4974 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4975 | }; |
| 4976 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4978 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4981 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4982 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4983 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4984 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4986 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4987 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4988 | |
| 4989 | rv = callback.WaitForResult(); |
| 4990 | EXPECT_EQ(expected_status, rv); |
| 4991 | } |
| 4992 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4993 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4994 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4995 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4996 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4997 | } |
| 4998 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4999 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5000 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5001 | } |
| 5002 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5003 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5004 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5005 | } |
| 5006 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5007 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5008 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5009 | } |
| 5010 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5011 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5012 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5013 | } |
| 5014 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5015 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5016 | ConnectStatusHelper( |
| 5017 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5018 | } |
| 5019 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5020 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5021 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5022 | } |
| 5023 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5024 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5025 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5026 | } |
| 5027 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5028 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5029 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5030 | } |
| 5031 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5032 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5033 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5034 | } |
| 5035 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5036 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5037 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5038 | } |
| 5039 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5040 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5041 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5042 | } |
| 5043 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5044 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5045 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5046 | } |
| 5047 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5048 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5049 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5050 | } |
| 5051 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5052 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5053 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5054 | } |
| 5055 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5056 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5057 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5058 | } |
| 5059 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5060 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5061 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5062 | } |
| 5063 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5064 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5065 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5066 | } |
| 5067 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5068 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5069 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5070 | } |
| 5071 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5072 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5073 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5074 | } |
| 5075 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5076 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5077 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5078 | } |
| 5079 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5080 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5081 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5082 | } |
| 5083 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5084 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5085 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5086 | } |
| 5087 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5088 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5089 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5090 | } |
| 5091 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5092 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5093 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5094 | } |
| 5095 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5096 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5097 | ConnectStatusHelperWithExpectedStatus( |
| 5098 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5099 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5100 | } |
| 5101 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5102 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5103 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5104 | } |
| 5105 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5106 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5107 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5108 | } |
| 5109 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5110 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5111 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5112 | } |
| 5113 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5114 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5115 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5116 | } |
| 5117 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5118 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5119 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5120 | } |
| 5121 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5122 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5123 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5124 | } |
| 5125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5126 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5127 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5128 | } |
| 5129 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5130 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5131 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5132 | } |
| 5133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5134 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5135 | ConnectStatusHelper( |
| 5136 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5137 | } |
| 5138 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5139 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5140 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5141 | } |
| 5142 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5143 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5144 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5145 | } |
| 5146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5147 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5148 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5149 | } |
| 5150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5151 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5152 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5153 | } |
| 5154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5155 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5156 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5157 | } |
| 5158 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5159 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5160 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5161 | } |
| 5162 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5163 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5164 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5165 | } |
| 5166 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5167 | // Test the flow when both the proxy server AND origin server require |
| 5168 | // authentication. Again, this uses basic auth for both since that is |
| 5169 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5170 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5171 | HttpRequestInfo request; |
| 5172 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5173 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5174 | request.load_flags = 0; |
| 5175 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5176 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5177 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5178 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5179 | |
| 5180 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5182 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5183 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5184 | MockWrite( |
| 5185 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5186 | "Host: www.example.org\r\n" |
| 5187 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5188 | }; |
| 5189 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5190 | MockRead data_reads1[] = { |
| 5191 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5192 | // Give a couple authenticate options (only the middle one is actually |
| 5193 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5194 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5195 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5196 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5197 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5198 | // Large content-length -- won't matter, as connection will be reset. |
| 5199 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5200 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5201 | }; |
| 5202 | |
| 5203 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5204 | // request we should be issuing -- the final header line contains the |
| 5205 | // proxy's credentials. |
| 5206 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5207 | MockWrite( |
| 5208 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5209 | "Host: www.example.org\r\n" |
| 5210 | "Proxy-Connection: keep-alive\r\n" |
| 5211 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5212 | }; |
| 5213 | |
| 5214 | // Now the proxy server lets the request pass through to origin server. |
| 5215 | // The origin server responds with a 401. |
| 5216 | MockRead data_reads2[] = { |
| 5217 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5218 | // Note: We are using the same realm-name as the proxy server. This is |
| 5219 | // completely valid, as realms are unique across hosts. |
| 5220 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5221 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5222 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5223 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5224 | }; |
| 5225 | |
| 5226 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5227 | // the credentials for both the proxy and origin server. |
| 5228 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5229 | MockWrite( |
| 5230 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5231 | "Host: www.example.org\r\n" |
| 5232 | "Proxy-Connection: keep-alive\r\n" |
| 5233 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5234 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5235 | }; |
| 5236 | |
| 5237 | // Lastly we get the desired content. |
| 5238 | MockRead data_reads3[] = { |
| 5239 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5240 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5241 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5242 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5243 | }; |
| 5244 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5245 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5246 | data_writes1, arraysize(data_writes1)); |
| 5247 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5248 | data_writes2, arraysize(data_writes2)); |
| 5249 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5250 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5252 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5253 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5255 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5257 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5259 | |
| 5260 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5261 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5262 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5263 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5264 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5265 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5266 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5267 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5269 | rv = trans->RestartWithAuth( |
| 5270 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5272 | |
| 5273 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5274 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5275 | |
| 5276 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5277 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5278 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5280 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5282 | rv = trans->RestartWithAuth( |
| 5283 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5284 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5285 | |
| 5286 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5287 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5288 | |
| 5289 | response = trans->GetResponseInfo(); |
| 5290 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5291 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5292 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5293 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5294 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5295 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5296 | // authorization headers. |
| 5297 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5298 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5299 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5300 | // bytes in the debugger. |
| 5301 | |
| 5302 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5303 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5304 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5305 | request.method = "GET"; |
| 5306 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5307 | |
| 5308 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5309 | // to other auth schemes. |
| 5310 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5311 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5312 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5313 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5314 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5315 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5316 | MockWrite data_writes1[] = { |
| 5317 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5318 | "Host: 172.22.68.17\r\n" |
| 5319 | "Connection: keep-alive\r\n\r\n"), |
| 5320 | }; |
| 5321 | |
| 5322 | MockRead data_reads1[] = { |
| 5323 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5324 | // Negotiate and NTLM are often requested together. However, we only want |
| 5325 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5326 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5327 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5328 | MockRead("Connection: close\r\n"), |
| 5329 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5330 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5331 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5332 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5333 | }; |
| 5334 | |
| 5335 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5336 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5337 | // request we should be issuing -- the final header line contains a Type |
| 5338 | // 1 message. |
| 5339 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5340 | "Host: 172.22.68.17\r\n" |
| 5341 | "Connection: keep-alive\r\n" |
| 5342 | "Authorization: NTLM " |
| 5343 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5344 | |
| 5345 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5346 | // (the credentials for the origin server). The second request continues |
| 5347 | // on the same connection. |
| 5348 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5349 | "Host: 172.22.68.17\r\n" |
| 5350 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5351 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5352 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5353 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5354 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5355 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5356 | }; |
| 5357 | |
| 5358 | MockRead data_reads2[] = { |
| 5359 | // The origin server responds with a Type 2 message. |
| 5360 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5361 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5362 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5363 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5364 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5365 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5366 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5367 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5368 | "BtAAAAAAA=\r\n"), |
| 5369 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5370 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5371 | MockRead("You are not authorized to view this page\r\n"), |
| 5372 | |
| 5373 | // Lastly we get the desired content. |
| 5374 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5375 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5376 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5377 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5378 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5379 | }; |
| 5380 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5381 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5382 | data_writes1, arraysize(data_writes1)); |
| 5383 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5384 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5385 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5386 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5388 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5389 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5390 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5391 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5393 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5395 | |
| 5396 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5397 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5398 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5399 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5400 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5401 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5402 | ASSERT_FALSE(response == NULL); |
| 5403 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5405 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5406 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5407 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5408 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5410 | |
| 5411 | rv = callback2.WaitForResult(); |
| 5412 | EXPECT_EQ(OK, rv); |
| 5413 | |
| 5414 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5415 | |
| 5416 | response = trans->GetResponseInfo(); |
| 5417 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5418 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5419 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5420 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5422 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5424 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5425 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5426 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5427 | |
| 5428 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5429 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5430 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5431 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5432 | } |
| 5433 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5434 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5435 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5436 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5437 | request.method = "GET"; |
| 5438 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5439 | request.load_flags = 0; |
| 5440 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5441 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5442 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5443 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5444 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5445 | MockWrite data_writes1[] = { |
| 5446 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5447 | "Host: 172.22.68.17\r\n" |
| 5448 | "Connection: keep-alive\r\n\r\n"), |
| 5449 | }; |
| 5450 | |
| 5451 | MockRead data_reads1[] = { |
| 5452 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5453 | // Negotiate and NTLM are often requested together. However, we only want |
| 5454 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5455 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5456 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5457 | MockRead("Connection: close\r\n"), |
| 5458 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5459 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5460 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5461 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5462 | }; |
| 5463 | |
| 5464 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5465 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5466 | // request we should be issuing -- the final header line contains a Type |
| 5467 | // 1 message. |
| 5468 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5469 | "Host: 172.22.68.17\r\n" |
| 5470 | "Connection: keep-alive\r\n" |
| 5471 | "Authorization: NTLM " |
| 5472 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5473 | |
| 5474 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5475 | // (the credentials for the origin server). The second request continues |
| 5476 | // on the same connection. |
| 5477 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5478 | "Host: 172.22.68.17\r\n" |
| 5479 | "Connection: keep-alive\r\n" |
| 5480 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5481 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5482 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5483 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5484 | "4Ww7b7E=\r\n\r\n"), |
| 5485 | }; |
| 5486 | |
| 5487 | MockRead data_reads2[] = { |
| 5488 | // The origin server responds with a Type 2 message. |
| 5489 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5490 | MockRead("WWW-Authenticate: NTLM " |
| 5491 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5492 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5493 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5494 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5495 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5496 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5497 | "BtAAAAAAA=\r\n"), |
| 5498 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5499 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5500 | MockRead("You are not authorized to view this page\r\n"), |
| 5501 | |
| 5502 | // Wrong password. |
| 5503 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5504 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5505 | MockRead("Connection: close\r\n"), |
| 5506 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5507 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5508 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5509 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5510 | }; |
| 5511 | |
| 5512 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5513 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5514 | // request we should be issuing -- the final header line contains a Type |
| 5515 | // 1 message. |
| 5516 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5517 | "Host: 172.22.68.17\r\n" |
| 5518 | "Connection: keep-alive\r\n" |
| 5519 | "Authorization: NTLM " |
| 5520 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5521 | |
| 5522 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5523 | // (the credentials for the origin server). The second request continues |
| 5524 | // on the same connection. |
| 5525 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5526 | "Host: 172.22.68.17\r\n" |
| 5527 | "Connection: keep-alive\r\n" |
| 5528 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5529 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5530 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5531 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5532 | "+4MUm7c=\r\n\r\n"), |
| 5533 | }; |
| 5534 | |
| 5535 | MockRead data_reads3[] = { |
| 5536 | // The origin server responds with a Type 2 message. |
| 5537 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5538 | MockRead("WWW-Authenticate: NTLM " |
| 5539 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5540 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5541 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5542 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5543 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5544 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5545 | "BtAAAAAAA=\r\n"), |
| 5546 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5547 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5548 | MockRead("You are not authorized to view this page\r\n"), |
| 5549 | |
| 5550 | // Lastly we get the desired content. |
| 5551 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5552 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5553 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5554 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5555 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5556 | }; |
| 5557 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5559 | data_writes1, arraysize(data_writes1)); |
| 5560 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5561 | data_writes2, arraysize(data_writes2)); |
| 5562 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5563 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5564 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5565 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5566 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5568 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5569 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5570 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5571 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5573 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5574 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5575 | |
| 5576 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5577 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5578 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5579 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5580 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5581 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5582 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5583 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5585 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5586 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5587 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5588 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5589 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5591 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5592 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5593 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5594 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5595 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5596 | TestCompletionCallback callback3; |
| 5597 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5599 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5600 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5601 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5602 | |
| 5603 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5604 | ASSERT_FALSE(response == NULL); |
| 5605 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5607 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5608 | |
| 5609 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5610 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5611 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5612 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5613 | |
| 5614 | rv = callback4.WaitForResult(); |
| 5615 | EXPECT_EQ(OK, rv); |
| 5616 | |
| 5617 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5619 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5620 | |
| 5621 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5622 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5623 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5624 | |
| 5625 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5626 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5627 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5628 | response = trans->GetResponseInfo(); |
| 5629 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5630 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5631 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5632 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5633 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5634 | // Test reading a server response which has only headers, and no body. |
| 5635 | // After some maximum number of bytes is consumed, the transaction should |
| 5636 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5637 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5638 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5640 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5641 | request.load_flags = 0; |
| 5642 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5643 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5644 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5645 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5646 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5647 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5648 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5649 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5650 | |
| 5651 | MockRead data_reads[] = { |
| 5652 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5653 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5654 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5655 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5656 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5657 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5658 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5660 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5662 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5664 | |
| 5665 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5666 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5667 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5668 | |
| 5669 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5670 | // establish tunnel. |
| 5671 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5672 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5673 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5674 | HttpRequestInfo request; |
| 5675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5677 | request.load_flags = 0; |
| 5678 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5679 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5680 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5681 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5682 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5683 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5684 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5686 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5687 | // Since we have proxy, should try to establish tunnel. |
| 5688 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5689 | MockWrite( |
| 5690 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5691 | "Host: www.example.org\r\n" |
| 5692 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5693 | }; |
| 5694 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5695 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5696 | // connection. Usually a proxy would return 501 (not implemented), |
| 5697 | // or 200 (tunnel established). |
| 5698 | MockRead data_reads1[] = { |
| 5699 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5700 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5701 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5702 | }; |
| 5703 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5704 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5705 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5706 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5708 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5710 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5712 | |
| 5713 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5714 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5715 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5716 | // Empty the current queue. This is necessary because idle sockets are |
| 5717 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5718 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5719 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5720 | // We now check to make sure the TCPClientSocket was not added back to |
| 5721 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5722 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5723 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5724 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5725 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5726 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5727 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5728 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5729 | // 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] | 5730 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5731 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5734 | request.load_flags = 0; |
| 5735 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5736 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5737 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5738 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5739 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5740 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5741 | MockRead data_reads[] = { |
| 5742 | // A part of the response body is received with the response headers. |
| 5743 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5744 | // The rest of the response body is received in two parts. |
| 5745 | MockRead("lo"), |
| 5746 | MockRead(" world"), |
| 5747 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5748 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5749 | }; |
| 5750 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5751 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5754 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5756 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5757 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5758 | |
| 5759 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5760 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5761 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5763 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5764 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5765 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5766 | std::string status_line = response->headers->GetStatusLine(); |
| 5767 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5768 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5769 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5770 | |
| 5771 | std::string response_data; |
| 5772 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5773 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5774 | EXPECT_EQ("hello world", response_data); |
| 5775 | |
| 5776 | // Empty the current queue. This is necessary because idle sockets are |
| 5777 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5778 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5779 | |
| 5780 | // 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] | 5781 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5782 | } |
| 5783 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5784 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5785 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5786 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5787 | HttpRequestInfo request; |
| 5788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5789 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5790 | request.load_flags = 0; |
| 5791 | |
| 5792 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5793 | MockWrite( |
| 5794 | "GET / HTTP/1.1\r\n" |
| 5795 | "Host: www.example.org\r\n" |
| 5796 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5797 | }; |
| 5798 | |
| 5799 | MockRead data_reads[] = { |
| 5800 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5801 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5802 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5804 | }; |
| 5805 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5806 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5808 | |
| 5809 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5810 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5811 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5813 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5814 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5815 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5816 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5817 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5819 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5820 | |
| 5821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5822 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5823 | |
| 5824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5825 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5826 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5827 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5828 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5829 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5830 | |
| 5831 | std::string response_data; |
| 5832 | rv = ReadTransaction(trans.get(), &response_data); |
| 5833 | EXPECT_EQ(OK, rv); |
| 5834 | EXPECT_EQ("hello world", response_data); |
| 5835 | |
| 5836 | // Empty the current queue. This is necessary because idle sockets are |
| 5837 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5838 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5839 | |
| 5840 | // 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] | 5841 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5842 | } |
| 5843 | |
| 5844 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5845 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5846 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5847 | HttpRequestInfo request; |
| 5848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5849 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5850 | request.load_flags = 0; |
| 5851 | |
| 5852 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5853 | MockWrite( |
| 5854 | "GET / HTTP/1.1\r\n" |
| 5855 | "Host: www.example.org\r\n" |
| 5856 | "Connection: keep-alive\r\n\r\n"), |
| 5857 | MockWrite( |
| 5858 | "GET / HTTP/1.1\r\n" |
| 5859 | "Host: www.example.org\r\n" |
| 5860 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5861 | }; |
| 5862 | |
| 5863 | MockRead data_reads[] = { |
| 5864 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5865 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5866 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5867 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5868 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5869 | }; |
| 5870 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5871 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5872 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5875 | |
| 5876 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5877 | data_writes, arraysize(data_writes)); |
| 5878 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5879 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5881 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5883 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5884 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5885 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5886 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5887 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5889 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5890 | |
| 5891 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5892 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5893 | |
| 5894 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5895 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5896 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5897 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5898 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5899 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5900 | |
| 5901 | std::string response_data; |
| 5902 | rv = ReadTransaction(trans.get(), &response_data); |
| 5903 | EXPECT_EQ(OK, rv); |
| 5904 | EXPECT_EQ("hello world", response_data); |
| 5905 | |
| 5906 | // Empty the current queue. This is necessary because idle sockets are |
| 5907 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5908 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5909 | |
| 5910 | // 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] | 5911 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5912 | |
| 5913 | // Now start the second transaction, which should reuse the previous socket. |
| 5914 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5915 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5917 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5918 | |
| 5919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5920 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5921 | |
| 5922 | response = trans->GetResponseInfo(); |
| 5923 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5924 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5925 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5926 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5927 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5928 | |
| 5929 | rv = ReadTransaction(trans.get(), &response_data); |
| 5930 | EXPECT_EQ(OK, rv); |
| 5931 | EXPECT_EQ("hello world", response_data); |
| 5932 | |
| 5933 | // Empty the current queue. This is necessary because idle sockets are |
| 5934 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5935 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5936 | |
| 5937 | // 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] | 5938 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5939 | } |
| 5940 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5941 | // Make sure that we recycle a socket after a zero-length response. |
| 5942 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5943 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5944 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5946 | request.url = GURL( |
| 5947 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5948 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5949 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5950 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5951 | request.load_flags = 0; |
| 5952 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5953 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5954 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5955 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5956 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5957 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5958 | MockRead data_reads[] = { |
| 5959 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5960 | "Content-Length: 0\r\n" |
| 5961 | "Content-Type: text/html\r\n\r\n"), |
| 5962 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5963 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5964 | }; |
| 5965 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5966 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5969 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5971 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5972 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5973 | |
| 5974 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5975 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5976 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5977 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5978 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5979 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5980 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5981 | std::string status_line = response->headers->GetStatusLine(); |
| 5982 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5983 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5984 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5985 | |
| 5986 | std::string response_data; |
| 5987 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5988 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5989 | EXPECT_EQ("", response_data); |
| 5990 | |
| 5991 | // Empty the current queue. This is necessary because idle sockets are |
| 5992 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5993 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5994 | |
| 5995 | // 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] | 5996 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5997 | } |
| 5998 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5999 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 6000 | ScopedVector<UploadElementReader> element_readers; |
| 6001 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6002 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6003 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6004 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6005 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6006 | // after use. |
| 6007 | request[0].method = "GET"; |
| 6008 | request[0].url = GURL("http://www.google.com/"); |
| 6009 | request[0].load_flags = 0; |
| 6010 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6011 | // transaction 1. The first attempts fails when writing the POST data. |
| 6012 | // This causes the transaction to retry with a new socket. The second |
| 6013 | // attempt succeeds. |
| 6014 | request[1].method = "POST"; |
| 6015 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6016 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6017 | request[1].load_flags = 0; |
| 6018 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6019 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6020 | |
| 6021 | // The first socket is used for transaction 1 and the first attempt of |
| 6022 | // transaction 2. |
| 6023 | |
| 6024 | // The response of transaction 1. |
| 6025 | MockRead data_reads1[] = { |
| 6026 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6027 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6028 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6029 | }; |
| 6030 | // The mock write results of transaction 1 and the first attempt of |
| 6031 | // transaction 2. |
| 6032 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6033 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6034 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6035 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6036 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6037 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6038 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6039 | |
| 6040 | // The second socket is used for the second attempt of transaction 2. |
| 6041 | |
| 6042 | // The response of transaction 2. |
| 6043 | MockRead data_reads2[] = { |
| 6044 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6045 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6046 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6047 | }; |
| 6048 | // The mock write results of the second attempt of transaction 2. |
| 6049 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6050 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6051 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6052 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6053 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6054 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6055 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6057 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6058 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6059 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6060 | "hello world", "welcome" |
| 6061 | }; |
| 6062 | |
| 6063 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6064 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6067 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6069 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6071 | |
| 6072 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6073 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6074 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6075 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6076 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6077 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6078 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6079 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6080 | |
| 6081 | std::string response_data; |
| 6082 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6083 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6084 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6085 | } |
| 6086 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6087 | |
| 6088 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6089 | // 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] | 6090 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6091 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6092 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6093 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6094 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6095 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6096 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6097 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6098 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6099 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6100 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6101 | // The password contains an escaped character -- for this test to pass it |
| 6102 | // will need to be unescaped by HttpNetworkTransaction. |
| 6103 | EXPECT_EQ("b%40r", request.url.password()); |
| 6104 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6105 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6106 | MockWrite( |
| 6107 | "GET / HTTP/1.1\r\n" |
| 6108 | "Host: www.example.org\r\n" |
| 6109 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6110 | }; |
| 6111 | |
| 6112 | MockRead data_reads1[] = { |
| 6113 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6114 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6115 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6116 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6117 | }; |
| 6118 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6119 | // After the challenge above, the transaction will be restarted using the |
| 6120 | // identity from the url (foo, b@r) to answer the challenge. |
| 6121 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6122 | MockWrite( |
| 6123 | "GET / HTTP/1.1\r\n" |
| 6124 | "Host: www.example.org\r\n" |
| 6125 | "Connection: keep-alive\r\n" |
| 6126 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6127 | }; |
| 6128 | |
| 6129 | MockRead data_reads2[] = { |
| 6130 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6131 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6132 | MockRead(SYNCHRONOUS, OK), |
| 6133 | }; |
| 6134 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6135 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6136 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6137 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6138 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6139 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6140 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6142 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6143 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6145 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6146 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6147 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6148 | |
| 6149 | TestCompletionCallback callback2; |
| 6150 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6151 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6152 | rv = callback2.WaitForResult(); |
| 6153 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6154 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6155 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6156 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6157 | ASSERT_TRUE(response != NULL); |
| 6158 | |
| 6159 | // There is no challenge info, since the identity in URL worked. |
| 6160 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6161 | |
| 6162 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6163 | |
| 6164 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6165 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6169 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6170 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6171 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6172 | HttpRequestInfo request; |
| 6173 | request.method = "GET"; |
| 6174 | // Note: the URL has a username:password in it. The password "baz" is |
| 6175 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6176 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6177 | |
| 6178 | request.load_flags = LOAD_NORMAL; |
| 6179 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6180 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6181 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6182 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6183 | |
| 6184 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6185 | MockWrite( |
| 6186 | "GET / HTTP/1.1\r\n" |
| 6187 | "Host: www.example.org\r\n" |
| 6188 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6189 | }; |
| 6190 | |
| 6191 | MockRead data_reads1[] = { |
| 6192 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6193 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6194 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6195 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6196 | }; |
| 6197 | |
| 6198 | // After the challenge above, the transaction will be restarted using the |
| 6199 | // identity from the url (foo, baz) to answer the challenge. |
| 6200 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6201 | MockWrite( |
| 6202 | "GET / HTTP/1.1\r\n" |
| 6203 | "Host: www.example.org\r\n" |
| 6204 | "Connection: keep-alive\r\n" |
| 6205 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6206 | }; |
| 6207 | |
| 6208 | MockRead data_reads2[] = { |
| 6209 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6210 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6211 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6212 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6213 | }; |
| 6214 | |
| 6215 | // After the challenge above, the transaction will be restarted using the |
| 6216 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6217 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6218 | MockWrite( |
| 6219 | "GET / HTTP/1.1\r\n" |
| 6220 | "Host: www.example.org\r\n" |
| 6221 | "Connection: keep-alive\r\n" |
| 6222 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6223 | }; |
| 6224 | |
| 6225 | MockRead data_reads3[] = { |
| 6226 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6227 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6228 | MockRead(SYNCHRONOUS, OK), |
| 6229 | }; |
| 6230 | |
| 6231 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6232 | data_writes1, arraysize(data_writes1)); |
| 6233 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6234 | data_writes2, arraysize(data_writes2)); |
| 6235 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6236 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6237 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6238 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6239 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6240 | |
| 6241 | TestCompletionCallback callback1; |
| 6242 | |
| 6243 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6245 | |
| 6246 | rv = callback1.WaitForResult(); |
| 6247 | EXPECT_EQ(OK, rv); |
| 6248 | |
| 6249 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6250 | TestCompletionCallback callback2; |
| 6251 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6253 | rv = callback2.WaitForResult(); |
| 6254 | EXPECT_EQ(OK, rv); |
| 6255 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6256 | |
| 6257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6258 | ASSERT_TRUE(response != NULL); |
| 6259 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6260 | |
| 6261 | TestCompletionCallback callback3; |
| 6262 | rv = trans->RestartWithAuth( |
| 6263 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6264 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6265 | rv = callback3.WaitForResult(); |
| 6266 | EXPECT_EQ(OK, rv); |
| 6267 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6268 | |
| 6269 | response = trans->GetResponseInfo(); |
| 6270 | ASSERT_TRUE(response != NULL); |
| 6271 | |
| 6272 | // There is no challenge info, since the identity worked. |
| 6273 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6274 | |
| 6275 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6276 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6277 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6278 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6279 | } |
| 6280 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6281 | |
| 6282 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6283 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6284 | // from the URL should never be used. |
| 6285 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6286 | HttpRequestInfo request; |
| 6287 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6288 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6289 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6290 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6291 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6292 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6293 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6294 | |
| 6295 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6296 | MockWrite( |
| 6297 | "GET / HTTP/1.1\r\n" |
| 6298 | "Host: www.example.org\r\n" |
| 6299 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6300 | }; |
| 6301 | |
| 6302 | MockRead data_reads1[] = { |
| 6303 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6304 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6305 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6306 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6307 | }; |
| 6308 | |
| 6309 | // After the challenge above, the transaction will be restarted using the |
| 6310 | // identity supplied by the user, not the one in the URL, to answer the |
| 6311 | // challenge. |
| 6312 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6313 | MockWrite( |
| 6314 | "GET / HTTP/1.1\r\n" |
| 6315 | "Host: www.example.org\r\n" |
| 6316 | "Connection: keep-alive\r\n" |
| 6317 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6318 | }; |
| 6319 | |
| 6320 | MockRead data_reads3[] = { |
| 6321 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6322 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6323 | MockRead(SYNCHRONOUS, OK), |
| 6324 | }; |
| 6325 | |
| 6326 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6327 | data_writes1, arraysize(data_writes1)); |
| 6328 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6329 | data_writes3, arraysize(data_writes3)); |
| 6330 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6331 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6332 | |
| 6333 | TestCompletionCallback callback1; |
| 6334 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6335 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6336 | rv = callback1.WaitForResult(); |
| 6337 | EXPECT_EQ(OK, rv); |
| 6338 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6339 | |
| 6340 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6341 | ASSERT_TRUE(response != NULL); |
| 6342 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6343 | |
| 6344 | TestCompletionCallback callback3; |
| 6345 | rv = trans->RestartWithAuth( |
| 6346 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6347 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6348 | rv = callback3.WaitForResult(); |
| 6349 | EXPECT_EQ(OK, rv); |
| 6350 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6351 | |
| 6352 | response = trans->GetResponseInfo(); |
| 6353 | ASSERT_TRUE(response != NULL); |
| 6354 | |
| 6355 | // There is no challenge info, since the identity worked. |
| 6356 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6357 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6358 | |
| 6359 | // Empty the current queue. |
| 6360 | base::MessageLoop::current()->RunUntilIdle(); |
| 6361 | } |
| 6362 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6363 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6364 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6365 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6366 | |
| 6367 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6368 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6369 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6371 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6372 | request.load_flags = 0; |
| 6373 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6374 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6375 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6376 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6377 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6378 | MockWrite( |
| 6379 | "GET /x/y/z HTTP/1.1\r\n" |
| 6380 | "Host: www.example.org\r\n" |
| 6381 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6382 | }; |
| 6383 | |
| 6384 | MockRead data_reads1[] = { |
| 6385 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6386 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6387 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6388 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6389 | }; |
| 6390 | |
| 6391 | // Resend with authorization (username=foo, password=bar) |
| 6392 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6393 | MockWrite( |
| 6394 | "GET /x/y/z HTTP/1.1\r\n" |
| 6395 | "Host: www.example.org\r\n" |
| 6396 | "Connection: keep-alive\r\n" |
| 6397 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6398 | }; |
| 6399 | |
| 6400 | // Sever accepts the authorization. |
| 6401 | MockRead data_reads2[] = { |
| 6402 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6403 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6404 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6405 | }; |
| 6406 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6407 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6408 | data_writes1, arraysize(data_writes1)); |
| 6409 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6410 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6412 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6414 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6416 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6417 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6418 | |
| 6419 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6420 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6421 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6422 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6423 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6424 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6426 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6428 | rv = trans->RestartWithAuth( |
| 6429 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6431 | |
| 6432 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6433 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6434 | |
| 6435 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6436 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6437 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6438 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6439 | } |
| 6440 | |
| 6441 | // ------------------------------------------------------------------------ |
| 6442 | |
| 6443 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6444 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6445 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6446 | request.method = "GET"; |
| 6447 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6448 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6449 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6450 | request.load_flags = 0; |
| 6451 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6452 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6453 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6454 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6455 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6456 | MockWrite( |
| 6457 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6458 | "Host: www.example.org\r\n" |
| 6459 | "Connection: keep-alive\r\n" |
| 6460 | // Send preemptive authorization for MyRealm1 |
| 6461 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6462 | }; |
| 6463 | |
| 6464 | // The server didn't like the preemptive authorization, and |
| 6465 | // challenges us for a different realm (MyRealm2). |
| 6466 | MockRead data_reads1[] = { |
| 6467 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6468 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6469 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6470 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6471 | }; |
| 6472 | |
| 6473 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6474 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6475 | MockWrite( |
| 6476 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6477 | "Host: www.example.org\r\n" |
| 6478 | "Connection: keep-alive\r\n" |
| 6479 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6480 | }; |
| 6481 | |
| 6482 | // Sever accepts the authorization. |
| 6483 | MockRead data_reads2[] = { |
| 6484 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6485 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6486 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6487 | }; |
| 6488 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6489 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6490 | data_writes1, arraysize(data_writes1)); |
| 6491 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6492 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6494 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6496 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6498 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6499 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6500 | |
| 6501 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6502 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6503 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6504 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6505 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6506 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6507 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6508 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6509 | response->auth_challenge->challenger.ToString()); |
| 6510 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 6511 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6513 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6515 | rv = trans->RestartWithAuth( |
| 6516 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6517 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6518 | |
| 6519 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6520 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6521 | |
| 6522 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6523 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6524 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6525 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6526 | } |
| 6527 | |
| 6528 | // ------------------------------------------------------------------------ |
| 6529 | |
| 6530 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6531 | // succeed with preemptive authorization. |
| 6532 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6533 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6534 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6535 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6536 | request.load_flags = 0; |
| 6537 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6538 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6539 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6540 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6541 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6542 | MockWrite( |
| 6543 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6544 | "Host: www.example.org\r\n" |
| 6545 | "Connection: keep-alive\r\n" |
| 6546 | // The authorization for MyRealm1 gets sent preemptively |
| 6547 | // (since the url is in the same protection space) |
| 6548 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6549 | }; |
| 6550 | |
| 6551 | // Sever accepts the preemptive authorization |
| 6552 | MockRead data_reads1[] = { |
| 6553 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6554 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6555 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6556 | }; |
| 6557 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6559 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6561 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6562 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6564 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6565 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6566 | |
| 6567 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6568 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6569 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6570 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6571 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6572 | |
| 6573 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6574 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6575 | } |
| 6576 | |
| 6577 | // ------------------------------------------------------------------------ |
| 6578 | |
| 6579 | // Transaction 4: request another URL in MyRealm (however the |
| 6580 | // url is not known to belong to the protection space, so no pre-auth). |
| 6581 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6582 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6583 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6584 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6585 | request.load_flags = 0; |
| 6586 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6587 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6589 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6590 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6591 | MockWrite( |
| 6592 | "GET /x/1 HTTP/1.1\r\n" |
| 6593 | "Host: www.example.org\r\n" |
| 6594 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6595 | }; |
| 6596 | |
| 6597 | MockRead data_reads1[] = { |
| 6598 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6599 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6600 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6601 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6602 | }; |
| 6603 | |
| 6604 | // Resend with authorization from MyRealm's cache. |
| 6605 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6606 | MockWrite( |
| 6607 | "GET /x/1 HTTP/1.1\r\n" |
| 6608 | "Host: www.example.org\r\n" |
| 6609 | "Connection: keep-alive\r\n" |
| 6610 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6611 | }; |
| 6612 | |
| 6613 | // Sever accepts the authorization. |
| 6614 | MockRead data_reads2[] = { |
| 6615 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6616 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6617 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6618 | }; |
| 6619 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6620 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6621 | data_writes1, arraysize(data_writes1)); |
| 6622 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6623 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6624 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6625 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6626 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6627 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6629 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6630 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6631 | |
| 6632 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6633 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6634 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6635 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6636 | TestCompletionCallback callback2; |
| 6637 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6638 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6639 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6640 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6641 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6642 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6643 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6644 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6645 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6646 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6647 | } |
| 6648 | |
| 6649 | // ------------------------------------------------------------------------ |
| 6650 | |
| 6651 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6652 | // cached identity. Should invalidate and re-prompt. |
| 6653 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6654 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6655 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6656 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6657 | request.load_flags = 0; |
| 6658 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6659 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6660 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6661 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6662 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6663 | MockWrite( |
| 6664 | "GET /p/q/t HTTP/1.1\r\n" |
| 6665 | "Host: www.example.org\r\n" |
| 6666 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6667 | }; |
| 6668 | |
| 6669 | MockRead data_reads1[] = { |
| 6670 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6671 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6672 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6673 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6674 | }; |
| 6675 | |
| 6676 | // Resend with authorization from cache for MyRealm. |
| 6677 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6678 | MockWrite( |
| 6679 | "GET /p/q/t HTTP/1.1\r\n" |
| 6680 | "Host: www.example.org\r\n" |
| 6681 | "Connection: keep-alive\r\n" |
| 6682 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6683 | }; |
| 6684 | |
| 6685 | // Sever rejects the authorization. |
| 6686 | MockRead data_reads2[] = { |
| 6687 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6688 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6689 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6690 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6691 | }; |
| 6692 | |
| 6693 | // At this point we should prompt for new credentials for MyRealm. |
| 6694 | // Restart with username=foo3, password=foo4. |
| 6695 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6696 | MockWrite( |
| 6697 | "GET /p/q/t HTTP/1.1\r\n" |
| 6698 | "Host: www.example.org\r\n" |
| 6699 | "Connection: keep-alive\r\n" |
| 6700 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6701 | }; |
| 6702 | |
| 6703 | // Sever accepts the authorization. |
| 6704 | MockRead data_reads3[] = { |
| 6705 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6706 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6707 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6708 | }; |
| 6709 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6710 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6711 | data_writes1, arraysize(data_writes1)); |
| 6712 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6713 | data_writes2, arraysize(data_writes2)); |
| 6714 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6715 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6716 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6717 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6718 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6720 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6722 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6723 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6724 | |
| 6725 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6726 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6727 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6728 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6729 | TestCompletionCallback callback2; |
| 6730 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6732 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6733 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6734 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6735 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6737 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6738 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6740 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6742 | rv = trans->RestartWithAuth( |
| 6743 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6745 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6746 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6747 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6748 | |
| 6749 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6750 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6751 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6752 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6753 | } |
| 6754 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6755 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6756 | // Tests that nonce count increments when multiple auth attempts |
| 6757 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6758 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6759 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6760 | new HttpAuthHandlerDigest::Factory(); |
| 6761 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6762 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6763 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6764 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6765 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6766 | |
| 6767 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6768 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6769 | HttpRequestInfo request; |
| 6770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6771 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6772 | request.load_flags = 0; |
| 6773 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6774 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6775 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6776 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6777 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6778 | MockWrite( |
| 6779 | "GET /x/y/z HTTP/1.1\r\n" |
| 6780 | "Host: www.example.org\r\n" |
| 6781 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6782 | }; |
| 6783 | |
| 6784 | MockRead data_reads1[] = { |
| 6785 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6786 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6787 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6789 | }; |
| 6790 | |
| 6791 | // Resend with authorization (username=foo, password=bar) |
| 6792 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6793 | MockWrite( |
| 6794 | "GET /x/y/z HTTP/1.1\r\n" |
| 6795 | "Host: www.example.org\r\n" |
| 6796 | "Connection: keep-alive\r\n" |
| 6797 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6798 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6799 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6800 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6801 | }; |
| 6802 | |
| 6803 | // Sever accepts the authorization. |
| 6804 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6805 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6806 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6807 | }; |
| 6808 | |
| 6809 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6810 | data_writes1, arraysize(data_writes1)); |
| 6811 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6812 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6814 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6816 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6818 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6820 | |
| 6821 | rv = callback1.WaitForResult(); |
| 6822 | EXPECT_EQ(OK, rv); |
| 6823 | |
| 6824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6825 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6826 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6827 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6828 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6830 | rv = trans->RestartWithAuth( |
| 6831 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6833 | |
| 6834 | rv = callback2.WaitForResult(); |
| 6835 | EXPECT_EQ(OK, rv); |
| 6836 | |
| 6837 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6838 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6839 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6840 | } |
| 6841 | |
| 6842 | // ------------------------------------------------------------------------ |
| 6843 | |
| 6844 | // Transaction 2: Request another resource in digestive's protection space. |
| 6845 | // This will preemptively add an Authorization header which should have an |
| 6846 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6847 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6848 | HttpRequestInfo request; |
| 6849 | request.method = "GET"; |
| 6850 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6851 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6852 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6853 | request.load_flags = 0; |
| 6854 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6855 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6856 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6857 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6858 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6859 | MockWrite( |
| 6860 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6861 | "Host: www.example.org\r\n" |
| 6862 | "Connection: keep-alive\r\n" |
| 6863 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6864 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6865 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6866 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6867 | }; |
| 6868 | |
| 6869 | // Sever accepts the authorization. |
| 6870 | MockRead data_reads1[] = { |
| 6871 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6872 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6873 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6874 | }; |
| 6875 | |
| 6876 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6877 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6880 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6882 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6883 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6884 | |
| 6885 | rv = callback1.WaitForResult(); |
| 6886 | EXPECT_EQ(OK, rv); |
| 6887 | |
| 6888 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6889 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6890 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6891 | } |
| 6892 | } |
| 6893 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6894 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6895 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6896 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6897 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6898 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6900 | |
| 6901 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6902 | trans->read_buf_ = new IOBuffer(15); |
| 6903 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6904 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6905 | |
| 6906 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6907 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6908 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6909 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6910 | response->response_time = base::Time::Now(); |
| 6911 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6912 | |
| 6913 | { // Setup state for response_.vary_data |
| 6914 | HttpRequestInfo request; |
| 6915 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6916 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6917 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6918 | request.extra_headers.SetHeader("Foo", "1"); |
| 6919 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6920 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | // Cause the above state to be reset. |
| 6924 | trans->ResetStateForRestart(); |
| 6925 | |
| 6926 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6927 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6928 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6929 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6930 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6931 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6932 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6933 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6934 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6935 | } |
| 6936 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6937 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6938 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6939 | HttpRequestInfo request; |
| 6940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6941 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6942 | request.load_flags = 0; |
| 6943 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6944 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6945 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6946 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6947 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6948 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6949 | MockWrite( |
| 6950 | "GET / HTTP/1.1\r\n" |
| 6951 | "Host: www.example.org\r\n" |
| 6952 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6953 | }; |
| 6954 | |
| 6955 | MockRead data_reads[] = { |
| 6956 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6957 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6958 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6959 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6960 | }; |
| 6961 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6962 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6963 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6964 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6965 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6966 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6967 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6968 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6971 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6973 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6974 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6975 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6977 | |
| 6978 | rv = callback.WaitForResult(); |
| 6979 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6981 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6983 | |
| 6984 | rv = callback.WaitForResult(); |
| 6985 | EXPECT_EQ(OK, rv); |
| 6986 | |
| 6987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6988 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6989 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6990 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6991 | } |
| 6992 | |
| 6993 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6994 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6995 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6996 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6997 | |
| 6998 | HttpRequestInfo request; |
| 6999 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7000 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7001 | request.load_flags = 0; |
| 7002 | |
| 7003 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7004 | MockWrite( |
| 7005 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7006 | "Host: www.example.org\r\n" |
| 7007 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7008 | }; |
| 7009 | |
| 7010 | MockRead proxy_reads[] = { |
| 7011 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7012 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7013 | }; |
| 7014 | |
| 7015 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7016 | MockWrite( |
| 7017 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7018 | "Host: www.example.org\r\n" |
| 7019 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7020 | MockWrite( |
| 7021 | "GET / HTTP/1.1\r\n" |
| 7022 | "Host: www.example.org\r\n" |
| 7023 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7024 | }; |
| 7025 | |
| 7026 | MockRead data_reads[] = { |
| 7027 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7028 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7029 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7030 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7031 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7032 | }; |
| 7033 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7034 | StaticSocketDataProvider ssl_bad_certificate( |
| 7035 | proxy_reads, arraysize(proxy_reads), |
| 7036 | proxy_writes, arraysize(proxy_writes)); |
| 7037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7038 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7039 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7040 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7041 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7042 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7047 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7048 | |
| 7049 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7050 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7051 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7053 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7054 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7056 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7058 | |
| 7059 | rv = callback.WaitForResult(); |
| 7060 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7062 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7064 | |
| 7065 | rv = callback.WaitForResult(); |
| 7066 | EXPECT_EQ(OK, rv); |
| 7067 | |
| 7068 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7069 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7070 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7071 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7072 | } |
| 7073 | } |
| 7074 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7075 | |
| 7076 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7077 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7078 | session_deps_.proxy_service = |
| 7079 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7080 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7081 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7082 | |
| 7083 | HttpRequestInfo request; |
| 7084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7085 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7086 | request.load_flags = 0; |
| 7087 | |
| 7088 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7089 | MockWrite( |
| 7090 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7091 | "Host: www.example.org\r\n" |
| 7092 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7093 | MockWrite( |
| 7094 | "GET / HTTP/1.1\r\n" |
| 7095 | "Host: www.example.org\r\n" |
| 7096 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7097 | }; |
| 7098 | |
| 7099 | MockRead data_reads[] = { |
| 7100 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7101 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7102 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7103 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7105 | }; |
| 7106 | |
| 7107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7108 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7109 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7110 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7111 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7116 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7117 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7118 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7119 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7122 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7123 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7124 | |
| 7125 | rv = callback.WaitForResult(); |
| 7126 | EXPECT_EQ(OK, rv); |
| 7127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7128 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7129 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7130 | |
| 7131 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7132 | EXPECT_EQ(200, response->headers->response_code()); |
| 7133 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7134 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7135 | |
| 7136 | LoadTimingInfo load_timing_info; |
| 7137 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7138 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7139 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7140 | } |
| 7141 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7142 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7143 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7144 | session_deps_.proxy_service = |
| 7145 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7146 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7147 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7148 | |
| 7149 | HttpRequestInfo request; |
| 7150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7151 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7152 | request.load_flags = 0; |
| 7153 | |
| 7154 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7155 | MockWrite( |
| 7156 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7157 | "Host: www.example.org\r\n" |
| 7158 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7159 | }; |
| 7160 | |
| 7161 | MockRead data_reads[] = { |
| 7162 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7163 | MockRead("Location: http://login.example.com/\r\n"), |
| 7164 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7165 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7166 | }; |
| 7167 | |
| 7168 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7169 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7170 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7171 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7175 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7176 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7177 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7178 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7179 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7183 | |
| 7184 | rv = callback.WaitForResult(); |
| 7185 | EXPECT_EQ(OK, rv); |
| 7186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7187 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7188 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7189 | |
| 7190 | EXPECT_EQ(302, response->headers->response_code()); |
| 7191 | std::string url; |
| 7192 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7193 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7194 | |
| 7195 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7196 | // timing for the proxy connection instead of the connection to the host, |
| 7197 | // and no send / receive times. |
| 7198 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7199 | LoadTimingInfo load_timing_info; |
| 7200 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7201 | |
| 7202 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7203 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7204 | |
| 7205 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7206 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7207 | load_timing_info.proxy_resolve_end); |
| 7208 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7209 | load_timing_info.connect_timing.connect_start); |
| 7210 | ExpectConnectTimingHasTimes( |
| 7211 | load_timing_info.connect_timing, |
| 7212 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7213 | |
| 7214 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7215 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7216 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7220 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7221 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7222 | |
| 7223 | HttpRequestInfo request; |
| 7224 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7225 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7226 | request.load_flags = 0; |
| 7227 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7228 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7229 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7230 | scoped_ptr<SpdyFrame> goaway( |
| 7231 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7232 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7233 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7234 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7235 | }; |
| 7236 | |
| 7237 | static const char* const kExtraHeaders[] = { |
| 7238 | "location", |
| 7239 | "http://login.example.com/", |
| 7240 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7241 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7242 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7243 | arraysize(kExtraHeaders)/2, 1)); |
| 7244 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7245 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7246 | }; |
| 7247 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7248 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7249 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7250 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7251 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7252 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7253 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7256 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7257 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7258 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7259 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7262 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7264 | |
| 7265 | rv = callback.WaitForResult(); |
| 7266 | EXPECT_EQ(OK, rv); |
| 7267 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7268 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7269 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7270 | |
| 7271 | EXPECT_EQ(302, response->headers->response_code()); |
| 7272 | std::string url; |
| 7273 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7274 | EXPECT_EQ("http://login.example.com/", url); |
| 7275 | } |
| 7276 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7277 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7278 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7279 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7280 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7281 | |
| 7282 | HttpRequestInfo request; |
| 7283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7284 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7285 | request.load_flags = 0; |
| 7286 | |
| 7287 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7288 | MockWrite( |
| 7289 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7290 | "Host: www.example.org\r\n" |
| 7291 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7292 | }; |
| 7293 | |
| 7294 | MockRead data_reads[] = { |
| 7295 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7296 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7297 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7298 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7299 | }; |
| 7300 | |
| 7301 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7302 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7303 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7304 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7308 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7309 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7310 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7311 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7312 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7314 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7315 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7316 | |
| 7317 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7318 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7319 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7320 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7321 | } |
| 7322 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7323 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7324 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7325 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7326 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7327 | |
| 7328 | HttpRequestInfo request; |
| 7329 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7330 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7331 | request.load_flags = 0; |
| 7332 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7333 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7334 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7335 | scoped_ptr<SpdyFrame> rst( |
| 7336 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7337 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7338 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | static const char* const kExtraHeaders[] = { |
| 7342 | "location", |
| 7343 | "http://login.example.com/", |
| 7344 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7345 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7346 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7347 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7348 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7349 | spdy_util_.ConstructSpdyBodyFrame( |
| 7350 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7351 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7352 | CreateMockRead(*resp.get(), 1), |
| 7353 | CreateMockRead(*body.get(), 2), |
| 7354 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7355 | }; |
| 7356 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7357 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7358 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7359 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7360 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7361 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7365 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7366 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7367 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7368 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7369 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7371 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7373 | |
| 7374 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7375 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7376 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7377 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7378 | } |
| 7379 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7380 | // Test the request-challenge-retry sequence for basic auth, through |
| 7381 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7382 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7383 | HttpRequestInfo request; |
| 7384 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7385 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7386 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7387 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7388 | |
| 7389 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7390 | session_deps_.proxy_service = |
| 7391 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7392 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7393 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7394 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7395 | |
| 7396 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7397 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7398 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7399 | scoped_ptr<SpdyFrame> rst( |
| 7400 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7401 | |
| 7402 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7403 | // be issuing -- the final header line contains the credentials. |
| 7404 | const char* const kAuthCredentials[] = { |
| 7405 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7406 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7407 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7408 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7409 | HostPortPair("www.example.org", 443))); |
| 7410 | // fetch https://www.example.org/ via HTTP |
| 7411 | const char get[] = |
| 7412 | "GET / HTTP/1.1\r\n" |
| 7413 | "Host: www.example.org\r\n" |
| 7414 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7415 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7416 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7417 | |
| 7418 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7419 | CreateMockWrite(*req, 0, ASYNC), |
| 7420 | CreateMockWrite(*rst, 2, ASYNC), |
| 7421 | CreateMockWrite(*connect2, 3), |
| 7422 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7423 | }; |
| 7424 | |
| 7425 | // The proxy responds to the connect with a 407, using a persistent |
| 7426 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7427 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7428 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7429 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7430 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7431 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7432 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7433 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7434 | scoped_ptr<SpdyFrame> conn_resp( |
| 7435 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7436 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7437 | "Content-Length: 5\r\n\r\n"; |
| 7438 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7439 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7440 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7441 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7442 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7443 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7444 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7445 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7446 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7447 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7448 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7449 | }; |
| 7450 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7451 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7452 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7453 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7454 | // Negotiate SPDY to the proxy |
| 7455 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7456 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7458 | // Vanilla SSL to the server |
| 7459 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7461 | |
| 7462 | TestCompletionCallback callback1; |
| 7463 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7464 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7465 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7466 | |
| 7467 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7469 | |
| 7470 | rv = callback1.WaitForResult(); |
| 7471 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7472 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7473 | log.GetEntries(&entries); |
| 7474 | size_t pos = ExpectLogContainsSomewhere( |
| 7475 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7476 | NetLog::PHASE_NONE); |
| 7477 | ExpectLogContainsSomewhere( |
| 7478 | entries, pos, |
| 7479 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7480 | NetLog::PHASE_NONE); |
| 7481 | |
| 7482 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7483 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7484 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7485 | EXPECT_EQ(407, response->headers->response_code()); |
| 7486 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7487 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7488 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7489 | |
| 7490 | TestCompletionCallback callback2; |
| 7491 | |
| 7492 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7493 | callback2.callback()); |
| 7494 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7495 | |
| 7496 | rv = callback2.WaitForResult(); |
| 7497 | EXPECT_EQ(OK, rv); |
| 7498 | |
| 7499 | response = trans->GetResponseInfo(); |
| 7500 | ASSERT_TRUE(response != NULL); |
| 7501 | |
| 7502 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7503 | EXPECT_EQ(200, response->headers->response_code()); |
| 7504 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7505 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7506 | |
| 7507 | // The password prompt info should not be set. |
| 7508 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7509 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7510 | LoadTimingInfo load_timing_info; |
| 7511 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7512 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7513 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7514 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7515 | trans.reset(); |
| 7516 | session->CloseAllConnections(); |
| 7517 | } |
| 7518 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7519 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7520 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7521 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7522 | HttpRequestInfo request; |
| 7523 | HttpRequestInfo push_request; |
| 7524 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7526 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7527 | push_request.method = "GET"; |
| 7528 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7529 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7530 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7531 | session_deps_.proxy_service = |
| 7532 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7533 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7534 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7535 | |
| 7536 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7537 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7538 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7539 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7540 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7541 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7542 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7543 | |
| 7544 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7545 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7546 | }; |
| 7547 | |
| 7548 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7549 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7550 | |
| 7551 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7552 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7553 | |
| 7554 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7555 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7556 | 0, |
| 7557 | 2, |
| 7558 | 1, |
| 7559 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7560 | const char kPushedData[] = "pushed"; |
| 7561 | scoped_ptr<SpdyFrame> stream2_body( |
| 7562 | spdy_util_.ConstructSpdyBodyFrame( |
| 7563 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7564 | |
| 7565 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7566 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7567 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7568 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7569 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7570 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7571 | }; |
| 7572 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7573 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7574 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7575 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7576 | // Negotiate SPDY to the proxy |
| 7577 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7578 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7580 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7581 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7582 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7583 | TestCompletionCallback callback; |
| 7584 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7586 | |
| 7587 | rv = callback.WaitForResult(); |
| 7588 | EXPECT_EQ(OK, rv); |
| 7589 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7590 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7591 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7592 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7593 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7594 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7595 | |
| 7596 | rv = callback.WaitForResult(); |
| 7597 | EXPECT_EQ(OK, rv); |
| 7598 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7599 | |
| 7600 | ASSERT_TRUE(response != NULL); |
| 7601 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7602 | |
| 7603 | EXPECT_EQ(200, response->headers->response_code()); |
| 7604 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7605 | |
| 7606 | std::string response_data; |
| 7607 | rv = ReadTransaction(trans.get(), &response_data); |
| 7608 | EXPECT_EQ(OK, rv); |
| 7609 | EXPECT_EQ("hello!", response_data); |
| 7610 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7611 | LoadTimingInfo load_timing_info; |
| 7612 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7613 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7614 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7615 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7616 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7617 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7618 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7619 | |
| 7620 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7621 | EXPECT_EQ(OK, rv); |
| 7622 | EXPECT_EQ("pushed", response_data); |
| 7623 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7624 | LoadTimingInfo push_load_timing_info; |
| 7625 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7626 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7627 | // The transactions should share a socket ID, despite being for different |
| 7628 | // origins. |
| 7629 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7630 | push_load_timing_info.socket_log_id); |
| 7631 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7632 | trans.reset(); |
| 7633 | push_trans.reset(); |
| 7634 | session->CloseAllConnections(); |
| 7635 | } |
| 7636 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7637 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7638 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7639 | HttpRequestInfo request; |
| 7640 | |
| 7641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7642 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7643 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7644 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7645 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7646 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7647 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7648 | |
| 7649 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7650 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7651 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7652 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7653 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7654 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7655 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7656 | |
| 7657 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7658 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7659 | |
| 7660 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7661 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7662 | }; |
| 7663 | |
| 7664 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7665 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7666 | |
| 7667 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7668 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7669 | |
| 7670 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7671 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7672 | 0, |
| 7673 | 2, |
| 7674 | 1, |
| 7675 | "https://www.another-origin.com/foo.dat")); |
| 7676 | |
| 7677 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7678 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7679 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7680 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7681 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7682 | }; |
| 7683 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7684 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7685 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7686 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7687 | // Negotiate SPDY to the proxy |
| 7688 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7689 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7691 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7692 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7693 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7694 | TestCompletionCallback callback; |
| 7695 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7696 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7697 | |
| 7698 | rv = callback.WaitForResult(); |
| 7699 | EXPECT_EQ(OK, rv); |
| 7700 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7701 | |
| 7702 | ASSERT_TRUE(response != NULL); |
| 7703 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7704 | |
| 7705 | EXPECT_EQ(200, response->headers->response_code()); |
| 7706 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7707 | |
| 7708 | std::string response_data; |
| 7709 | rv = ReadTransaction(trans.get(), &response_data); |
| 7710 | EXPECT_EQ(OK, rv); |
| 7711 | EXPECT_EQ("hello!", response_data); |
| 7712 | |
| 7713 | trans.reset(); |
| 7714 | session->CloseAllConnections(); |
| 7715 | } |
| 7716 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7717 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7718 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7719 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7720 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7721 | |
| 7722 | HttpRequestInfo request; |
| 7723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7724 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7725 | request.load_flags = 0; |
| 7726 | |
| 7727 | // Attempt to fetch the URL from a server with a bad cert |
| 7728 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7729 | MockWrite( |
| 7730 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7731 | "Host: www.example.org\r\n" |
| 7732 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7733 | }; |
| 7734 | |
| 7735 | MockRead bad_cert_reads[] = { |
| 7736 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7737 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7738 | }; |
| 7739 | |
| 7740 | // Attempt to fetch the URL with a good cert |
| 7741 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7742 | MockWrite( |
| 7743 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7744 | "Host: www.example.org\r\n" |
| 7745 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7746 | MockWrite( |
| 7747 | "GET / HTTP/1.1\r\n" |
| 7748 | "Host: www.example.org\r\n" |
| 7749 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7750 | }; |
| 7751 | |
| 7752 | MockRead good_cert_reads[] = { |
| 7753 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7754 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7755 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7756 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7758 | }; |
| 7759 | |
| 7760 | StaticSocketDataProvider ssl_bad_certificate( |
| 7761 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7762 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7763 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7764 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7765 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7766 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7767 | |
| 7768 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7770 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7772 | |
| 7773 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7774 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7778 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7779 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7780 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7781 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7782 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7784 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7786 | |
| 7787 | rv = callback.WaitForResult(); |
| 7788 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7790 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7791 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7792 | |
| 7793 | rv = callback.WaitForResult(); |
| 7794 | EXPECT_EQ(OK, rv); |
| 7795 | |
| 7796 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7797 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7798 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7799 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7800 | } |
| 7801 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7802 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7803 | HttpRequestInfo request; |
| 7804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7805 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7806 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7807 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7808 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7809 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7810 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7812 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7813 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7814 | MockWrite( |
| 7815 | "GET / HTTP/1.1\r\n" |
| 7816 | "Host: www.example.org\r\n" |
| 7817 | "Connection: keep-alive\r\n" |
| 7818 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7819 | }; |
| 7820 | |
| 7821 | // Lastly, the server responds with the actual content. |
| 7822 | MockRead data_reads[] = { |
| 7823 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7824 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7825 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7826 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7827 | }; |
| 7828 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7829 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7830 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7831 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7833 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7835 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7836 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7837 | |
| 7838 | rv = callback.WaitForResult(); |
| 7839 | EXPECT_EQ(OK, rv); |
| 7840 | } |
| 7841 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7842 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7843 | HttpRequestInfo request; |
| 7844 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7845 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7846 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7847 | "Chromium Ultra Awesome X Edition"); |
| 7848 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7849 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7850 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7851 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7852 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7853 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7854 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7855 | MockWrite( |
| 7856 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7857 | "Host: www.example.org\r\n" |
| 7858 | "Proxy-Connection: keep-alive\r\n" |
| 7859 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7860 | }; |
| 7861 | MockRead data_reads[] = { |
| 7862 | // Return an error, so the transaction stops here (this test isn't |
| 7863 | // interested in the rest). |
| 7864 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7865 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7866 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7867 | }; |
| 7868 | |
| 7869 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7870 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7873 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7875 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7877 | |
| 7878 | rv = callback.WaitForResult(); |
| 7879 | EXPECT_EQ(OK, rv); |
| 7880 | } |
| 7881 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7882 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7883 | HttpRequestInfo request; |
| 7884 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7885 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7886 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7887 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7888 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7889 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7890 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7891 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7893 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7894 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7895 | MockWrite( |
| 7896 | "GET / HTTP/1.1\r\n" |
| 7897 | "Host: www.example.org\r\n" |
| 7898 | "Connection: keep-alive\r\n" |
| 7899 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7900 | }; |
| 7901 | |
| 7902 | // Lastly, the server responds with the actual content. |
| 7903 | MockRead data_reads[] = { |
| 7904 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7905 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7906 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7907 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7908 | }; |
| 7909 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7910 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7911 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7914 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7916 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7918 | |
| 7919 | rv = callback.WaitForResult(); |
| 7920 | EXPECT_EQ(OK, rv); |
| 7921 | } |
| 7922 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7923 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7924 | HttpRequestInfo request; |
| 7925 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7926 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7927 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7928 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7929 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7930 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7931 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7932 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7933 | MockWrite( |
| 7934 | "POST / HTTP/1.1\r\n" |
| 7935 | "Host: www.example.org\r\n" |
| 7936 | "Connection: keep-alive\r\n" |
| 7937 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7938 | }; |
| 7939 | |
| 7940 | // Lastly, the server responds with the actual content. |
| 7941 | MockRead data_reads[] = { |
| 7942 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7943 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7944 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7946 | }; |
| 7947 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7948 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7949 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7952 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7954 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7956 | |
| 7957 | rv = callback.WaitForResult(); |
| 7958 | EXPECT_EQ(OK, rv); |
| 7959 | } |
| 7960 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7961 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7962 | HttpRequestInfo request; |
| 7963 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7964 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7965 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7966 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7967 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7968 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7969 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7970 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7971 | MockWrite( |
| 7972 | "PUT / HTTP/1.1\r\n" |
| 7973 | "Host: www.example.org\r\n" |
| 7974 | "Connection: keep-alive\r\n" |
| 7975 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7976 | }; |
| 7977 | |
| 7978 | // Lastly, the server responds with the actual content. |
| 7979 | MockRead data_reads[] = { |
| 7980 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7981 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7982 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7984 | }; |
| 7985 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7986 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7987 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7990 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7992 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7994 | |
| 7995 | rv = callback.WaitForResult(); |
| 7996 | EXPECT_EQ(OK, rv); |
| 7997 | } |
| 7998 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7999 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8000 | HttpRequestInfo request; |
| 8001 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8002 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8003 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8004 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8005 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8007 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8008 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8009 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8010 | "Host: www.example.org\r\n" |
| 8011 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8012 | }; |
| 8013 | |
| 8014 | // Lastly, the server responds with the actual content. |
| 8015 | MockRead data_reads[] = { |
| 8016 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8017 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8018 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8020 | }; |
| 8021 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8022 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8023 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8024 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8026 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8028 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8029 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8030 | |
| 8031 | rv = callback.WaitForResult(); |
| 8032 | EXPECT_EQ(OK, rv); |
| 8033 | } |
| 8034 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8035 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8036 | HttpRequestInfo request; |
| 8037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8038 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8039 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8040 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8041 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8042 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8043 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8044 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8045 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8046 | MockWrite( |
| 8047 | "GET / HTTP/1.1\r\n" |
| 8048 | "Host: www.example.org\r\n" |
| 8049 | "Connection: keep-alive\r\n" |
| 8050 | "Pragma: no-cache\r\n" |
| 8051 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8052 | }; |
| 8053 | |
| 8054 | // Lastly, the server responds with the actual content. |
| 8055 | MockRead data_reads[] = { |
| 8056 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8057 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8058 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8059 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8060 | }; |
| 8061 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8062 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8063 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8064 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8066 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8068 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8070 | |
| 8071 | rv = callback.WaitForResult(); |
| 8072 | EXPECT_EQ(OK, rv); |
| 8073 | } |
| 8074 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8075 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8076 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8077 | HttpRequestInfo request; |
| 8078 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8079 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8080 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8081 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8082 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8083 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8084 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8085 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8086 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8087 | MockWrite( |
| 8088 | "GET / HTTP/1.1\r\n" |
| 8089 | "Host: www.example.org\r\n" |
| 8090 | "Connection: keep-alive\r\n" |
| 8091 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8092 | }; |
| 8093 | |
| 8094 | // Lastly, the server responds with the actual content. |
| 8095 | MockRead data_reads[] = { |
| 8096 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8097 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8098 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8099 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8100 | }; |
| 8101 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8102 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8103 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8104 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8106 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8108 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8109 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8110 | |
| 8111 | rv = callback.WaitForResult(); |
| 8112 | EXPECT_EQ(OK, rv); |
| 8113 | } |
| 8114 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8115 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8116 | HttpRequestInfo request; |
| 8117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8118 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8119 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8120 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8121 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8122 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8124 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8125 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8126 | MockWrite( |
| 8127 | "GET / HTTP/1.1\r\n" |
| 8128 | "Host: www.example.org\r\n" |
| 8129 | "Connection: keep-alive\r\n" |
| 8130 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8131 | }; |
| 8132 | |
| 8133 | // Lastly, the server responds with the actual content. |
| 8134 | MockRead data_reads[] = { |
| 8135 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8136 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8137 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8138 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8139 | }; |
| 8140 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8141 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8142 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8145 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8147 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8148 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8149 | |
| 8150 | rv = callback.WaitForResult(); |
| 8151 | EXPECT_EQ(OK, rv); |
| 8152 | } |
| 8153 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8154 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8155 | HttpRequestInfo request; |
| 8156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8157 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8158 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8159 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8160 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8161 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8162 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8163 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8165 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8166 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8167 | MockWrite( |
| 8168 | "GET / HTTP/1.1\r\n" |
| 8169 | "Host: www.example.org\r\n" |
| 8170 | "Connection: keep-alive\r\n" |
| 8171 | "referer: www.foo.com\r\n" |
| 8172 | "hEllo: Kitty\r\n" |
| 8173 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8174 | }; |
| 8175 | |
| 8176 | // Lastly, the server responds with the actual content. |
| 8177 | MockRead data_reads[] = { |
| 8178 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8179 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8180 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8182 | }; |
| 8183 | |
| 8184 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8185 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8186 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8188 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8190 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8192 | |
| 8193 | rv = callback.WaitForResult(); |
| 8194 | EXPECT_EQ(OK, rv); |
| 8195 | } |
| 8196 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8197 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8198 | HttpRequestInfo request; |
| 8199 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8200 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8201 | request.load_flags = 0; |
| 8202 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8203 | session_deps_.proxy_service = |
| 8204 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8205 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8206 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8207 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8208 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8209 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8211 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8212 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8213 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8214 | |
| 8215 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8216 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8217 | MockWrite( |
| 8218 | "GET / HTTP/1.1\r\n" |
| 8219 | "Host: www.example.org\r\n" |
| 8220 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8221 | |
| 8222 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8223 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8224 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8225 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8226 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8227 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8228 | }; |
| 8229 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8230 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8231 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8232 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8234 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8236 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8237 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8238 | |
| 8239 | rv = callback.WaitForResult(); |
| 8240 | EXPECT_EQ(OK, rv); |
| 8241 | |
| 8242 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8243 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8244 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8245 | LoadTimingInfo load_timing_info; |
| 8246 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8247 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8248 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8249 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8250 | std::string response_text; |
| 8251 | rv = ReadTransaction(trans.get(), &response_text); |
| 8252 | EXPECT_EQ(OK, rv); |
| 8253 | EXPECT_EQ("Payload", response_text); |
| 8254 | } |
| 8255 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8256 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8257 | HttpRequestInfo request; |
| 8258 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8259 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8260 | request.load_flags = 0; |
| 8261 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8262 | session_deps_.proxy_service = |
| 8263 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8264 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8265 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8266 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8267 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8268 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8270 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8271 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8272 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8273 | |
| 8274 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8275 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8276 | arraysize(write_buffer)), |
| 8277 | MockWrite( |
| 8278 | "GET / HTTP/1.1\r\n" |
| 8279 | "Host: www.example.org\r\n" |
| 8280 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8281 | |
| 8282 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8283 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8284 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8285 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8286 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8287 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8288 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8289 | }; |
| 8290 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8291 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8292 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8294 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8295 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8298 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8300 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8301 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8302 | |
| 8303 | rv = callback.WaitForResult(); |
| 8304 | EXPECT_EQ(OK, rv); |
| 8305 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8306 | LoadTimingInfo load_timing_info; |
| 8307 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8308 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8309 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8310 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8311 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8312 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8313 | |
| 8314 | std::string response_text; |
| 8315 | rv = ReadTransaction(trans.get(), &response_text); |
| 8316 | EXPECT_EQ(OK, rv); |
| 8317 | EXPECT_EQ("Payload", response_text); |
| 8318 | } |
| 8319 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8320 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8321 | HttpRequestInfo request; |
| 8322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8323 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8324 | request.load_flags = 0; |
| 8325 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8326 | session_deps_.proxy_service = |
| 8327 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8328 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8329 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8330 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8331 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8332 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8334 | |
| 8335 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8336 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8337 | |
| 8338 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8339 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8340 | MockWrite( |
| 8341 | "GET / HTTP/1.1\r\n" |
| 8342 | "Host: www.example.org\r\n" |
| 8343 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8344 | |
| 8345 | MockRead data_reads[] = { |
| 8346 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8347 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8348 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8349 | MockRead("Payload"), |
| 8350 | MockRead(SYNCHRONOUS, OK) |
| 8351 | }; |
| 8352 | |
| 8353 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8354 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8356 | |
| 8357 | TestCompletionCallback callback; |
| 8358 | |
| 8359 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8360 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8361 | |
| 8362 | rv = callback.WaitForResult(); |
| 8363 | EXPECT_EQ(OK, rv); |
| 8364 | |
| 8365 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8366 | ASSERT_TRUE(response != NULL); |
| 8367 | |
| 8368 | LoadTimingInfo load_timing_info; |
| 8369 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8370 | TestLoadTimingNotReused(load_timing_info, |
| 8371 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8372 | |
| 8373 | std::string response_text; |
| 8374 | rv = ReadTransaction(trans.get(), &response_text); |
| 8375 | EXPECT_EQ(OK, rv); |
| 8376 | EXPECT_EQ("Payload", response_text); |
| 8377 | } |
| 8378 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8379 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8380 | HttpRequestInfo request; |
| 8381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8382 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8383 | request.load_flags = 0; |
| 8384 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8385 | session_deps_.proxy_service = |
| 8386 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8387 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8388 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8389 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8390 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8391 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8392 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8393 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8394 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8395 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8396 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8397 | 0x05, // Version |
| 8398 | 0x01, // Command (CONNECT) |
| 8399 | 0x00, // Reserved. |
| 8400 | 0x03, // Address type (DOMAINNAME). |
| 8401 | 0x0F, // Length of domain (15) |
| 8402 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8403 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8404 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8405 | const char kSOCKS5OkResponse[] = |
| 8406 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8407 | |
| 8408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8409 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8410 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8411 | MockWrite( |
| 8412 | "GET / HTTP/1.1\r\n" |
| 8413 | "Host: www.example.org\r\n" |
| 8414 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8415 | |
| 8416 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8417 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8418 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8419 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8421 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8422 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8423 | }; |
| 8424 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8425 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8426 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8427 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8429 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8431 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8432 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8433 | |
| 8434 | rv = callback.WaitForResult(); |
| 8435 | EXPECT_EQ(OK, rv); |
| 8436 | |
| 8437 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8438 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8439 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8440 | LoadTimingInfo load_timing_info; |
| 8441 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8442 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8443 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8444 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8445 | std::string response_text; |
| 8446 | rv = ReadTransaction(trans.get(), &response_text); |
| 8447 | EXPECT_EQ(OK, rv); |
| 8448 | EXPECT_EQ("Payload", response_text); |
| 8449 | } |
| 8450 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8451 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8452 | HttpRequestInfo request; |
| 8453 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8454 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8455 | request.load_flags = 0; |
| 8456 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8457 | session_deps_.proxy_service = |
| 8458 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8459 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8460 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8461 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8462 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8463 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8465 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8466 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8467 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8468 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8469 | 0x05, // Version |
| 8470 | 0x01, // Command (CONNECT) |
| 8471 | 0x00, // Reserved. |
| 8472 | 0x03, // Address type (DOMAINNAME). |
| 8473 | 0x0F, // Length of domain (15) |
| 8474 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8475 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8476 | }; |
| 8477 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8478 | const char kSOCKS5OkResponse[] = |
| 8479 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8480 | |
| 8481 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8482 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8483 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8484 | arraysize(kSOCKS5OkRequest)), |
| 8485 | MockWrite( |
| 8486 | "GET / HTTP/1.1\r\n" |
| 8487 | "Host: www.example.org\r\n" |
| 8488 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8489 | |
| 8490 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8491 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8492 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8493 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8494 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8495 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8496 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8497 | }; |
| 8498 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8499 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8500 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8502 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8503 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8506 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8507 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8508 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8509 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8510 | |
| 8511 | rv = callback.WaitForResult(); |
| 8512 | EXPECT_EQ(OK, rv); |
| 8513 | |
| 8514 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8515 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8516 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8517 | LoadTimingInfo load_timing_info; |
| 8518 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8519 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8520 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8521 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8522 | std::string response_text; |
| 8523 | rv = ReadTransaction(trans.get(), &response_text); |
| 8524 | EXPECT_EQ(OK, rv); |
| 8525 | EXPECT_EQ("Payload", response_text); |
| 8526 | } |
| 8527 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8528 | namespace { |
| 8529 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8530 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8531 | |
| 8532 | struct GroupNameTest { |
| 8533 | std::string proxy_server; |
| 8534 | std::string url; |
| 8535 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8536 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8537 | }; |
| 8538 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8539 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8540 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8541 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8542 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8543 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8544 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8545 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8546 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8547 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8548 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8549 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8550 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8551 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8552 | |
| 8553 | return session; |
| 8554 | } |
| 8555 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8556 | int GroupNameTransactionHelper(const std::string& url, |
| 8557 | 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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8564 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8615 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8618 | HttpNetworkSessionPeer peer(session.get()); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8630 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8677 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8680 | HttpNetworkSessionPeer peer(session.get()); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8695 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8747 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8750 | HttpNetworkSessionPeer peer(session.get()); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8768 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8790 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8816 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8885 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8917 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8995 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9051 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9068 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9117 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9172 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9226 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9333 | scoped_ptr<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 | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9428 | scoped_ptr<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 | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9464 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
| 9465 | session_deps_.next_protos = SpdyNextProtos(); |
| 9466 | session_deps_.use_alternative_services = true; |
| 9467 | |
| 9468 | // Set an alternative service for origin. |
| 9469 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9470 | HttpServerProperties& http_server_properties = |
| 9471 | *session->http_server_properties(); |
| 9472 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9473 | AlternativeService alternative_service(QUIC, "", 80); |
| 9474 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9475 | http_server_properties.SetAlternativeService( |
| 9476 | http_host_port_pair, alternative_service, 1.0, expiration); |
| 9477 | AlternativeServiceVector alternative_service_vector = |
| 9478 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9479 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9480 | |
| 9481 | // Send a clear header. |
| 9482 | MockRead data_reads[] = { |
| 9483 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9484 | MockRead("Alt-Svc: clear\r\n"), |
| 9485 | MockRead("\r\n"), |
| 9486 | MockRead("hello world"), |
| 9487 | MockRead(SYNCHRONOUS, OK), |
| 9488 | }; |
| 9489 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9490 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9491 | |
| 9492 | HttpRequestInfo request; |
| 9493 | request.method = "GET"; |
| 9494 | request.url = GURL("http://www.example.org/"); |
| 9495 | request.load_flags = 0; |
| 9496 | |
| 9497 | TestCompletionCallback callback; |
| 9498 | |
| 9499 | scoped_ptr<HttpTransaction> trans( |
| 9500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9501 | |
| 9502 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9503 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9504 | |
| 9505 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9506 | ASSERT_TRUE(response != nullptr); |
| 9507 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9508 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9509 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9510 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9511 | |
| 9512 | std::string response_data; |
| 9513 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9514 | EXPECT_EQ("hello world", response_data); |
| 9515 | |
| 9516 | alternative_service_vector = |
| 9517 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9518 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9519 | } |
| 9520 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9521 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9522 | // is false. |
| 9523 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9524 | session_deps_.next_protos = SpdyNextProtos(); |
| 9525 | session_deps_.use_alternative_services = false; |
| 9526 | |
| 9527 | std::string alternative_service_http_header = |
| 9528 | GetAlternativeServiceHttpHeader(); |
| 9529 | |
| 9530 | MockRead data_reads[] = { |
| 9531 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9532 | MockRead(alternative_service_http_header.c_str()), |
| 9533 | MockRead("\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), nullptr, 0); |
| 9544 | |
| 9545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9546 | |
| 9547 | TestCompletionCallback callback; |
| 9548 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9549 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [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 != nullptr); |
| 9567 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 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 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9579 | } |
| 9580 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9581 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9582 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9583 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9584 | |
| 9585 | MockRead data_reads[] = { |
| 9586 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9587 | MockRead("Alt-Svc: "), |
| 9588 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame^] | 9589 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9590 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9591 | MockRead("hello world"), |
| 9592 | MockRead(SYNCHRONOUS, OK), |
| 9593 | }; |
| 9594 | |
| 9595 | HttpRequestInfo request; |
| 9596 | request.method = "GET"; |
| 9597 | request.url = GURL("http://www.example.org/"); |
| 9598 | request.load_flags = 0; |
| 9599 | |
| 9600 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9601 | |
| 9602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9603 | |
| 9604 | TestCompletionCallback callback; |
| 9605 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9606 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9607 | scoped_ptr<HttpTransaction> trans( |
| 9608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9609 | |
| 9610 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9612 | |
| 9613 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9614 | HttpServerProperties& http_server_properties = |
| 9615 | *session->http_server_properties(); |
| 9616 | AlternativeServiceVector alternative_service_vector = |
| 9617 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9618 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9619 | |
| 9620 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9621 | |
| 9622 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9623 | ASSERT_TRUE(response != NULL); |
| 9624 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9625 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9626 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9627 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9628 | |
| 9629 | std::string response_data; |
| 9630 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9631 | EXPECT_EQ("hello world", response_data); |
| 9632 | |
| 9633 | alternative_service_vector = |
| 9634 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9635 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 9636 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9637 | alternative_service_vector[0].protocol); |
| 9638 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9639 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9640 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9641 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9642 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9643 | } |
| 9644 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9645 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9646 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9647 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9648 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9649 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9650 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9651 | std::string alternate_protocol_http_header = |
| 9652 | GetAlternateProtocolHttpHeader(); |
| 9653 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9654 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9655 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9656 | MockRead(alternate_protocol_http_header.c_str()), |
| 9657 | MockRead("\r\n"), |
| 9658 | MockRead("hello world"), |
| 9659 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 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/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9665 | request.load_flags = 0; |
| 9666 | |
| 9667 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9668 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9671 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9672 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9673 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9674 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9675 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9677 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9678 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9679 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9680 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9681 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9682 | *session->http_server_properties(); |
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 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9686 | |
| 9687 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9688 | |
| 9689 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9690 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9691 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9692 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9693 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9694 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9695 | |
| 9696 | std::string response_data; |
| 9697 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9698 | EXPECT_EQ("hello world", response_data); |
| 9699 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9700 | alternative_service_vector = |
| 9701 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9702 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9703 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9704 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9705 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9706 | } |
| 9707 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9708 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9709 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9710 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9711 | |
| 9712 | MockRead data_reads[] = { |
| 9713 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9714 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9715 | MockRead("hello world"), |
| 9716 | MockRead(SYNCHRONOUS, OK), |
| 9717 | }; |
| 9718 | |
| 9719 | HttpRequestInfo request; |
| 9720 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9721 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9722 | request.load_flags = 0; |
| 9723 | |
| 9724 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9725 | |
| 9726 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9727 | |
| 9728 | TestCompletionCallback callback; |
| 9729 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9730 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9731 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9732 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9733 | HttpServerProperties& http_server_properties = |
| 9734 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9735 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9736 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9737 | http_server_properties.SetAlternativeService( |
| 9738 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9739 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9740 | AlternativeServiceVector alternative_service_vector = |
| 9741 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9742 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9743 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9744 | |
| 9745 | scoped_ptr<HttpTransaction> trans( |
| 9746 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9747 | |
| 9748 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9749 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9750 | |
| 9751 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9752 | |
| 9753 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9754 | ASSERT_TRUE(response != NULL); |
| 9755 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9756 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9757 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9758 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9759 | |
| 9760 | std::string response_data; |
| 9761 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9762 | EXPECT_EQ("hello world", response_data); |
| 9763 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9764 | alternative_service_vector = |
| 9765 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9766 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9767 | } |
| 9768 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9769 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9770 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9771 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9772 | |
| 9773 | std::string alternative_service_http_header = |
| 9774 | GetAlternativeServiceHttpHeader(); |
| 9775 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9776 | |
| 9777 | MockRead data_reads[] = { |
| 9778 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9779 | MockRead(alternative_service_http_header.c_str()), |
| 9780 | MockRead(alternate_protocol_http_header.c_str()), |
| 9781 | MockRead("\r\n"), |
| 9782 | MockRead("hello world"), |
| 9783 | MockRead(SYNCHRONOUS, OK), |
| 9784 | }; |
| 9785 | |
| 9786 | HttpRequestInfo request; |
| 9787 | request.method = "GET"; |
| 9788 | request.url = GURL("http://www.example.org/"); |
| 9789 | request.load_flags = 0; |
| 9790 | |
| 9791 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9792 | |
| 9793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9794 | |
| 9795 | TestCompletionCallback callback; |
| 9796 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9797 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9798 | scoped_ptr<HttpTransaction> trans( |
| 9799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9800 | |
| 9801 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9803 | |
| 9804 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9805 | HttpServerProperties& http_server_properties = |
| 9806 | *session->http_server_properties(); |
| 9807 | AlternativeServiceVector alternative_service_vector = |
| 9808 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9809 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9810 | |
| 9811 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9812 | |
| 9813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9814 | ASSERT_TRUE(response != NULL); |
| 9815 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9816 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9817 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9818 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9819 | |
| 9820 | std::string response_data; |
| 9821 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9822 | EXPECT_EQ("hello world", response_data); |
| 9823 | |
| 9824 | alternative_service_vector = |
| 9825 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9826 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9827 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9828 | alternative_service_vector[0].protocol); |
| 9829 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9830 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9831 | } |
| 9832 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9833 | // When |use_alternative_services| is false, do not observe alternative service |
| 9834 | // entries that point to a different host. |
| 9835 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9836 | session_deps_.use_alternative_services = false; |
| 9837 | |
| 9838 | HttpRequestInfo request; |
| 9839 | request.method = "GET"; |
| 9840 | request.url = GURL("http://www.example.org/"); |
| 9841 | request.load_flags = 0; |
| 9842 | |
| 9843 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9844 | StaticSocketDataProvider first_data; |
| 9845 | first_data.set_connect_data(mock_connect); |
| 9846 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9847 | |
| 9848 | MockRead data_reads[] = { |
| 9849 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9850 | MockRead(ASYNC, OK), |
| 9851 | }; |
| 9852 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9853 | nullptr, 0); |
| 9854 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9855 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9856 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9857 | |
| 9858 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9859 | session->http_server_properties(); |
| 9860 | AlternativeService alternative_service( |
| 9861 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9862 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9863 | http_server_properties->SetAlternativeService( |
| 9864 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9865 | |
| 9866 | scoped_ptr<HttpTransaction> trans( |
| 9867 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9868 | TestCompletionCallback callback; |
| 9869 | |
| 9870 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9871 | // The connetion to origin was refused, and the alternative service should not |
| 9872 | // be used (even though mock data are there), therefore the request should |
| 9873 | // fail. |
| 9874 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9875 | } |
| 9876 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9877 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9878 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9879 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9880 | |
| 9881 | HttpRequestInfo request; |
| 9882 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9883 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9884 | request.load_flags = 0; |
| 9885 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9886 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9887 | StaticSocketDataProvider first_data; |
| 9888 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9889 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9890 | |
| 9891 | MockRead data_reads[] = { |
| 9892 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9893 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9894 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9895 | }; |
| 9896 | StaticSocketDataProvider second_data( |
| 9897 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9898 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9899 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9900 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9901 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9902 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9903 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9904 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9905 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9906 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9907 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9908 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9909 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9910 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9911 | http_server_properties->SetAlternativeService( |
| 9912 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9913 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9914 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9915 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9916 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9918 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9920 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9921 | |
| 9922 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9923 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9924 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9925 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9926 | |
| 9927 | std::string response_data; |
| 9928 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9929 | EXPECT_EQ("hello world", response_data); |
| 9930 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9931 | const AlternativeServiceVector alternative_service_vector = |
| 9932 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9933 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9934 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9935 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9936 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9937 | } |
| 9938 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9939 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9940 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9941 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9942 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9943 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9944 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9945 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9946 | |
| 9947 | HttpRequestInfo restricted_port_request; |
| 9948 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9949 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9950 | restricted_port_request.load_flags = 0; |
| 9951 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9952 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9953 | StaticSocketDataProvider first_data; |
| 9954 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9955 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9956 | |
| 9957 | MockRead data_reads[] = { |
| 9958 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9959 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9960 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9961 | }; |
| 9962 | StaticSocketDataProvider second_data( |
| 9963 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9964 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9965 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9966 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9967 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9968 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9969 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9970 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9971 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9972 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9973 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9974 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9975 | http_server_properties->SetAlternativeService( |
| 9976 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9977 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9978 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9979 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9980 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9981 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9983 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9984 | &restricted_port_request, |
| 9985 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9986 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9987 | // Invalid change to unrestricted port should fail. |
| 9988 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9989 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9990 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9991 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9992 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9993 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9994 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9995 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9996 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9997 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9998 | |
| 9999 | HttpRequestInfo restricted_port_request; |
| 10000 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10001 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10002 | restricted_port_request.load_flags = 0; |
| 10003 | |
| 10004 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10005 | StaticSocketDataProvider first_data; |
| 10006 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10007 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10008 | |
| 10009 | MockRead data_reads[] = { |
| 10010 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10011 | MockRead("hello world"), |
| 10012 | MockRead(ASYNC, OK), |
| 10013 | }; |
| 10014 | StaticSocketDataProvider second_data( |
| 10015 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10016 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10017 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10018 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10019 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10020 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10021 | session->http_server_properties(); |
| 10022 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10023 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10024 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10025 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10026 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10027 | http_server_properties->SetAlternativeService( |
| 10028 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10029 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10030 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10031 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10033 | TestCompletionCallback callback; |
| 10034 | |
| 10035 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10036 | &restricted_port_request, |
| 10037 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10038 | // Change to unrestricted port should succeed. |
| 10039 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10040 | } |
| 10041 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10042 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10043 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10044 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10045 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10046 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10047 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10048 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10049 | |
| 10050 | HttpRequestInfo restricted_port_request; |
| 10051 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10052 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10053 | restricted_port_request.load_flags = 0; |
| 10054 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10055 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10056 | StaticSocketDataProvider first_data; |
| 10057 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10058 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10059 | |
| 10060 | MockRead data_reads[] = { |
| 10061 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10062 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10063 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10064 | }; |
| 10065 | StaticSocketDataProvider second_data( |
| 10066 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10067 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10068 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10069 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10070 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10071 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10072 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10073 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10074 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10075 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10076 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10077 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10078 | http_server_properties->SetAlternativeService( |
| 10079 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10080 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10081 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10082 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10084 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10086 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10087 | &restricted_port_request, |
| 10088 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10090 | // Valid change to restricted port should pass. |
| 10091 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10092 | } |
| 10093 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10094 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10095 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10096 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10097 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10098 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10099 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10100 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10101 | |
| 10102 | HttpRequestInfo unrestricted_port_request; |
| 10103 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10104 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10105 | unrestricted_port_request.load_flags = 0; |
| 10106 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10107 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10108 | StaticSocketDataProvider first_data; |
| 10109 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10110 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10111 | |
| 10112 | MockRead data_reads[] = { |
| 10113 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10114 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10115 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10116 | }; |
| 10117 | StaticSocketDataProvider second_data( |
| 10118 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10119 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10120 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10121 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10122 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10123 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10124 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10125 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10126 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10127 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10128 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10129 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10130 | http_server_properties->SetAlternativeService( |
| 10131 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10132 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10133 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10134 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10136 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10138 | int rv = trans->Start( |
| 10139 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10140 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10141 | // Valid change to restricted port should pass. |
| 10142 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10143 | } |
| 10144 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10145 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10146 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10147 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10148 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10149 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10150 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10151 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10152 | |
| 10153 | HttpRequestInfo unrestricted_port_request; |
| 10154 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10155 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10156 | unrestricted_port_request.load_flags = 0; |
| 10157 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10158 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10159 | StaticSocketDataProvider first_data; |
| 10160 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10161 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10162 | |
| 10163 | MockRead data_reads[] = { |
| 10164 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10165 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10166 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10167 | }; |
| 10168 | StaticSocketDataProvider second_data( |
| 10169 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10170 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10171 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10172 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10173 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10174 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10175 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10176 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10177 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10178 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10179 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10180 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10181 | http_server_properties->SetAlternativeService( |
| 10182 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10183 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10184 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10185 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10186 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10187 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10189 | int rv = trans->Start( |
| 10190 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10192 | // Valid change to an unrestricted port should pass. |
| 10193 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10194 | } |
| 10195 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10196 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10197 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10198 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10199 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10200 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10201 | |
| 10202 | HttpRequestInfo request; |
| 10203 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10204 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10205 | request.load_flags = 0; |
| 10206 | |
| 10207 | // The alternate protocol request will error out before we attempt to connect, |
| 10208 | // so only the standard HTTP request will try to connect. |
| 10209 | MockRead data_reads[] = { |
| 10210 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10211 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10212 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10213 | }; |
| 10214 | StaticSocketDataProvider data( |
| 10215 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10216 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10217 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10218 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10219 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10220 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10221 | session->http_server_properties(); |
| 10222 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10223 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10224 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10225 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10226 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10227 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10228 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10229 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10230 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10232 | TestCompletionCallback callback; |
| 10233 | |
| 10234 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10236 | // The HTTP request should succeed. |
| 10237 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10238 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10239 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10240 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10241 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10242 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10243 | |
| 10244 | std::string response_data; |
| 10245 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10246 | EXPECT_EQ("hello world", response_data); |
| 10247 | } |
| 10248 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10249 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10250 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10251 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10252 | |
| 10253 | HttpRequestInfo request; |
| 10254 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10255 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10256 | request.load_flags = 0; |
| 10257 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10258 | std::string alternate_protocol_http_header = |
| 10259 | GetAlternateProtocolHttpHeader(); |
| 10260 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10261 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10263 | MockRead(alternate_protocol_http_header.c_str()), |
| 10264 | MockRead("\r\n"), |
| 10265 | MockRead("hello world"), |
| 10266 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10267 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10268 | |
| 10269 | StaticSocketDataProvider first_transaction( |
| 10270 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10271 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10272 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10273 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10274 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10275 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10276 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10277 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10278 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10279 | scoped_ptr<SpdyFrame> req( |
| 10280 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10281 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10282 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10283 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10284 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10285 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10286 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10287 | }; |
| 10288 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10289 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10290 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10291 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10292 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10293 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10294 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10295 | NULL, 0, NULL, 0); |
| 10296 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10297 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10298 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10299 | &hanging_non_alternate_protocol_socket); |
| 10300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10301 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10302 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10303 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10304 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10307 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10308 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10309 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10310 | |
| 10311 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10312 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10313 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10314 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10315 | |
| 10316 | std::string response_data; |
| 10317 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10318 | EXPECT_EQ("hello world", response_data); |
| 10319 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10320 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10322 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10323 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10324 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10325 | |
| 10326 | response = trans->GetResponseInfo(); |
| 10327 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10328 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10329 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10330 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10331 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10332 | |
| 10333 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10334 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10335 | } |
| 10336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10337 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10338 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10339 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10340 | |
| 10341 | HttpRequestInfo request; |
| 10342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10343 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10344 | request.load_flags = 0; |
| 10345 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10346 | std::string alternate_protocol_http_header = |
| 10347 | GetAlternateProtocolHttpHeader(); |
| 10348 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10349 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10350 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10351 | MockRead(alternate_protocol_http_header.c_str()), |
| 10352 | MockRead("\r\n"), |
| 10353 | MockRead("hello world"), |
| 10354 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10355 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10356 | }; |
| 10357 | |
| 10358 | StaticSocketDataProvider first_transaction( |
| 10359 | data_reads, arraysize(data_reads), NULL, 0); |
| 10360 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10361 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10362 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10363 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10364 | StaticSocketDataProvider hanging_socket( |
| 10365 | NULL, 0, NULL, 0); |
| 10366 | hanging_socket.set_connect_data(never_finishing_connect); |
| 10367 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10368 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10369 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 10370 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10371 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10372 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10373 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10374 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10375 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10377 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10378 | scoped_ptr<SpdyFrame> req1( |
| 10379 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10380 | scoped_ptr<SpdyFrame> req2( |
| 10381 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10382 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10383 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10384 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10385 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10386 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10387 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10388 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10389 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10390 | CreateMockRead(*resp1, 2), |
| 10391 | CreateMockRead(*data1, 3), |
| 10392 | CreateMockRead(*resp2, 4), |
| 10393 | CreateMockRead(*data2, 5), |
| 10394 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10395 | }; |
| 10396 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10397 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10398 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10399 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10400 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10401 | |
| 10402 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10403 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10404 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10405 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10406 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10407 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10409 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10410 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10411 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10412 | |
| 10413 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10414 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10415 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10416 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10417 | |
| 10418 | std::string response_data; |
| 10419 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10420 | EXPECT_EQ("hello world", response_data); |
| 10421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10422 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10423 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10424 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10427 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10428 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10429 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10431 | |
| 10432 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10433 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10434 | |
| 10435 | response = trans2.GetResponseInfo(); |
| 10436 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10437 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10438 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10439 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10440 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10441 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10442 | EXPECT_EQ("hello!", response_data); |
| 10443 | |
| 10444 | response = trans3.GetResponseInfo(); |
| 10445 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10446 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10447 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10448 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10449 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10450 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10451 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10452 | } |
| 10453 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10454 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10455 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10456 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10457 | |
| 10458 | HttpRequestInfo request; |
| 10459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10460 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10461 | request.load_flags = 0; |
| 10462 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10463 | std::string alternate_protocol_http_header = |
| 10464 | GetAlternateProtocolHttpHeader(); |
| 10465 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10466 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10467 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10468 | MockRead(alternate_protocol_http_header.c_str()), |
| 10469 | MockRead("\r\n"), |
| 10470 | MockRead("hello world"), |
| 10471 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10472 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10473 | }; |
| 10474 | |
| 10475 | StaticSocketDataProvider first_transaction( |
| 10476 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10477 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10478 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10479 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10480 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10482 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10483 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10484 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10485 | NULL, 0, NULL, 0); |
| 10486 | hanging_alternate_protocol_socket.set_connect_data( |
| 10487 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10488 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10489 | &hanging_alternate_protocol_socket); |
| 10490 | |
| 10491 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10494 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10495 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10496 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10497 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10498 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10500 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10501 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10502 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10503 | |
| 10504 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10505 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10506 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10507 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10508 | |
| 10509 | std::string response_data; |
| 10510 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10511 | EXPECT_EQ("hello world", response_data); |
| 10512 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10513 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10515 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10517 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10518 | |
| 10519 | response = trans->GetResponseInfo(); |
| 10520 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10521 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10522 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10523 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10524 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10525 | |
| 10526 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10527 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10528 | } |
| 10529 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10530 | class CapturingProxyResolver : public ProxyResolver { |
| 10531 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10532 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10533 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10534 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10535 | int GetProxyForURL(const GURL& url, |
| 10536 | ProxyInfo* results, |
| 10537 | const CompletionCallback& callback, |
| 10538 | RequestHandle* request, |
| 10539 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10540 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10541 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10542 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10543 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10544 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10545 | } |
| 10546 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10547 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10548 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10549 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10550 | NOTREACHED(); |
| 10551 | return LOAD_STATE_IDLE; |
| 10552 | } |
| 10553 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10554 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10555 | |
| 10556 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10557 | std::vector<GURL> resolved_; |
| 10558 | |
| 10559 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10560 | }; |
| 10561 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10562 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10563 | public: |
| 10564 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10565 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10566 | |
| 10567 | int CreateProxyResolver( |
| 10568 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10569 | scoped_ptr<ProxyResolver>* resolver, |
| 10570 | const net::CompletionCallback& callback, |
| 10571 | scoped_ptr<Request>* request) override { |
| 10572 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10573 | return OK; |
| 10574 | } |
| 10575 | |
| 10576 | private: |
| 10577 | ProxyResolver* resolver_; |
| 10578 | }; |
| 10579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10580 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10581 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10582 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10583 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10584 | |
| 10585 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10586 | proxy_config.set_auto_detect(true); |
| 10587 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10588 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10589 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10590 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10591 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10592 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10593 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10594 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10595 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10596 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10597 | |
| 10598 | HttpRequestInfo request; |
| 10599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10600 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10601 | request.load_flags = 0; |
| 10602 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10603 | std::string alternate_protocol_http_header = |
| 10604 | GetAlternateProtocolHttpHeader(); |
| 10605 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10606 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10607 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10608 | MockRead(alternate_protocol_http_header.c_str()), |
| 10609 | MockRead("\r\n"), |
| 10610 | MockRead("hello world"), |
| 10611 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10612 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10613 | }; |
| 10614 | |
| 10615 | StaticSocketDataProvider first_transaction( |
| 10616 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10617 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10618 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10619 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10620 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10621 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10622 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10624 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10625 | scoped_ptr<SpdyFrame> req( |
| 10626 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10627 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10628 | MockWrite(ASYNC, 0, |
| 10629 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10630 | "Host: www.example.org\r\n" |
| 10631 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10632 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10633 | }; |
| 10634 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10635 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10636 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10637 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10638 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10639 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10640 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10641 | CreateMockRead(*resp.get(), 3), |
| 10642 | CreateMockRead(*data.get(), 4), |
| 10643 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10644 | }; |
| 10645 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10646 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10647 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10648 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10649 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10650 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10651 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10652 | NULL, 0, NULL, 0); |
| 10653 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10654 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10655 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10656 | &hanging_non_alternate_protocol_socket); |
| 10657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10658 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10659 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10660 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10661 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10662 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10663 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10664 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10666 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10667 | |
| 10668 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10669 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10670 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10671 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10672 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10673 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10674 | |
| 10675 | std::string response_data; |
| 10676 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10677 | EXPECT_EQ("hello world", response_data); |
| 10678 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10679 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10681 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10682 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10683 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10684 | |
| 10685 | response = trans->GetResponseInfo(); |
| 10686 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10687 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10688 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10689 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10690 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10691 | |
| 10692 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10693 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10694 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10695 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10696 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10697 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10698 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10699 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10700 | LoadTimingInfo load_timing_info; |
| 10701 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10702 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10703 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10704 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10705 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10706 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10707 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10708 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10709 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10710 | |
| 10711 | HttpRequestInfo request; |
| 10712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10713 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10714 | request.load_flags = 0; |
| 10715 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10716 | std::string alternate_protocol_http_header = |
| 10717 | GetAlternateProtocolHttpHeader(); |
| 10718 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10719 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10720 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10721 | MockRead(alternate_protocol_http_header.c_str()), |
| 10722 | MockRead("\r\n"), |
| 10723 | MockRead("hello world"), |
| 10724 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10725 | }; |
| 10726 | |
| 10727 | StaticSocketDataProvider first_transaction( |
| 10728 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10729 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10730 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10731 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10732 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10733 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10734 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10736 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10737 | scoped_ptr<SpdyFrame> req( |
| 10738 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10739 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10740 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10741 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10742 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10743 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10744 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10745 | }; |
| 10746 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10747 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10748 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10749 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10750 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10751 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10752 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10753 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10754 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10755 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10758 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10759 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10760 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10761 | |
| 10762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10763 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10764 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10765 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10766 | |
| 10767 | std::string response_data; |
| 10768 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10769 | EXPECT_EQ("hello world", response_data); |
| 10770 | |
| 10771 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10772 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10773 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10774 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10775 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10776 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10777 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10778 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10780 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10781 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10782 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10783 | |
| 10784 | response = trans->GetResponseInfo(); |
| 10785 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10786 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10787 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10788 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10789 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10790 | |
| 10791 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10792 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10793 | } |
| 10794 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10795 | // GenerateAuthToken is a mighty big test. |
| 10796 | // It tests all permutation of GenerateAuthToken behavior: |
| 10797 | // - Synchronous and Asynchronous completion. |
| 10798 | // - OK or error on completion. |
| 10799 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10800 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10801 | // - Non-authenticating and authenticating backend. |
| 10802 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10803 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10804 | // problems generating an auth token for an authenticating proxy, we don't |
| 10805 | // need to test all permutations of the backend server). |
| 10806 | // |
| 10807 | // The test proceeds by going over each of the configuration cases, and |
| 10808 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10809 | // specifies both the configuration for the test as well as the expectations |
| 10810 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10811 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10812 | static const char kServer[] = "http://www.example.com"; |
| 10813 | static const char kSecureServer[] = "https://www.example.com"; |
| 10814 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10815 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10816 | |
| 10817 | enum AuthTiming { |
| 10818 | AUTH_NONE, |
| 10819 | AUTH_SYNC, |
| 10820 | AUTH_ASYNC, |
| 10821 | }; |
| 10822 | |
| 10823 | const MockWrite kGet( |
| 10824 | "GET / HTTP/1.1\r\n" |
| 10825 | "Host: www.example.com\r\n" |
| 10826 | "Connection: keep-alive\r\n\r\n"); |
| 10827 | const MockWrite kGetProxy( |
| 10828 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10829 | "Host: www.example.com\r\n" |
| 10830 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10831 | const MockWrite kGetAuth( |
| 10832 | "GET / HTTP/1.1\r\n" |
| 10833 | "Host: www.example.com\r\n" |
| 10834 | "Connection: keep-alive\r\n" |
| 10835 | "Authorization: auth_token\r\n\r\n"); |
| 10836 | const MockWrite kGetProxyAuth( |
| 10837 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10838 | "Host: www.example.com\r\n" |
| 10839 | "Proxy-Connection: keep-alive\r\n" |
| 10840 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10841 | const MockWrite kGetAuthThroughProxy( |
| 10842 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10843 | "Host: www.example.com\r\n" |
| 10844 | "Proxy-Connection: keep-alive\r\n" |
| 10845 | "Authorization: auth_token\r\n\r\n"); |
| 10846 | const MockWrite kGetAuthWithProxyAuth( |
| 10847 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10848 | "Host: www.example.com\r\n" |
| 10849 | "Proxy-Connection: keep-alive\r\n" |
| 10850 | "Proxy-Authorization: auth_token\r\n" |
| 10851 | "Authorization: auth_token\r\n\r\n"); |
| 10852 | const MockWrite kConnect( |
| 10853 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10854 | "Host: www.example.com\r\n" |
| 10855 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10856 | const MockWrite kConnectProxyAuth( |
| 10857 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10858 | "Host: www.example.com\r\n" |
| 10859 | "Proxy-Connection: keep-alive\r\n" |
| 10860 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10861 | |
| 10862 | const MockRead kSuccess( |
| 10863 | "HTTP/1.1 200 OK\r\n" |
| 10864 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10865 | "Content-Length: 3\r\n\r\n" |
| 10866 | "Yes"); |
| 10867 | const MockRead kFailure( |
| 10868 | "Should not be called."); |
| 10869 | const MockRead kServerChallenge( |
| 10870 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10871 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10872 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10873 | "Content-Length: 14\r\n\r\n" |
| 10874 | "Unauthorized\r\n"); |
| 10875 | const MockRead kProxyChallenge( |
| 10876 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10877 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10878 | "Proxy-Connection: close\r\n" |
| 10879 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10880 | "Content-Length: 14\r\n\r\n" |
| 10881 | "Unauthorized\r\n"); |
| 10882 | const MockRead kProxyConnected( |
| 10883 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10884 | |
| 10885 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10886 | // no constructors, but the C++ compiler on Windows warns about |
| 10887 | // unspecified data in compound literals. So, moved to using constructors, |
| 10888 | // and TestRound's created with the default constructor should not be used. |
| 10889 | struct TestRound { |
| 10890 | TestRound() |
| 10891 | : expected_rv(ERR_UNEXPECTED), |
| 10892 | extra_write(NULL), |
| 10893 | extra_read(NULL) { |
| 10894 | } |
| 10895 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10896 | int expected_rv_arg) |
| 10897 | : write(write_arg), |
| 10898 | read(read_arg), |
| 10899 | expected_rv(expected_rv_arg), |
| 10900 | extra_write(NULL), |
| 10901 | extra_read(NULL) { |
| 10902 | } |
| 10903 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10904 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10905 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10906 | : write(write_arg), |
| 10907 | read(read_arg), |
| 10908 | expected_rv(expected_rv_arg), |
| 10909 | extra_write(extra_write_arg), |
| 10910 | extra_read(extra_read_arg) { |
| 10911 | } |
| 10912 | MockWrite write; |
| 10913 | MockRead read; |
| 10914 | int expected_rv; |
| 10915 | const MockWrite* extra_write; |
| 10916 | const MockRead* extra_read; |
| 10917 | }; |
| 10918 | |
| 10919 | static const int kNoSSL = 500; |
| 10920 | |
| 10921 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10922 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10923 | AuthTiming proxy_auth_timing; |
| 10924 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10925 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10926 | AuthTiming server_auth_timing; |
| 10927 | int server_auth_rv; |
| 10928 | int num_auth_rounds; |
| 10929 | int first_ssl_round; |
| 10930 | TestRound rounds[3]; |
| 10931 | } test_configs[] = { |
| 10932 | // Non-authenticating HTTP server with a direct connection. |
| 10933 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10934 | { TestRound(kGet, kSuccess, OK)}}, |
| 10935 | // Authenticating HTTP server with a direct connection. |
| 10936 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10937 | { TestRound(kGet, kServerChallenge, OK), |
| 10938 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10939 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10940 | { TestRound(kGet, kServerChallenge, OK), |
| 10941 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10942 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10943 | { TestRound(kGet, kServerChallenge, OK), |
| 10944 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10945 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10946 | { TestRound(kGet, kServerChallenge, OK), |
| 10947 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10948 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10949 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10950 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10951 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10952 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10953 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10954 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10955 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10956 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10957 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10958 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10959 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10960 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10961 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10962 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10963 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10964 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10965 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10966 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10967 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10968 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10969 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10970 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10971 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10972 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10973 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10974 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10975 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10976 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10977 | // Authenticating HTTP server through an authenticating proxy. |
| 10978 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10979 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10980 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10981 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10982 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10983 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10984 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10985 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10986 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10987 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10988 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10989 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10990 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10991 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10992 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10993 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10994 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10995 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10996 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10997 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10998 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10999 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11000 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11001 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11002 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11003 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11004 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11005 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11006 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11007 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11008 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11009 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11010 | // Non-authenticating HTTPS server with a direct connection. |
| 11011 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11012 | { TestRound(kGet, kSuccess, OK)}}, |
| 11013 | // Authenticating HTTPS server with a direct connection. |
| 11014 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11015 | { TestRound(kGet, kServerChallenge, OK), |
| 11016 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11017 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11018 | { TestRound(kGet, kServerChallenge, OK), |
| 11019 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11020 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11021 | { TestRound(kGet, kServerChallenge, OK), |
| 11022 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11023 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11024 | { TestRound(kGet, kServerChallenge, OK), |
| 11025 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11026 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11027 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11028 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11029 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11030 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11031 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11032 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11033 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11034 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11035 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11036 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11037 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11038 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11039 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11040 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11041 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11042 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11043 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11044 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11045 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11046 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11047 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11048 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11049 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11050 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11051 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11052 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11053 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11054 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11055 | // Authenticating HTTPS server through an authenticating proxy. |
| 11056 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11057 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11058 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11059 | &kGet, &kServerChallenge), |
| 11060 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11061 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11062 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11063 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11064 | &kGet, &kServerChallenge), |
| 11065 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11066 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11067 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11068 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11069 | &kGet, &kServerChallenge), |
| 11070 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11071 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11072 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11073 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11074 | &kGet, &kServerChallenge), |
| 11075 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11076 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11077 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11078 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11079 | &kGet, &kServerChallenge), |
| 11080 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11081 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11082 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11083 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11084 | &kGet, &kServerChallenge), |
| 11085 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11086 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11087 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11088 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11089 | &kGet, &kServerChallenge), |
| 11090 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11091 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11092 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11093 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11094 | &kGet, &kServerChallenge), |
| 11095 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11096 | }; |
| 11097 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11098 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11099 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11100 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11101 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11102 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11103 | |
| 11104 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11105 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11106 | for (int n = 0; n < 2; n++) { |
| 11107 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11108 | std::string auth_challenge = "Mock realm=proxy"; |
| 11109 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11110 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11111 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11112 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11113 | origin, BoundNetLog()); |
| 11114 | auth_handler->SetGenerateExpectation( |
| 11115 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11116 | test_config.proxy_auth_rv); |
| 11117 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11118 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11119 | } |
| 11120 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11121 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11122 | std::string auth_challenge = "Mock realm=server"; |
| 11123 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11124 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11125 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11126 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11127 | origin, BoundNetLog()); |
| 11128 | auth_handler->SetGenerateExpectation( |
| 11129 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11130 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11131 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11132 | } |
| 11133 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11134 | session_deps_.proxy_service = |
| 11135 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11136 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11137 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11138 | } |
| 11139 | |
| 11140 | HttpRequestInfo request; |
| 11141 | request.method = "GET"; |
| 11142 | request.url = GURL(test_config.server_url); |
| 11143 | request.load_flags = 0; |
| 11144 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11145 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11147 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11148 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11149 | |
| 11150 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11151 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11152 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11153 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11154 | |
| 11155 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11156 | mock_reads.back().push_back(read_write_round.read); |
| 11157 | mock_writes.back().push_back(read_write_round.write); |
| 11158 | |
| 11159 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11160 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11161 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11162 | mock_reads.push_back(std::vector<MockRead>()); |
| 11163 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11164 | } |
| 11165 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11166 | if (read_write_round.extra_read) { |
| 11167 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11168 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11169 | if (read_write_round.extra_write) { |
| 11170 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11171 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11172 | |
| 11173 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11174 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11175 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11176 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11177 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11178 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11179 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 11180 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 11181 | data_providers.push_back(new StaticSocketDataProvider( |
| 11182 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 11183 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 11184 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11185 | data_providers.back()); |
| 11186 | } |
| 11187 | |
| 11188 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11189 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11190 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11191 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11192 | int rv; |
| 11193 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11194 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11195 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11196 | rv = trans.RestartWithAuth( |
| 11197 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11198 | } |
| 11199 | if (rv == ERR_IO_PENDING) |
| 11200 | rv = callback.WaitForResult(); |
| 11201 | |
| 11202 | // Compare results with expected data. |
| 11203 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11204 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11205 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11206 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11207 | continue; |
| 11208 | } |
| 11209 | if (round + 1 < test_config.num_auth_rounds) { |
| 11210 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11211 | } else { |
| 11212 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11213 | } |
| 11214 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11215 | } |
| 11216 | } |
| 11217 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11218 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11219 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11220 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11221 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11222 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11223 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11224 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11225 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11226 | |
| 11227 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11228 | auth_handler->set_connection_based(true); |
| 11229 | std::string auth_challenge = "Mock realm=server"; |
| 11230 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11231 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11232 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11233 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11234 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11235 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11236 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11237 | int rv = OK; |
| 11238 | const HttpResponseInfo* response = NULL; |
| 11239 | HttpRequestInfo request; |
| 11240 | request.method = "GET"; |
| 11241 | request.url = origin; |
| 11242 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11243 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11244 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11245 | |
| 11246 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11247 | // to validate that the TCP socket is not released to the pool between |
| 11248 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11249 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11250 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11251 | 50, // Max sockets for pool |
| 11252 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11253 | session_deps_.host_resolver.get(), |
| 11254 | session_deps_.socket_factory.get(), |
| 11255 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11256 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11257 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11258 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 11259 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11260 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11261 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11262 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11263 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11264 | |
| 11265 | const MockWrite kGet( |
| 11266 | "GET / HTTP/1.1\r\n" |
| 11267 | "Host: www.example.com\r\n" |
| 11268 | "Connection: keep-alive\r\n\r\n"); |
| 11269 | const MockWrite kGetAuth( |
| 11270 | "GET / HTTP/1.1\r\n" |
| 11271 | "Host: www.example.com\r\n" |
| 11272 | "Connection: keep-alive\r\n" |
| 11273 | "Authorization: auth_token\r\n\r\n"); |
| 11274 | |
| 11275 | const MockRead kServerChallenge( |
| 11276 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11277 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11278 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11279 | "Content-Length: 14\r\n\r\n" |
| 11280 | "Unauthorized\r\n"); |
| 11281 | const MockRead kSuccess( |
| 11282 | "HTTP/1.1 200 OK\r\n" |
| 11283 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11284 | "Content-Length: 3\r\n\r\n" |
| 11285 | "Yes"); |
| 11286 | |
| 11287 | MockWrite writes[] = { |
| 11288 | // First round |
| 11289 | kGet, |
| 11290 | // Second round |
| 11291 | kGetAuth, |
| 11292 | // Third round |
| 11293 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11294 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11295 | kGetAuth, |
| 11296 | // Competing request |
| 11297 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11298 | }; |
| 11299 | MockRead reads[] = { |
| 11300 | // First round |
| 11301 | kServerChallenge, |
| 11302 | // Second round |
| 11303 | kServerChallenge, |
| 11304 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11305 | kServerChallenge, |
| 11306 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11307 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11308 | // Competing response |
| 11309 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11310 | }; |
| 11311 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11312 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11313 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11314 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11315 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11316 | |
| 11317 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11318 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11319 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11320 | if (rv == ERR_IO_PENDING) |
| 11321 | rv = callback.WaitForResult(); |
| 11322 | EXPECT_EQ(OK, rv); |
| 11323 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11324 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11325 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11326 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11327 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11328 | // In between rounds, another request comes in for the same domain. |
| 11329 | // It should not be able to grab the TCP socket that trans has already |
| 11330 | // claimed. |
| 11331 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11333 | TestCompletionCallback callback_compete; |
| 11334 | rv = trans_compete->Start( |
| 11335 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11337 | // callback_compete.WaitForResult at this point would stall forever, |
| 11338 | // since the HttpNetworkTransaction does not release the request back to |
| 11339 | // the pool until after authentication completes. |
| 11340 | |
| 11341 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11342 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11343 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11344 | if (rv == ERR_IO_PENDING) |
| 11345 | rv = callback.WaitForResult(); |
| 11346 | EXPECT_EQ(OK, rv); |
| 11347 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11348 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11349 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11350 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11351 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11352 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11353 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11354 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11355 | if (rv == ERR_IO_PENDING) |
| 11356 | rv = callback.WaitForResult(); |
| 11357 | EXPECT_EQ(OK, rv); |
| 11358 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11359 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11360 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11361 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11362 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11363 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11364 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11365 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11366 | if (rv == ERR_IO_PENDING) |
| 11367 | rv = callback.WaitForResult(); |
| 11368 | EXPECT_EQ(OK, rv); |
| 11369 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11370 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11371 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11372 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11373 | |
| 11374 | // Read the body since the fourth round was successful. This will also |
| 11375 | // release the socket back to the pool. |
| 11376 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11377 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11378 | if (rv == ERR_IO_PENDING) |
| 11379 | rv = callback.WaitForResult(); |
| 11380 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11381 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11382 | EXPECT_EQ(0, rv); |
| 11383 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11384 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11385 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11386 | |
| 11387 | // The competing request can now finish. Wait for the headers and then |
| 11388 | // read the body. |
| 11389 | rv = callback_compete.WaitForResult(); |
| 11390 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11391 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11392 | if (rv == ERR_IO_PENDING) |
| 11393 | rv = callback.WaitForResult(); |
| 11394 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11395 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11396 | EXPECT_EQ(0, rv); |
| 11397 | |
| 11398 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11399 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11400 | } |
| 11401 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11402 | // This tests the case that a request is issued via http instead of spdy after |
| 11403 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11404 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11405 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11406 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11407 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11408 | session_deps_.next_protos = next_protos; |
| 11409 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11410 | HttpRequestInfo request; |
| 11411 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11413 | request.load_flags = 0; |
| 11414 | |
| 11415 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11416 | MockWrite( |
| 11417 | "GET / HTTP/1.1\r\n" |
| 11418 | "Host: www.example.org\r\n" |
| 11419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11420 | }; |
| 11421 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11422 | std::string alternate_protocol_http_header = |
| 11423 | GetAlternateProtocolHttpHeader(); |
| 11424 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11425 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11427 | MockRead(alternate_protocol_http_header.c_str()), |
| 11428 | MockRead("\r\n"), |
| 11429 | MockRead("hello world"), |
| 11430 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11431 | }; |
| 11432 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11433 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11434 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11435 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11437 | |
| 11438 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11439 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11442 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11443 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11444 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11445 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11446 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11448 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11449 | |
| 11450 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11451 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11452 | |
| 11453 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11454 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11455 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11457 | |
| 11458 | std::string response_data; |
| 11459 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11460 | EXPECT_EQ("hello world", response_data); |
| 11461 | |
| 11462 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11463 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11464 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11465 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11466 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11467 | // immediate server closing of the socket. |
| 11468 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11469 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11470 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11471 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11472 | |
| 11473 | HttpRequestInfo request; |
| 11474 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11475 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11476 | request.load_flags = 0; |
| 11477 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11478 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11479 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11481 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11482 | scoped_ptr<SpdyFrame> req( |
| 11483 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11484 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11485 | |
| 11486 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11487 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11488 | }; |
| 11489 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11490 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11491 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11492 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11494 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11495 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11496 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11497 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11498 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11500 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11501 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11502 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11503 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11504 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11505 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11506 | // it gets it. This is needed since the auth handler may get destroyed |
| 11507 | // before we get a chance to query it. |
| 11508 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11509 | public: |
| 11510 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11511 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11512 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11513 | |
| 11514 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11515 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11516 | const HttpRequestInfo* request, |
| 11517 | const CompletionCallback& callback, |
| 11518 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11519 | *url_ = request->url; |
| 11520 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11521 | credentials, request, callback, auth_token); |
| 11522 | } |
| 11523 | |
| 11524 | private: |
| 11525 | GURL* url_; |
| 11526 | }; |
| 11527 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11528 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11529 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11530 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11531 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11532 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11533 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11534 | session_deps_.proxy_service = |
| 11535 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11536 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11537 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11538 | GURL request_url; |
| 11539 | { |
| 11540 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11541 | new HttpAuthHandlerMock::Factory(); |
| 11542 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11543 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11544 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11545 | auth_factory->set_do_init_from_challenge(true); |
| 11546 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11547 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11548 | |
| 11549 | HttpRequestInfo request; |
| 11550 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11551 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11552 | request.load_flags = 0; |
| 11553 | |
| 11554 | // First round goes unauthenticated through the proxy. |
| 11555 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11556 | MockWrite( |
| 11557 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11558 | "Host: www.example.org\r\n" |
| 11559 | "Proxy-Connection: keep-alive\r\n" |
| 11560 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11561 | }; |
| 11562 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11563 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11564 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11565 | MockRead("Alternate-Protocol: 443:"), |
| 11566 | MockRead(GetAlternateProtocolFromParam()), |
| 11567 | MockRead("\r\n"), |
| 11568 | MockRead("Proxy-Connection: close\r\n"), |
| 11569 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11570 | }; |
| 11571 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11572 | data_writes_1, arraysize(data_writes_1)); |
| 11573 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11574 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11575 | // Alternate-Protocol announcement in the first round. It fails due |
| 11576 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11577 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11578 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11579 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11580 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11581 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11582 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11583 | // to obtain a new one. |
| 11584 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11585 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11586 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11587 | // establishment and SPDY framing issues. Alas, the |
| 11588 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11589 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11590 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11591 | scoped_ptr<SpdyFrame> req( |
| 11592 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11593 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11594 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11595 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11596 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11597 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11598 | MockWrite(ASYNC, 0, |
| 11599 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11600 | "Host: www.example.org\r\n" |
| 11601 | "Proxy-Connection: keep-alive\r\n" |
| 11602 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11603 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11604 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11605 | MockWrite(ASYNC, 2, |
| 11606 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11607 | "Host: www.example.org\r\n" |
| 11608 | "Proxy-Connection: keep-alive\r\n" |
| 11609 | "Proxy-Authorization: auth_token\r\n" |
| 11610 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11611 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11612 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11613 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11614 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11615 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11616 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11617 | MockRead(ASYNC, 1, |
| 11618 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11619 | "Proxy-Authenticate: Mock\r\n" |
| 11620 | "Content-Length: 0\r\n" |
| 11621 | "Proxy-Connection: keep-alive\r\n" |
| 11622 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11623 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11624 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11625 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11626 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11627 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11628 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11629 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11630 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11631 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11632 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11633 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11634 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11635 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11636 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11637 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11638 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11639 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11640 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11641 | NULL, 0, NULL, 0); |
| 11642 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11643 | never_finishing_connect); |
| 11644 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11645 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11646 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11647 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11648 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11649 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11650 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11651 | |
| 11652 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11653 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11654 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11655 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11656 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11657 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11658 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11659 | |
| 11660 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11661 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11662 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11663 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11664 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11666 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11667 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11668 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11669 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11670 | |
| 11671 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11672 | TestCompletionCallback callback_3; |
| 11673 | rv = trans_2->RestartWithAuth( |
| 11674 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11675 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11676 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11677 | |
| 11678 | // After all that work, these two lines (or actually, just the scheme) are |
| 11679 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11680 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11681 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11682 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11683 | LoadTimingInfo load_timing_info; |
| 11684 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11685 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11686 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11687 | } |
| 11688 | |
| 11689 | // Test that if we cancel the transaction as the connection is completing, that |
| 11690 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11691 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11692 | // Setup everything about the connection to complete synchronously, so that |
| 11693 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11694 | // for is the callback from the HttpStreamRequest. |
| 11695 | // Then cancel the transaction. |
| 11696 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11697 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11698 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11699 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11700 | MockRead(SYNCHRONOUS, "hello world"), |
| 11701 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11702 | }; |
| 11703 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11704 | HttpRequestInfo request; |
| 11705 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11706 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11707 | request.load_flags = 0; |
| 11708 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11709 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11711 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11712 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11713 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11714 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11715 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11716 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11718 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11719 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11720 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11721 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11723 | trans.reset(); // Cancel the transaction here. |
| 11724 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11725 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11726 | } |
| 11727 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11728 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11729 | // stream is drained properly and added back to the socket pool. The main |
| 11730 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11731 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11732 | // deleted. |
| 11733 | // See http://crbug.com/368418 |
| 11734 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11735 | MockRead data_reads[] = { |
| 11736 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11737 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11738 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11739 | MockRead(ASYNC, "1"), |
| 11740 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11741 | // HttpNetworkTransaction has been deleted. |
| 11742 | MockRead(ASYNC, "2"), |
| 11743 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11744 | }; |
| 11745 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11747 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11748 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11749 | |
| 11750 | { |
| 11751 | HttpRequestInfo request; |
| 11752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11753 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11754 | request.load_flags = 0; |
| 11755 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11757 | TestCompletionCallback callback; |
| 11758 | |
| 11759 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11761 | callback.WaitForResult(); |
| 11762 | |
| 11763 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11764 | ASSERT_TRUE(response != NULL); |
| 11765 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11766 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11767 | |
| 11768 | // The transaction and HttpRequestInfo are deleted. |
| 11769 | } |
| 11770 | |
| 11771 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11772 | base::MessageLoop::current()->RunUntilIdle(); |
| 11773 | |
| 11774 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11775 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11776 | } |
| 11777 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11778 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11779 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11780 | session_deps_.proxy_service = |
| 11781 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11782 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11783 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11784 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11785 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11786 | HttpRequestInfo request; |
| 11787 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11788 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11789 | |
| 11790 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11791 | MockWrite( |
| 11792 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11793 | "Host: www.example.org\r\n" |
| 11794 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11795 | }; |
| 11796 | |
| 11797 | MockRead data_reads1[] = { |
| 11798 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11799 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11802 | }; |
| 11803 | |
| 11804 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11805 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11808 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11809 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11810 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11812 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11813 | trans->SetBeforeProxyHeadersSentCallback( |
| 11814 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11815 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11817 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11819 | |
| 11820 | rv = callback1.WaitForResult(); |
| 11821 | EXPECT_EQ(OK, rv); |
| 11822 | |
| 11823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11824 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11825 | |
| 11826 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11827 | EXPECT_EQ(200, response->headers->response_code()); |
| 11828 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11829 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11830 | EXPECT_TRUE( |
| 11831 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11832 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11833 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11834 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11835 | |
| 11836 | LoadTimingInfo load_timing_info; |
| 11837 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11838 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11839 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11840 | } |
| 11841 | |
| 11842 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11843 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11844 | session_deps_.proxy_service = |
| 11845 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11846 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11847 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11848 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11849 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11850 | HttpRequestInfo request; |
| 11851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11852 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11853 | |
| 11854 | // Since we have proxy, should try to establish tunnel. |
| 11855 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11856 | MockWrite( |
| 11857 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11858 | "Host: www.example.org\r\n" |
| 11859 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11860 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11861 | MockWrite( |
| 11862 | "GET / HTTP/1.1\r\n" |
| 11863 | "Host: www.example.org\r\n" |
| 11864 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11865 | }; |
| 11866 | |
| 11867 | MockRead data_reads1[] = { |
| 11868 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11869 | |
| 11870 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11871 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11872 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11873 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11874 | }; |
| 11875 | |
| 11876 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11877 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11879 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11880 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11882 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11883 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11884 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11887 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11889 | |
| 11890 | rv = callback1.WaitForResult(); |
| 11891 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11892 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11893 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11894 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11895 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11896 | NetLog::PHASE_NONE); |
| 11897 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11898 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11899 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11900 | NetLog::PHASE_NONE); |
| 11901 | |
| 11902 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11903 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11904 | |
| 11905 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11906 | EXPECT_EQ(200, response->headers->response_code()); |
| 11907 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11908 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11909 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11910 | EXPECT_TRUE( |
| 11911 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11912 | |
| 11913 | LoadTimingInfo load_timing_info; |
| 11914 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11915 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11916 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11917 | } |
| 11918 | |
| 11919 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11920 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11921 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11922 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11923 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11924 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11925 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11926 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11927 | HttpRequestInfo request; |
| 11928 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11929 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11930 | |
| 11931 | // Since we have proxy, should try to establish tunnel. |
| 11932 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11933 | MockWrite( |
| 11934 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11935 | "Host: www.example.org\r\n" |
| 11936 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11937 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11938 | MockWrite( |
| 11939 | "GET / HTTP/1.1\r\n" |
| 11940 | "Host: www.example.org\r\n" |
| 11941 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11942 | }; |
| 11943 | |
| 11944 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11945 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11946 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11947 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11948 | }; |
| 11949 | |
| 11950 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11951 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11953 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11956 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11957 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11958 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11959 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11961 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11962 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11963 | |
| 11964 | rv = callback1.WaitForResult(); |
| 11965 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11966 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11967 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11968 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11969 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11970 | NetLog::PHASE_NONE); |
| 11971 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11972 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11973 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11974 | NetLog::PHASE_NONE); |
| 11975 | } |
| 11976 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11977 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11978 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11979 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11980 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11981 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11982 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11983 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11984 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11985 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11986 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11987 | }; |
| 11988 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11989 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11990 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11991 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11992 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11993 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11994 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11996 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11997 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11998 | |
| 11999 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12000 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12001 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12002 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12003 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12004 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12005 | |
| 12006 | HttpRequestInfo request; |
| 12007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12008 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12009 | request.load_flags = 0; |
| 12010 | |
| 12011 | // This is the important line that marks this as a preconnect. |
| 12012 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12013 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12014 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12016 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12017 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12018 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12019 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12020 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12021 | } |
| 12022 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12023 | // Given a net error, cause that error to be returned from the first Write() |
| 12024 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12025 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12026 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12027 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12028 | request_info.url = GURL("https://www.example.com/"); |
| 12029 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12030 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12031 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12032 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12033 | MockWrite data_writes[] = { |
| 12034 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12035 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12036 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12039 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12040 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12041 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12044 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12045 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12046 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12047 | rv = callback.WaitForResult(); |
| 12048 | ASSERT_EQ(error, rv); |
| 12049 | } |
| 12050 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12051 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12052 | // Just check a grab bag of cert errors. |
| 12053 | static const int kErrors[] = { |
| 12054 | ERR_CERT_COMMON_NAME_INVALID, |
| 12055 | ERR_CERT_AUTHORITY_INVALID, |
| 12056 | ERR_CERT_DATE_INVALID, |
| 12057 | }; |
| 12058 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12059 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12060 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12061 | } |
| 12062 | } |
| 12063 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12064 | // Ensure that a client certificate is removed from the SSL client auth |
| 12065 | // cache when: |
| 12066 | // 1) No proxy is involved. |
| 12067 | // 2) TLS False Start is disabled. |
| 12068 | // 3) The initial TLS handshake requests a client certificate. |
| 12069 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12070 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12071 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12072 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12073 | request_info.url = GURL("https://www.example.com/"); |
| 12074 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12075 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12076 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12077 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12078 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12079 | |
| 12080 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12081 | // CertificateRequest is received for the first time, the handshake will |
| 12082 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12083 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12084 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12086 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12087 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12088 | |
| 12089 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12090 | // False Start is not being used, the result of the SSL handshake will be |
| 12091 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12092 | // matches the result of a server sending a handshake_failure alert, |
| 12093 | // rather than a Finished message, because it requires a client |
| 12094 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12095 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12096 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12098 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12099 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12100 | |
| 12101 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12102 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12103 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12104 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12105 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12106 | // requiring a client certificate, this fallback handshake should also |
| 12107 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12108 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12109 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12111 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12112 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12113 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12114 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12115 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12116 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12117 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12118 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12119 | // requiring a client certificate, this fallback handshake should also |
| 12120 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12121 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12122 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12123 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12124 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12125 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12126 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12127 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12128 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12129 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12130 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12131 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12132 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12133 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12134 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12135 | |
| 12136 | // Complete the SSL handshake, which should abort due to requiring a |
| 12137 | // client certificate. |
| 12138 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12139 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12140 | |
| 12141 | // Indicate that no certificate should be supplied. From the perspective |
| 12142 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12143 | // certificate, so this is the same as supply a |
| 12144 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12145 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12146 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12147 | |
| 12148 | // Ensure the certificate was added to the client auth cache before |
| 12149 | // allowing the connection to continue restarting. |
| 12150 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12151 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12152 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12153 | ASSERT_EQ(NULL, client_cert.get()); |
| 12154 | |
| 12155 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12156 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12157 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12158 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12159 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12160 | |
| 12161 | // Ensure that the client certificate is removed from the cache on a |
| 12162 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12163 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12164 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12165 | } |
| 12166 | |
| 12167 | // Ensure that a client certificate is removed from the SSL client auth |
| 12168 | // cache when: |
| 12169 | // 1) No proxy is involved. |
| 12170 | // 2) TLS False Start is enabled. |
| 12171 | // 3) The initial TLS handshake requests a client certificate. |
| 12172 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12173 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12174 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12175 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12176 | request_info.url = GURL("https://www.example.com/"); |
| 12177 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12178 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12179 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12180 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12181 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12182 | |
| 12183 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12184 | // return successfully after reading up to the peer's Certificate message. |
| 12185 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12186 | // enqueue application data to be sent in the same packet as the |
| 12187 | // ChangeCipherSpec and Finished messages. |
| 12188 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12189 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12190 | // Finished messages. If there was an error negotiating with the peer, |
| 12191 | // such as due to the peer requiring a client certificate when none was |
| 12192 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12193 | // called. |
| 12194 | |
| 12195 | // Like the non-False Start case, when a client certificate is requested by |
| 12196 | // the peer, the handshake is aborted during the Connect() call. |
| 12197 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12198 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12199 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12200 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12201 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12202 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12203 | |
| 12204 | // When a client certificate is supplied, Connect() will not be aborted |
| 12205 | // when the peer requests the certificate. Instead, the handshake will |
| 12206 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12207 | // the socket. The handshake messages are not processed until Read() is |
| 12208 | // called, which then detects that the handshake was aborted, due to the |
| 12209 | // peer sending a handshake_failure because it requires a client |
| 12210 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12211 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12212 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12214 | MockRead data2_reads[] = { |
| 12215 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12216 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12217 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12218 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12219 | |
| 12220 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12221 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12222 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12223 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12224 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12226 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12227 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12228 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12229 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12230 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12231 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12232 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12234 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12235 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12236 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12237 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12238 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12239 | ssl_data5.cert_request_info = cert_request.get(); |
| 12240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12241 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12242 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12243 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12244 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12245 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12247 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12248 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12249 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12250 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12251 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12252 | |
| 12253 | // Complete the SSL handshake, which should abort due to requiring a |
| 12254 | // client certificate. |
| 12255 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12256 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12257 | |
| 12258 | // Indicate that no certificate should be supplied. From the perspective |
| 12259 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12260 | // certificate, so this is the same as supply a |
| 12261 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12262 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12263 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12264 | |
| 12265 | // Ensure the certificate was added to the client auth cache before |
| 12266 | // allowing the connection to continue restarting. |
| 12267 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12268 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12269 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12270 | ASSERT_EQ(NULL, client_cert.get()); |
| 12271 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12272 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12273 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12274 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12275 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12276 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12277 | |
| 12278 | // Ensure that the client certificate is removed from the cache on a |
| 12279 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12280 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12281 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12282 | } |
| 12283 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12284 | // Ensure that a client certificate is removed from the SSL client auth |
| 12285 | // cache when: |
| 12286 | // 1) An HTTPS proxy is involved. |
| 12287 | // 3) The HTTPS proxy requests a client certificate. |
| 12288 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12289 | // proxy. |
| 12290 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12291 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12292 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12293 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12294 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12295 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12296 | |
| 12297 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12298 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12299 | |
| 12300 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12301 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12302 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12303 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12304 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12305 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12307 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12308 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12309 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12310 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12311 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12313 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12315 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12316 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12317 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12318 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12319 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12321 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12322 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12323 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12324 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12325 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12326 | requests[0].url = GURL("https://www.example.com/"); |
| 12327 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12328 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12329 | |
| 12330 | requests[1].url = GURL("http://www.example.com/"); |
| 12331 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12332 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12333 | |
| 12334 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12335 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12336 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12337 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12339 | |
| 12340 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12341 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12342 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12343 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12344 | |
| 12345 | // Complete the SSL handshake, which should abort due to requiring a |
| 12346 | // client certificate. |
| 12347 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12348 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12349 | |
| 12350 | // Indicate that no certificate should be supplied. From the perspective |
| 12351 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12352 | // certificate, so this is the same as supply a |
| 12353 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12354 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12355 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12356 | |
| 12357 | // Ensure the certificate was added to the client auth cache before |
| 12358 | // allowing the connection to continue restarting. |
| 12359 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12360 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12361 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12362 | ASSERT_EQ(NULL, client_cert.get()); |
| 12363 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12364 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12365 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12366 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12367 | |
| 12368 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12369 | // then consume ssl_data3, which should also fail. The result code is |
| 12370 | // checked against what ssl_data3 should return. |
| 12371 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12372 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12373 | |
| 12374 | // Now that the new handshake has failed, ensure that the client |
| 12375 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12376 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12377 | HostPortPair("proxy", 70), &client_cert)); |
| 12378 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12379 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12380 | } |
| 12381 | } |
| 12382 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12383 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12384 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12385 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12386 | |
| 12387 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12388 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12389 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12390 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12391 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12392 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12393 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12394 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12396 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12397 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12398 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12399 | scoped_ptr<SpdyFrame> host2_req( |
| 12400 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12401 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12402 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12403 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12404 | scoped_ptr<SpdyFrame> host1_resp( |
| 12405 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12406 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12407 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12408 | scoped_ptr<SpdyFrame> host2_resp( |
| 12409 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12410 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12411 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12412 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12413 | CreateMockRead(*host1_resp, 1), |
| 12414 | CreateMockRead(*host1_resp_body, 2), |
| 12415 | CreateMockRead(*host2_resp, 4), |
| 12416 | CreateMockRead(*host2_resp_body, 5), |
| 12417 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12418 | }; |
| 12419 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12420 | IPAddressNumber ip; |
| 12421 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12422 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12423 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12424 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12425 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12426 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12427 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12428 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12429 | HttpRequestInfo request1; |
| 12430 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12431 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12432 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12433 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12435 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12436 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12437 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12438 | |
| 12439 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12440 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12441 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12442 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12443 | |
| 12444 | std::string response_data; |
| 12445 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12446 | EXPECT_EQ("hello!", response_data); |
| 12447 | |
| 12448 | // Preload www.gmail.com into HostCache. |
| 12449 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12450 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12451 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12452 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12453 | DEFAULT_PRIORITY, |
| 12454 | &ignored, |
| 12455 | callback.callback(), |
| 12456 | NULL, |
| 12457 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12458 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12459 | rv = callback.WaitForResult(); |
| 12460 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12461 | |
| 12462 | HttpRequestInfo request2; |
| 12463 | request2.method = "GET"; |
| 12464 | request2.url = GURL("https://www.gmail.com/"); |
| 12465 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12466 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12468 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12469 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12470 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12471 | |
| 12472 | response = trans2.GetResponseInfo(); |
| 12473 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12474 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12475 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12476 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12477 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12478 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12479 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12480 | } |
| 12481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12482 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12483 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12484 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12485 | |
| 12486 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12487 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12488 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12489 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12490 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12491 | |
| 12492 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12493 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12495 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12496 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12497 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12498 | scoped_ptr<SpdyFrame> host2_req( |
| 12499 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12500 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12501 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12502 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12503 | scoped_ptr<SpdyFrame> host1_resp( |
| 12504 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12505 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12506 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12507 | scoped_ptr<SpdyFrame> host2_resp( |
| 12508 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12509 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12510 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12511 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12512 | CreateMockRead(*host1_resp, 1), |
| 12513 | CreateMockRead(*host1_resp_body, 2), |
| 12514 | CreateMockRead(*host2_resp, 4), |
| 12515 | CreateMockRead(*host2_resp_body, 5), |
| 12516 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12517 | }; |
| 12518 | |
| 12519 | IPAddressNumber ip; |
| 12520 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12521 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12522 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12523 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12524 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12525 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12526 | |
| 12527 | TestCompletionCallback callback; |
| 12528 | HttpRequestInfo request1; |
| 12529 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12530 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12531 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12532 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12533 | |
| 12534 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12535 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12536 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12537 | |
| 12538 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12539 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12540 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12541 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12542 | |
| 12543 | std::string response_data; |
| 12544 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12545 | EXPECT_EQ("hello!", response_data); |
| 12546 | |
| 12547 | HttpRequestInfo request2; |
| 12548 | request2.method = "GET"; |
| 12549 | request2.url = GURL("https://www.gmail.com/"); |
| 12550 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12551 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12552 | |
| 12553 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12555 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12556 | |
| 12557 | response = trans2.GetResponseInfo(); |
| 12558 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12559 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12560 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12561 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12562 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12563 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12564 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12565 | } |
| 12566 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12567 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12568 | public: |
| 12569 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12570 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12571 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12572 | |
| 12573 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12574 | |
| 12575 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12576 | int Resolve(const RequestInfo& info, |
| 12577 | RequestPriority priority, |
| 12578 | AddressList* addresses, |
| 12579 | const CompletionCallback& callback, |
| 12580 | RequestHandle* out_req, |
| 12581 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12582 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12583 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12584 | } |
| 12585 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12586 | int ResolveFromCache(const RequestInfo& info, |
| 12587 | AddressList* addresses, |
| 12588 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12589 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12590 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12591 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12592 | return rv; |
| 12593 | } |
| 12594 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12595 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12596 | host_resolver_.CancelRequest(req); |
| 12597 | } |
| 12598 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12599 | MockCachingHostResolver* GetMockHostResolver() { |
| 12600 | return &host_resolver_; |
| 12601 | } |
| 12602 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12603 | private: |
| 12604 | MockCachingHostResolver host_resolver_; |
| 12605 | const HostPortPair host_port_; |
| 12606 | }; |
| 12607 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12608 | TEST_P(HttpNetworkTransactionTest, |
| 12609 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12610 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12611 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12612 | |
| 12613 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12614 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12615 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12616 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12617 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12618 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12619 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12620 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12621 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12622 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12623 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12624 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12625 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12626 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12627 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12628 | scoped_ptr<SpdyFrame> host2_req( |
| 12629 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12630 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12631 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12632 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12633 | scoped_ptr<SpdyFrame> host1_resp( |
| 12634 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12635 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12636 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12637 | scoped_ptr<SpdyFrame> host2_resp( |
| 12638 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12639 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12640 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12641 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12642 | CreateMockRead(*host1_resp, 1), |
| 12643 | CreateMockRead(*host1_resp_body, 2), |
| 12644 | CreateMockRead(*host2_resp, 4), |
| 12645 | CreateMockRead(*host2_resp_body, 5), |
| 12646 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12647 | }; |
| 12648 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12649 | IPAddressNumber ip; |
| 12650 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12651 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12652 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12653 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12654 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12655 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12656 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12657 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12658 | HttpRequestInfo request1; |
| 12659 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12660 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12661 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12662 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12663 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12664 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12666 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12667 | |
| 12668 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12669 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12670 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12671 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12672 | |
| 12673 | std::string response_data; |
| 12674 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12675 | EXPECT_EQ("hello!", response_data); |
| 12676 | |
| 12677 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12678 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12679 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12680 | rv = host_resolver.Resolve(resolve_info, |
| 12681 | DEFAULT_PRIORITY, |
| 12682 | &ignored, |
| 12683 | callback.callback(), |
| 12684 | NULL, |
| 12685 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12687 | rv = callback.WaitForResult(); |
| 12688 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12689 | |
| 12690 | HttpRequestInfo request2; |
| 12691 | request2.method = "GET"; |
| 12692 | request2.url = GURL("https://www.gmail.com/"); |
| 12693 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12694 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12696 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12697 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12698 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12699 | |
| 12700 | response = trans2.GetResponseInfo(); |
| 12701 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12702 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12703 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12704 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12705 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12706 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12707 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12708 | } |
| 12709 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12710 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12711 | const std::string https_url = "https://www.example.org:8080/"; |
| 12712 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12713 | |
| 12714 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12715 | scoped_ptr<SpdyFrame> req1( |
| 12716 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12717 | |
| 12718 | MockWrite writes1[] = { |
| 12719 | CreateMockWrite(*req1, 0), |
| 12720 | }; |
| 12721 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12722 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12723 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12724 | MockRead reads1[] = { |
| 12725 | CreateMockRead(*resp1, 1), |
| 12726 | CreateMockRead(*body1, 2), |
| 12727 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12728 | }; |
| 12729 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12730 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12731 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12732 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12733 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12734 | |
| 12735 | // HTTP GET for the HTTP URL |
| 12736 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12737 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12738 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12739 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12740 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12741 | }; |
| 12742 | |
| 12743 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12744 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12745 | MockRead(ASYNC, 2, "hello"), |
| 12746 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12747 | }; |
| 12748 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12749 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12750 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12751 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12752 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12753 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12755 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12756 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12757 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12758 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12759 | |
| 12760 | // Start the first transaction to set up the SpdySession |
| 12761 | HttpRequestInfo request1; |
| 12762 | request1.method = "GET"; |
| 12763 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12764 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12765 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12766 | TestCompletionCallback callback1; |
| 12767 | EXPECT_EQ(ERR_IO_PENDING, |
| 12768 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12769 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12770 | |
| 12771 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12772 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12773 | |
| 12774 | // Now, start the HTTP request |
| 12775 | HttpRequestInfo request2; |
| 12776 | request2.method = "GET"; |
| 12777 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12778 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12779 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12780 | TestCompletionCallback callback2; |
| 12781 | EXPECT_EQ(ERR_IO_PENDING, |
| 12782 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12783 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12784 | |
| 12785 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12786 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12787 | } |
| 12788 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12789 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12790 | public: |
| 12791 | void Run(bool pooling, bool valid) { |
| 12792 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12793 | 443); |
| 12794 | HostPortPair alternative("www.example.org", 443); |
| 12795 | |
| 12796 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12797 | scoped_refptr<X509Certificate> cert( |
| 12798 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12799 | ASSERT_TRUE(cert.get()); |
| 12800 | bool common_name_fallback_used; |
| 12801 | EXPECT_EQ(valid, |
| 12802 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12803 | EXPECT_TRUE( |
| 12804 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12805 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12806 | ssl.SetNextProto(GetParam()); |
| 12807 | ssl.cert = cert; |
| 12808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12809 | |
| 12810 | // If pooling, then start a request to alternative first to create a |
| 12811 | // SpdySession. |
| 12812 | std::string url0 = "https://www.example.org:443"; |
| 12813 | // Second request to origin, which has an alternative service, and could |
| 12814 | // open a connection to the alternative host or pool to the existing one. |
| 12815 | std::string url1("https://"); |
| 12816 | url1.append(origin.host()); |
| 12817 | url1.append(":443"); |
| 12818 | |
| 12819 | scoped_ptr<SpdyFrame> req0; |
| 12820 | scoped_ptr<SpdyFrame> req1; |
| 12821 | scoped_ptr<SpdyFrame> resp0; |
| 12822 | scoped_ptr<SpdyFrame> body0; |
| 12823 | scoped_ptr<SpdyFrame> resp1; |
| 12824 | scoped_ptr<SpdyFrame> body1; |
| 12825 | std::vector<MockWrite> writes; |
| 12826 | std::vector<MockRead> reads; |
| 12827 | |
| 12828 | if (pooling) { |
| 12829 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12830 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12831 | |
| 12832 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12833 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12834 | |
| 12835 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12836 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12837 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12838 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12839 | |
| 12840 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12841 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12842 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12843 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12844 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12845 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12846 | } else { |
| 12847 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12848 | |
| 12849 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12850 | |
| 12851 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12852 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12853 | |
| 12854 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12855 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12856 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12857 | } |
| 12858 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12859 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12860 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12862 | |
| 12863 | // Connection to the origin fails. |
| 12864 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12865 | StaticSocketDataProvider data_refused; |
| 12866 | data_refused.set_connect_data(mock_connect); |
| 12867 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12868 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12869 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12870 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12871 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12872 | session->http_server_properties(); |
| 12873 | AlternativeService alternative_service( |
| 12874 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12875 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12876 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12877 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12878 | |
| 12879 | // First request to alternative. |
| 12880 | if (pooling) { |
| 12881 | scoped_ptr<HttpTransaction> trans0( |
| 12882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12883 | HttpRequestInfo request0; |
| 12884 | request0.method = "GET"; |
| 12885 | request0.url = GURL(url0); |
| 12886 | request0.load_flags = 0; |
| 12887 | TestCompletionCallback callback0; |
| 12888 | |
| 12889 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12890 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12891 | rv = callback0.WaitForResult(); |
| 12892 | EXPECT_EQ(OK, rv); |
| 12893 | } |
| 12894 | |
| 12895 | // Second request to origin. |
| 12896 | scoped_ptr<HttpTransaction> trans1( |
| 12897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12898 | HttpRequestInfo request1; |
| 12899 | request1.method = "GET"; |
| 12900 | request1.url = GURL(url1); |
| 12901 | request1.load_flags = 0; |
| 12902 | TestCompletionCallback callback1; |
| 12903 | |
| 12904 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12906 | base::MessageLoop::current()->RunUntilIdle(); |
| 12907 | if (data.IsReadPaused()) { |
| 12908 | data.CompleteRead(); |
| 12909 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12910 | rv = callback1.WaitForResult(); |
| 12911 | if (valid) { |
| 12912 | EXPECT_EQ(OK, rv); |
| 12913 | } else { |
| 12914 | if (pooling) { |
| 12915 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12916 | } else { |
| 12917 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12918 | } |
| 12919 | } |
| 12920 | } |
| 12921 | }; |
| 12922 | |
| 12923 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12924 | AltSvcCertificateVerificationTest, |
| 12925 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12926 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12927 | |
| 12928 | // The alternative service host must exhibit a certificate that is valid for the |
| 12929 | // origin host. Test that this is enforced when pooling to an existing |
| 12930 | // connection. |
| 12931 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12932 | Run(true, true); |
| 12933 | } |
| 12934 | |
| 12935 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12936 | Run(true, false); |
| 12937 | } |
| 12938 | |
| 12939 | // The alternative service host must exhibit a certificate that is valid for the |
| 12940 | // origin host. Test that this is enforced when opening a new connection. |
| 12941 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12942 | Run(false, true); |
| 12943 | } |
| 12944 | |
| 12945 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12946 | Run(false, false); |
| 12947 | } |
| 12948 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12949 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12950 | // with the alternative server. That connection should not be used. |
| 12951 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12952 | HostPortPair origin("origin.example.org", 443); |
| 12953 | HostPortPair alternative("alternative.example.org", 443); |
| 12954 | |
| 12955 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12956 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12957 | ssl.SetNextProto(kProtoHTTP11); |
| 12958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12959 | |
| 12960 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12961 | // negotiated. |
| 12962 | StaticSocketDataProvider data; |
| 12963 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12964 | |
| 12965 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12966 | // negotiated. In order to test this, a failed connection to the origin is |
| 12967 | // mocked. This way the request relies on the alternate Job. |
| 12968 | StaticSocketDataProvider data_refused; |
| 12969 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12970 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12971 | |
| 12972 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12973 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12974 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12975 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12976 | session->http_server_properties(); |
| 12977 | AlternativeService alternative_service( |
| 12978 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12979 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12980 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12981 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12982 | |
| 12983 | scoped_ptr<HttpTransaction> trans( |
| 12984 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12985 | HttpRequestInfo request; |
| 12986 | request.method = "GET"; |
| 12987 | request.url = GURL("https://origin.example.org:443"); |
| 12988 | request.load_flags = 0; |
| 12989 | TestCompletionCallback callback; |
| 12990 | |
| 12991 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12992 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12993 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12994 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12995 | } |
| 12996 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12997 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12998 | // origin, and an alternate one to the alternative server. If the former |
| 12999 | // succeeds, the request should succeed, even if the latter fails because |
| 13000 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13001 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13002 | HostPortPair origin("origin.example.org", 443); |
| 13003 | HostPortPair alternative("alternative.example.org", 443); |
| 13004 | |
| 13005 | // Negotiate HTTP/1.1 with alternative. |
| 13006 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13007 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13009 | |
| 13010 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13011 | // negotiated. |
| 13012 | StaticSocketDataProvider data; |
| 13013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13014 | |
| 13015 | // Negotiate HTTP/1.1 with origin. |
| 13016 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13017 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13019 | |
| 13020 | MockWrite http_writes[] = { |
| 13021 | MockWrite( |
| 13022 | "GET / HTTP/1.1\r\n" |
| 13023 | "Host: origin.example.org\r\n" |
| 13024 | "Connection: keep-alive\r\n\r\n"), |
| 13025 | MockWrite( |
| 13026 | "GET /second HTTP/1.1\r\n" |
| 13027 | "Host: origin.example.org\r\n" |
| 13028 | "Connection: keep-alive\r\n\r\n"), |
| 13029 | }; |
| 13030 | |
| 13031 | MockRead http_reads[] = { |
| 13032 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13033 | MockRead("Content-Type: text/html\r\n"), |
| 13034 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13035 | MockRead("foobar"), |
| 13036 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13037 | MockRead("Content-Type: text/html\r\n"), |
| 13038 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13039 | MockRead("another"), |
| 13040 | }; |
| 13041 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13042 | http_writes, arraysize(http_writes)); |
| 13043 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13044 | |
| 13045 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13046 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13047 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13048 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13049 | session->http_server_properties(); |
| 13050 | AlternativeService alternative_service( |
| 13051 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13052 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13053 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13054 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13055 | |
| 13056 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13057 | HttpRequestInfo request1; |
| 13058 | request1.method = "GET"; |
| 13059 | request1.url = GURL("https://origin.example.org:443"); |
| 13060 | request1.load_flags = 0; |
| 13061 | TestCompletionCallback callback1; |
| 13062 | |
| 13063 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13064 | rv = callback1.GetResult(rv); |
| 13065 | EXPECT_EQ(OK, rv); |
| 13066 | |
| 13067 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13068 | ASSERT_TRUE(response1 != nullptr); |
| 13069 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13070 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13071 | |
| 13072 | std::string response_data1; |
| 13073 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13074 | EXPECT_EQ("foobar", response_data1); |
| 13075 | |
| 13076 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13077 | // for alternative service. |
| 13078 | EXPECT_TRUE( |
| 13079 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13080 | |
| 13081 | // Since |alternative_service| is broken, a second transaction to origin |
| 13082 | // should not start an alternate Job. It should pool to existing connection |
| 13083 | // to origin. |
| 13084 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13085 | HttpRequestInfo request2; |
| 13086 | request2.method = "GET"; |
| 13087 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13088 | request2.load_flags = 0; |
| 13089 | TestCompletionCallback callback2; |
| 13090 | |
| 13091 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13092 | rv = callback2.GetResult(rv); |
| 13093 | EXPECT_EQ(OK, rv); |
| 13094 | |
| 13095 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13096 | ASSERT_TRUE(response2 != nullptr); |
| 13097 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13098 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13099 | |
| 13100 | std::string response_data2; |
| 13101 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13102 | EXPECT_EQ("another", response_data2); |
| 13103 | } |
| 13104 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13105 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13106 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13107 | // used. |
| 13108 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13109 | HostPortPair origin("origin.example.org", 443); |
| 13110 | HostPortPair alternative("alternative.example.org", 443); |
| 13111 | std::string origin_url = "https://origin.example.org:443"; |
| 13112 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13113 | |
| 13114 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13115 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13116 | ssl.SetNextProto(kProtoHTTP11); |
| 13117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13118 | |
| 13119 | // HTTP/1.1 data for |request1| and |request2|. |
| 13120 | MockWrite http_writes[] = { |
| 13121 | MockWrite( |
| 13122 | "GET / HTTP/1.1\r\n" |
| 13123 | "Host: alternative.example.org\r\n" |
| 13124 | "Connection: keep-alive\r\n\r\n"), |
| 13125 | MockWrite( |
| 13126 | "GET / HTTP/1.1\r\n" |
| 13127 | "Host: alternative.example.org\r\n" |
| 13128 | "Connection: keep-alive\r\n\r\n"), |
| 13129 | }; |
| 13130 | |
| 13131 | MockRead http_reads[] = { |
| 13132 | MockRead( |
| 13133 | "HTTP/1.1 200 OK\r\n" |
| 13134 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13135 | "Content-Length: 40\r\n\r\n" |
| 13136 | "first HTTP/1.1 response from alternative"), |
| 13137 | MockRead( |
| 13138 | "HTTP/1.1 200 OK\r\n" |
| 13139 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13140 | "Content-Length: 41\r\n\r\n" |
| 13141 | "second HTTP/1.1 response from alternative"), |
| 13142 | }; |
| 13143 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13144 | http_writes, arraysize(http_writes)); |
| 13145 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13146 | |
| 13147 | // This test documents that an alternate Job should not pool to an already |
| 13148 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13149 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13150 | StaticSocketDataProvider data_refused; |
| 13151 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13152 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13153 | |
| 13154 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13155 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13156 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13157 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13158 | session->http_server_properties(); |
| 13159 | AlternativeService alternative_service( |
| 13160 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13161 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13162 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13163 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13164 | |
| 13165 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13166 | scoped_ptr<HttpTransaction> trans1( |
| 13167 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13168 | HttpRequestInfo request1; |
| 13169 | request1.method = "GET"; |
| 13170 | request1.url = GURL(alternative_url); |
| 13171 | request1.load_flags = 0; |
| 13172 | TestCompletionCallback callback1; |
| 13173 | |
| 13174 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13175 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13176 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13177 | ASSERT_TRUE(response1); |
| 13178 | ASSERT_TRUE(response1->headers.get()); |
| 13179 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13180 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13181 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13182 | std::string response_data1; |
| 13183 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13184 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13185 | |
| 13186 | // Request for origin.example.org, which has an alternative service. This |
| 13187 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13188 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13189 | // open other connections to alternative server. The Job to origin fails, so |
| 13190 | // this request fails. |
| 13191 | scoped_ptr<HttpTransaction> trans2( |
| 13192 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13193 | HttpRequestInfo request2; |
| 13194 | request2.method = "GET"; |
| 13195 | request2.url = GURL(origin_url); |
| 13196 | request2.load_flags = 0; |
| 13197 | TestCompletionCallback callback2; |
| 13198 | |
| 13199 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13200 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13201 | |
| 13202 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13203 | // socket is still open and in the pool. |
| 13204 | scoped_ptr<HttpTransaction> trans3( |
| 13205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13206 | HttpRequestInfo request3; |
| 13207 | request3.method = "GET"; |
| 13208 | request3.url = GURL(alternative_url); |
| 13209 | request3.load_flags = 0; |
| 13210 | TestCompletionCallback callback3; |
| 13211 | |
| 13212 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13213 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13214 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13215 | ASSERT_TRUE(response3); |
| 13216 | ASSERT_TRUE(response3->headers.get()); |
| 13217 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13218 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13219 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13220 | std::string response_data3; |
| 13221 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13222 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13223 | } |
| 13224 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13225 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13226 | const std::string https_url = "https://www.example.org:8080/"; |
| 13227 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13228 | |
| 13229 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13230 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13231 | scoped_ptr<SpdyFrame> connect( |
| 13232 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13233 | scoped_ptr<SpdyFrame> req1( |
| 13234 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13235 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13236 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13237 | |
| 13238 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13239 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13240 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13241 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13242 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13243 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13244 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13245 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13246 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13247 | |
| 13248 | MockWrite writes1[] = { |
| 13249 | CreateMockWrite(*connect, 0), |
| 13250 | CreateMockWrite(*wrapped_req1, 2), |
| 13251 | CreateMockWrite(*req2, 5), |
| 13252 | }; |
| 13253 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13254 | scoped_ptr<SpdyFrame> conn_resp( |
| 13255 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13256 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13257 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13258 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 13259 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 13260 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 13261 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 13262 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13263 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13264 | MockRead reads1[] = { |
| 13265 | CreateMockRead(*conn_resp, 1), |
| 13266 | CreateMockRead(*wrapped_resp1, 3), |
| 13267 | CreateMockRead(*wrapped_body1, 4), |
| 13268 | CreateMockRead(*resp2, 6), |
| 13269 | CreateMockRead(*body2, 7), |
| 13270 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 13271 | }; |
| 13272 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13273 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 13274 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13275 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13276 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13277 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13278 | session_deps_.proxy_service = |
| 13279 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13280 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13281 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13282 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13283 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13284 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13285 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13286 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13287 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13288 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13289 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13290 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13291 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13292 | |
| 13293 | // Start the first transaction to set up the SpdySession |
| 13294 | HttpRequestInfo request1; |
| 13295 | request1.method = "GET"; |
| 13296 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13297 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13298 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13299 | TestCompletionCallback callback1; |
| 13300 | EXPECT_EQ(ERR_IO_PENDING, |
| 13301 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13302 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13303 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13304 | |
| 13305 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13306 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13307 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13308 | LoadTimingInfo load_timing_info1; |
| 13309 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13310 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13311 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13312 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13313 | // Now, start the HTTP request |
| 13314 | HttpRequestInfo request2; |
| 13315 | request2.method = "GET"; |
| 13316 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13317 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13318 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13319 | TestCompletionCallback callback2; |
| 13320 | EXPECT_EQ(ERR_IO_PENDING, |
| 13321 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13322 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13323 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13324 | |
| 13325 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13326 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13327 | |
| 13328 | LoadTimingInfo load_timing_info2; |
| 13329 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13330 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13331 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13332 | // HTTP requests over a SPDY session should have a different connection |
| 13333 | // socket_log_id than requests over a tunnel. |
| 13334 | 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] | 13335 | } |
| 13336 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13337 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13338 | // that we do not pool other origins that resolve to the same IP when |
| 13339 | // the certificate does not match the new origin. |
| 13340 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13341 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13342 | const std::string url1 = "http://www.example.org/"; |
| 13343 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13344 | const std::string ip_addr = "1.2.3.4"; |
| 13345 | |
| 13346 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13347 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13348 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13349 | scoped_ptr<SpdyFrame> req1( |
| 13350 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13351 | |
| 13352 | MockWrite writes1[] = { |
| 13353 | CreateMockWrite(*req1, 0), |
| 13354 | }; |
| 13355 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13356 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13357 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13358 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13359 | CreateMockRead(*resp1, 1), |
| 13360 | CreateMockRead(*body1, 2), |
| 13361 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13362 | }; |
| 13363 | |
| 13364 | scoped_ptr<DeterministicSocketData> data1( |
| 13365 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 13366 | writes1, arraysize(writes1))); |
| 13367 | IPAddressNumber ip; |
| 13368 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13369 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13370 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 13371 | data1->set_connect_data(connect_data1); |
| 13372 | |
| 13373 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13374 | scoped_ptr<SpdyFrame> req2( |
| 13375 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13376 | |
| 13377 | MockWrite writes2[] = { |
| 13378 | CreateMockWrite(*req2, 0), |
| 13379 | }; |
| 13380 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13381 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13382 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13383 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13384 | CreateMockRead(*resp2, 1), |
| 13385 | CreateMockRead(*body2, 2), |
| 13386 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13387 | }; |
| 13388 | |
| 13389 | scoped_ptr<DeterministicSocketData> data2( |
| 13390 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 13391 | writes2, arraysize(writes2))); |
| 13392 | MockConnect connect_data2(ASYNC, OK); |
| 13393 | data2->set_connect_data(connect_data2); |
| 13394 | |
| 13395 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13396 | // all others direct. |
| 13397 | ProxyConfig proxy_config; |
| 13398 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13399 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13400 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13401 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13402 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13403 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 13404 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13405 | // Load a valid cert. Note, that this does not need to |
| 13406 | // be valid for proxy because the MockSSLClientSocket does |
| 13407 | // not actually verify it. But SpdySession will use this |
| 13408 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13409 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13410 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13411 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13412 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13413 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13414 | |
| 13415 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13416 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13417 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13418 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13419 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13420 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13421 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13422 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13423 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13424 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13425 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13426 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13427 | |
| 13428 | // Start the first transaction to set up the SpdySession |
| 13429 | HttpRequestInfo request1; |
| 13430 | request1.method = "GET"; |
| 13431 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13432 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13433 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13434 | TestCompletionCallback callback1; |
| 13435 | ASSERT_EQ(ERR_IO_PENDING, |
| 13436 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 13437 | data1->RunFor(3); |
| 13438 | |
| 13439 | ASSERT_TRUE(callback1.have_result()); |
| 13440 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13441 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13442 | |
| 13443 | // Now, start the HTTP request |
| 13444 | HttpRequestInfo request2; |
| 13445 | request2.method = "GET"; |
| 13446 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13447 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13448 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13449 | TestCompletionCallback callback2; |
| 13450 | EXPECT_EQ(ERR_IO_PENDING, |
| 13451 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13452 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13453 | data2->RunFor(3); |
| 13454 | |
| 13455 | ASSERT_TRUE(callback2.have_result()); |
| 13456 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13457 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13458 | } |
| 13459 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13460 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13461 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13462 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13463 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13464 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13465 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13466 | |
| 13467 | MockRead reads1[] = { |
| 13468 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13469 | }; |
| 13470 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13471 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13472 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13473 | scoped_ptr<SpdyFrame> req2( |
| 13474 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13475 | MockWrite writes2[] = { |
| 13476 | CreateMockWrite(*req2, 0), |
| 13477 | }; |
| 13478 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13479 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13480 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13481 | MockRead reads2[] = { |
| 13482 | CreateMockRead(*resp2, 1), |
| 13483 | CreateMockRead(*body2, 2), |
| 13484 | MockRead(ASYNC, OK, 3) // EOF |
| 13485 | }; |
| 13486 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13487 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13488 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13489 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13490 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13491 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13494 | |
| 13495 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13496 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13497 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13498 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13499 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13500 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13501 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13502 | |
| 13503 | // Start the first transaction to set up the SpdySession and verify that |
| 13504 | // connection was closed. |
| 13505 | HttpRequestInfo request1; |
| 13506 | request1.method = "GET"; |
| 13507 | request1.url = GURL(https_url); |
| 13508 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13509 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13510 | TestCompletionCallback callback1; |
| 13511 | EXPECT_EQ(ERR_IO_PENDING, |
| 13512 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13513 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13514 | |
| 13515 | // Now, start the second request and make sure it succeeds. |
| 13516 | HttpRequestInfo request2; |
| 13517 | request2.method = "GET"; |
| 13518 | request2.url = GURL(https_url); |
| 13519 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13520 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13521 | TestCompletionCallback callback2; |
| 13522 | EXPECT_EQ(ERR_IO_PENDING, |
| 13523 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13524 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13525 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13526 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13527 | } |
| 13528 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13529 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13530 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13531 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13532 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13533 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13534 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13535 | |
| 13536 | // Use two different hosts with different IPs so they don't get pooled. |
| 13537 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13538 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13539 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13540 | |
| 13541 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13542 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13543 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13544 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13547 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13548 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13549 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13550 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13551 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13552 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13553 | scoped_ptr<SpdyFrame> host1_resp( |
| 13554 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13555 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13556 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13557 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13558 | CreateMockRead(*host1_resp, 1), |
| 13559 | CreateMockRead(*host1_resp_body, 2), |
| 13560 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13561 | }; |
| 13562 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13563 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13564 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13565 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13566 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13567 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13568 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13569 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13570 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13571 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13572 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13573 | scoped_ptr<SpdyFrame> host2_resp( |
| 13574 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13575 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13576 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13577 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13578 | CreateMockRead(*host2_resp, 1), |
| 13579 | CreateMockRead(*host2_resp_body, 2), |
| 13580 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13581 | }; |
| 13582 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13583 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13584 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13585 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13586 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13587 | |
| 13588 | MockWrite http_write[] = { |
| 13589 | MockWrite("GET / HTTP/1.1\r\n" |
| 13590 | "Host: www.a.com\r\n" |
| 13591 | "Connection: keep-alive\r\n\r\n"), |
| 13592 | }; |
| 13593 | |
| 13594 | MockRead http_read[] = { |
| 13595 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13596 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13597 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13598 | MockRead("hello!"), |
| 13599 | }; |
| 13600 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13601 | http_write, arraysize(http_write)); |
| 13602 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13603 | |
| 13604 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13605 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13606 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13607 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13608 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13609 | |
| 13610 | TestCompletionCallback callback; |
| 13611 | HttpRequestInfo request1; |
| 13612 | request1.method = "GET"; |
| 13613 | request1.url = GURL("https://www.a.com/"); |
| 13614 | request1.load_flags = 0; |
| 13615 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13616 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13617 | |
| 13618 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13620 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13621 | |
| 13622 | const HttpResponseInfo* 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_TRUE(response->was_fetched_via_spdy); |
| 13627 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13628 | |
| 13629 | std::string response_data; |
| 13630 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13631 | EXPECT_EQ("hello!", response_data); |
| 13632 | trans.reset(); |
| 13633 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13634 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13635 | |
| 13636 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13637 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13638 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13639 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13640 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13641 | HttpRequestInfo request2; |
| 13642 | request2.method = "GET"; |
| 13643 | request2.url = GURL("https://www.b.com/"); |
| 13644 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13645 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13646 | |
| 13647 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13648 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13649 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13650 | |
| 13651 | response = trans->GetResponseInfo(); |
| 13652 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13653 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13654 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13655 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13656 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13657 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13658 | EXPECT_EQ("hello!", response_data); |
| 13659 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13660 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13661 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13662 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13663 | |
| 13664 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13665 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13666 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13667 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13668 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13669 | HttpRequestInfo request3; |
| 13670 | request3.method = "GET"; |
| 13671 | request3.url = GURL("http://www.a.com/"); |
| 13672 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13673 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13674 | |
| 13675 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13677 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13678 | |
| 13679 | response = trans->GetResponseInfo(); |
| 13680 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13681 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13682 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13683 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13684 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13685 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13686 | EXPECT_EQ("hello!", response_data); |
| 13687 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13688 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13689 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13690 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13691 | } |
| 13692 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13693 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13694 | HttpRequestInfo request; |
| 13695 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13696 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13697 | request.load_flags = 0; |
| 13698 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13699 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13700 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13701 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13702 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13703 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13704 | StaticSocketDataProvider data; |
| 13705 | data.set_connect_data(mock_connect); |
| 13706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13707 | |
| 13708 | TestCompletionCallback callback; |
| 13709 | |
| 13710 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13712 | |
| 13713 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13714 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13715 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13716 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13717 | HttpRequestHeaders request_headers; |
| 13718 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13719 | |
| 13720 | ConnectionAttempts attempts; |
| 13721 | trans->GetConnectionAttempts(&attempts); |
| 13722 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13723 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13724 | |
| 13725 | IPEndPoint endpoint; |
| 13726 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13727 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13728 | } |
| 13729 | |
| 13730 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13731 | HttpRequestInfo request; |
| 13732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13733 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13734 | request.load_flags = 0; |
| 13735 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13736 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13737 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13738 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13739 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13740 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13741 | StaticSocketDataProvider data; |
| 13742 | data.set_connect_data(mock_connect); |
| 13743 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13744 | |
| 13745 | TestCompletionCallback callback; |
| 13746 | |
| 13747 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13748 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13749 | |
| 13750 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13751 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13752 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13753 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13754 | HttpRequestHeaders request_headers; |
| 13755 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13756 | |
| 13757 | ConnectionAttempts attempts; |
| 13758 | trans->GetConnectionAttempts(&attempts); |
| 13759 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13760 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13761 | |
| 13762 | IPEndPoint endpoint; |
| 13763 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13764 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13765 | } |
| 13766 | |
| 13767 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13768 | HttpRequestInfo request; |
| 13769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13770 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13771 | request.load_flags = 0; |
| 13772 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13773 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13774 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13775 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13776 | |
| 13777 | MockWrite data_writes[] = { |
| 13778 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13779 | }; |
| 13780 | MockRead data_reads[] = { |
| 13781 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13782 | }; |
| 13783 | |
| 13784 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13785 | data_writes, arraysize(data_writes)); |
| 13786 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13787 | |
| 13788 | TestCompletionCallback callback; |
| 13789 | |
| 13790 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13791 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13792 | |
| 13793 | rv = callback.WaitForResult(); |
| 13794 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13795 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13796 | HttpRequestHeaders request_headers; |
| 13797 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13798 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13799 | } |
| 13800 | |
| 13801 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13802 | HttpRequestInfo request; |
| 13803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13804 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13805 | request.load_flags = 0; |
| 13806 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13807 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13808 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13809 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13810 | |
| 13811 | MockWrite data_writes[] = { |
| 13812 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13813 | }; |
| 13814 | MockRead data_reads[] = { |
| 13815 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13816 | }; |
| 13817 | |
| 13818 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13819 | data_writes, arraysize(data_writes)); |
| 13820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13821 | |
| 13822 | TestCompletionCallback callback; |
| 13823 | |
| 13824 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13826 | |
| 13827 | rv = callback.WaitForResult(); |
| 13828 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13829 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13830 | HttpRequestHeaders request_headers; |
| 13831 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13832 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13833 | } |
| 13834 | |
| 13835 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13836 | HttpRequestInfo request; |
| 13837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13838 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13839 | request.load_flags = 0; |
| 13840 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13841 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13842 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13843 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13844 | |
| 13845 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13846 | MockWrite( |
| 13847 | "GET / HTTP/1.1\r\n" |
| 13848 | "Host: www.example.org\r\n" |
| 13849 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13850 | }; |
| 13851 | MockRead data_reads[] = { |
| 13852 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13853 | }; |
| 13854 | |
| 13855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13856 | data_writes, arraysize(data_writes)); |
| 13857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13858 | |
| 13859 | TestCompletionCallback callback; |
| 13860 | |
| 13861 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13863 | |
| 13864 | rv = callback.WaitForResult(); |
| 13865 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13866 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13867 | HttpRequestHeaders request_headers; |
| 13868 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13869 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13870 | } |
| 13871 | |
| 13872 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13873 | HttpRequestInfo request; |
| 13874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13875 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13876 | request.load_flags = 0; |
| 13877 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13878 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13879 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13881 | |
| 13882 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13883 | MockWrite( |
| 13884 | "GET / HTTP/1.1\r\n" |
| 13885 | "Host: www.example.org\r\n" |
| 13886 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13887 | }; |
| 13888 | MockRead data_reads[] = { |
| 13889 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13890 | }; |
| 13891 | |
| 13892 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13893 | data_writes, arraysize(data_writes)); |
| 13894 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13895 | |
| 13896 | TestCompletionCallback callback; |
| 13897 | |
| 13898 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13900 | |
| 13901 | rv = callback.WaitForResult(); |
| 13902 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13903 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13904 | HttpRequestHeaders request_headers; |
| 13905 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13906 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13907 | } |
| 13908 | |
| 13909 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13910 | HttpRequestInfo request; |
| 13911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13912 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13913 | request.load_flags = 0; |
| 13914 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13915 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13916 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13917 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13919 | |
| 13920 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13921 | MockWrite( |
| 13922 | "GET / HTTP/1.1\r\n" |
| 13923 | "Host: www.example.org\r\n" |
| 13924 | "Connection: keep-alive\r\n" |
| 13925 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13926 | }; |
| 13927 | MockRead data_reads[] = { |
| 13928 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13929 | "Content-Length: 5\r\n\r\n" |
| 13930 | "hello"), |
| 13931 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13932 | }; |
| 13933 | |
| 13934 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13935 | data_writes, arraysize(data_writes)); |
| 13936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13937 | |
| 13938 | TestCompletionCallback callback; |
| 13939 | |
| 13940 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13942 | |
| 13943 | rv = callback.WaitForResult(); |
| 13944 | EXPECT_EQ(OK, rv); |
| 13945 | |
| 13946 | HttpRequestHeaders request_headers; |
| 13947 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13948 | std::string foo; |
| 13949 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13950 | EXPECT_EQ("bar", foo); |
| 13951 | } |
| 13952 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13953 | namespace { |
| 13954 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13955 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13956 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13957 | public base::SupportsWeakPtr<FakeStream> { |
| 13958 | public: |
| 13959 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13960 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13961 | |
| 13962 | RequestPriority priority() const { return priority_; } |
| 13963 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13964 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13965 | RequestPriority priority, |
| 13966 | const BoundNetLog& net_log, |
| 13967 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13968 | return ERR_IO_PENDING; |
| 13969 | } |
| 13970 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13971 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13972 | HttpResponseInfo* response, |
| 13973 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13974 | ADD_FAILURE(); |
| 13975 | return ERR_UNEXPECTED; |
| 13976 | } |
| 13977 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13978 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13979 | ADD_FAILURE(); |
| 13980 | return ERR_UNEXPECTED; |
| 13981 | } |
| 13982 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13983 | int ReadResponseBody(IOBuffer* buf, |
| 13984 | int buf_len, |
| 13985 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13986 | ADD_FAILURE(); |
| 13987 | return ERR_UNEXPECTED; |
| 13988 | } |
| 13989 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13990 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13991 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13992 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13993 | ADD_FAILURE(); |
| 13994 | return false; |
| 13995 | } |
| 13996 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13997 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13998 | ADD_FAILURE(); |
| 13999 | return false; |
| 14000 | } |
| 14001 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14002 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14003 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14004 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14005 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14006 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14007 | ADD_FAILURE(); |
| 14008 | return 0; |
| 14009 | } |
| 14010 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14011 | int64_t GetTotalSentBytes() const override { |
| 14012 | ADD_FAILURE(); |
| 14013 | return 0; |
| 14014 | } |
| 14015 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14016 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14017 | ADD_FAILURE(); |
| 14018 | return false; |
| 14019 | } |
| 14020 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14021 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14022 | |
| 14023 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14024 | ADD_FAILURE(); |
| 14025 | } |
| 14026 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14027 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14028 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14029 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14030 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14031 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14032 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14033 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14034 | |
| 14035 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14036 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14037 | private: |
| 14038 | RequestPriority priority_; |
| 14039 | |
| 14040 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14041 | }; |
| 14042 | |
| 14043 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14044 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14045 | class FakeStreamRequest : public HttpStreamRequest, |
| 14046 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14047 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14048 | FakeStreamRequest(RequestPriority priority, |
| 14049 | HttpStreamRequest::Delegate* delegate) |
| 14050 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14051 | delegate_(delegate), |
| 14052 | websocket_stream_create_helper_(NULL) {} |
| 14053 | |
| 14054 | FakeStreamRequest(RequestPriority priority, |
| 14055 | HttpStreamRequest::Delegate* delegate, |
| 14056 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14057 | : priority_(priority), |
| 14058 | delegate_(delegate), |
| 14059 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14060 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14061 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14062 | |
| 14063 | RequestPriority priority() const { return priority_; } |
| 14064 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14065 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14066 | websocket_stream_create_helper() const { |
| 14067 | return websocket_stream_create_helper_; |
| 14068 | } |
| 14069 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14070 | // Create a new FakeStream and pass it to the request's |
| 14071 | // delegate. Returns a weak pointer to the FakeStream. |
| 14072 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14073 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14074 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14075 | // immediately delete |fake_stream|. |
| 14076 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14077 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14078 | return weak_stream; |
| 14079 | } |
| 14080 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14081 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14082 | ADD_FAILURE(); |
| 14083 | return ERR_UNEXPECTED; |
| 14084 | } |
| 14085 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14086 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14087 | ADD_FAILURE(); |
| 14088 | return LoadState(); |
| 14089 | } |
| 14090 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14091 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14092 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14093 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14094 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14095 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14096 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14097 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14098 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14099 | const ConnectionAttempts& connection_attempts() const override { |
| 14100 | static ConnectionAttempts no_attempts; |
| 14101 | return no_attempts; |
| 14102 | } |
| 14103 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14104 | private: |
| 14105 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14106 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14107 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14108 | |
| 14109 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14110 | }; |
| 14111 | |
| 14112 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14113 | class FakeStreamFactory : public HttpStreamFactory { |
| 14114 | public: |
| 14115 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14116 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14117 | |
| 14118 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14119 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14120 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14121 | return last_stream_request_; |
| 14122 | } |
| 14123 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14124 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14125 | RequestPriority priority, |
| 14126 | const SSLConfig& server_ssl_config, |
| 14127 | const SSLConfig& proxy_ssl_config, |
| 14128 | HttpStreamRequest::Delegate* delegate, |
| 14129 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14130 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14131 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14132 | return fake_request; |
| 14133 | } |
| 14134 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14135 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14136 | const HttpRequestInfo& info, |
| 14137 | RequestPriority priority, |
| 14138 | const SSLConfig& server_ssl_config, |
| 14139 | const SSLConfig& proxy_ssl_config, |
| 14140 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14141 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14142 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14143 | FakeStreamRequest* fake_request = |
| 14144 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14145 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14146 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14147 | } |
| 14148 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14149 | void PreconnectStreams(int num_streams, |
| 14150 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14151 | const SSLConfig& server_ssl_config, |
| 14152 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14153 | ADD_FAILURE(); |
| 14154 | } |
| 14155 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14156 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14157 | ADD_FAILURE(); |
| 14158 | return NULL; |
| 14159 | } |
| 14160 | |
| 14161 | private: |
| 14162 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14163 | |
| 14164 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14165 | }; |
| 14166 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14167 | // TODO(ricea): Maybe unify this with the one in |
| 14168 | // url_request_http_job_unittest.cc ? |
| 14169 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14170 | public: |
| 14171 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14172 | bool using_proxy) |
| 14173 | : state_(connection.release(), using_proxy) {} |
| 14174 | |
| 14175 | // Fake implementation of HttpStreamBase methods. |
| 14176 | // This ends up being quite "real" because this object has to really send data |
| 14177 | // on the mock socket. It might be easier to use the real implementation, but |
| 14178 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14179 | // difficult. |
| 14180 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14181 | RequestPriority priority, |
| 14182 | const BoundNetLog& net_log, |
| 14183 | const CompletionCallback& callback) override { |
| 14184 | state_.Initialize(request_info, priority, net_log, callback); |
| 14185 | return OK; |
| 14186 | } |
| 14187 | |
| 14188 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14189 | HttpResponseInfo* response, |
| 14190 | const CompletionCallback& callback) override { |
| 14191 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14192 | response, callback); |
| 14193 | } |
| 14194 | |
| 14195 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14196 | return parser()->ReadResponseHeaders(callback); |
| 14197 | } |
| 14198 | |
| 14199 | int ReadResponseBody(IOBuffer* buf, |
| 14200 | int buf_len, |
| 14201 | const CompletionCallback& callback) override { |
| 14202 | NOTREACHED(); |
| 14203 | return ERR_IO_PENDING; |
| 14204 | } |
| 14205 | |
| 14206 | void Close(bool not_reusable) override { |
| 14207 | if (parser()) |
| 14208 | parser()->Close(true); |
| 14209 | } |
| 14210 | |
| 14211 | bool IsResponseBodyComplete() const override { |
| 14212 | NOTREACHED(); |
| 14213 | return false; |
| 14214 | } |
| 14215 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14216 | bool IsConnectionReused() const override { |
| 14217 | NOTREACHED(); |
| 14218 | return false; |
| 14219 | } |
| 14220 | void SetConnectionReused() override { NOTREACHED(); } |
| 14221 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14222 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14223 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14224 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14225 | NOTREACHED(); |
| 14226 | return 0; |
| 14227 | } |
| 14228 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14229 | int64_t GetTotalSentBytes() const override { |
| 14230 | NOTREACHED(); |
| 14231 | return 0; |
| 14232 | } |
| 14233 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14234 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14235 | NOTREACHED(); |
| 14236 | return false; |
| 14237 | } |
| 14238 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14239 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14240 | |
| 14241 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14242 | NOTREACHED(); |
| 14243 | } |
| 14244 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14245 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14246 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14247 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14248 | |
| 14249 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14250 | |
| 14251 | UploadProgress GetUploadProgress() const override { |
| 14252 | NOTREACHED(); |
| 14253 | return UploadProgress(); |
| 14254 | } |
| 14255 | |
| 14256 | HttpStream* RenewStreamForAuth() override { |
| 14257 | NOTREACHED(); |
| 14258 | return nullptr; |
| 14259 | } |
| 14260 | |
| 14261 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14262 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14263 | NOTREACHED(); |
| 14264 | return scoped_ptr<WebSocketStream>(); |
| 14265 | } |
| 14266 | |
| 14267 | private: |
| 14268 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14269 | HttpBasicState state_; |
| 14270 | |
| 14271 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14272 | }; |
| 14273 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14274 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14275 | // worth doing. |
| 14276 | class FakeWebSocketStreamCreateHelper : |
| 14277 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14278 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14279 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14280 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14281 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14282 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 14283 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14284 | } |
| 14285 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14286 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14287 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14288 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14289 | NOTREACHED(); |
| 14290 | return NULL; |
| 14291 | }; |
| 14292 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14293 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14294 | |
| 14295 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14296 | NOTREACHED(); |
| 14297 | return scoped_ptr<WebSocketStream>(); |
| 14298 | } |
| 14299 | }; |
| 14300 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14301 | } // namespace |
| 14302 | |
| 14303 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14304 | // stream request on start. |
| 14305 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14306 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14307 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14308 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14309 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14310 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14311 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14312 | |
| 14313 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14314 | |
| 14315 | HttpRequestInfo request; |
| 14316 | TestCompletionCallback callback; |
| 14317 | EXPECT_EQ(ERR_IO_PENDING, |
| 14318 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14319 | |
| 14320 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14321 | fake_factory->last_stream_request(); |
| 14322 | ASSERT_TRUE(fake_request != NULL); |
| 14323 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14324 | } |
| 14325 | |
| 14326 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14327 | // updates to its stream request. |
| 14328 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14329 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14330 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14331 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14332 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14333 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14334 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14335 | |
| 14336 | HttpRequestInfo request; |
| 14337 | TestCompletionCallback callback; |
| 14338 | EXPECT_EQ(ERR_IO_PENDING, |
| 14339 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14340 | |
| 14341 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14342 | fake_factory->last_stream_request(); |
| 14343 | ASSERT_TRUE(fake_request != NULL); |
| 14344 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14345 | |
| 14346 | trans.SetPriority(LOWEST); |
| 14347 | ASSERT_TRUE(fake_request != NULL); |
| 14348 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14349 | } |
| 14350 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14351 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14352 | // updates to its stream. |
| 14353 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14354 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14355 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14356 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14357 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14358 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14359 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14360 | |
| 14361 | HttpRequestInfo request; |
| 14362 | TestCompletionCallback callback; |
| 14363 | EXPECT_EQ(ERR_IO_PENDING, |
| 14364 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14365 | |
| 14366 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14367 | fake_factory->last_stream_request(); |
| 14368 | ASSERT_TRUE(fake_request != NULL); |
| 14369 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14370 | ASSERT_TRUE(fake_stream != NULL); |
| 14371 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14372 | |
| 14373 | trans.SetPriority(LOWEST); |
| 14374 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14375 | } |
| 14376 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14377 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14378 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14379 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14380 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14381 | std::string test_cases[] = {"ws://www.example.org/", |
| 14382 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14383 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14384 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14385 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14386 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14387 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14388 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14389 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14390 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14391 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14392 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14393 | &websocket_stream_create_helper); |
| 14394 | |
| 14395 | HttpRequestInfo request; |
| 14396 | TestCompletionCallback callback; |
| 14397 | request.method = "GET"; |
| 14398 | request.url = GURL(test_cases[i]); |
| 14399 | |
| 14400 | EXPECT_EQ(ERR_IO_PENDING, |
| 14401 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14402 | |
| 14403 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14404 | fake_factory->last_stream_request(); |
| 14405 | ASSERT_TRUE(fake_request != NULL); |
| 14406 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14407 | fake_request->websocket_stream_create_helper()); |
| 14408 | } |
| 14409 | } |
| 14410 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14411 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14412 | // if the transport socket pool is stalled on the global socket limit. |
| 14413 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14414 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14415 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14416 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14417 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14418 | |
| 14419 | // Set up SSL request. |
| 14420 | |
| 14421 | HttpRequestInfo ssl_request; |
| 14422 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14423 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14424 | |
| 14425 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14426 | MockWrite( |
| 14427 | "GET / HTTP/1.1\r\n" |
| 14428 | "Host: www.example.org\r\n" |
| 14429 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14430 | }; |
| 14431 | MockRead ssl_reads[] = { |
| 14432 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14433 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14434 | MockRead("hello world"), |
| 14435 | MockRead(SYNCHRONOUS, OK), |
| 14436 | }; |
| 14437 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14438 | ssl_writes, arraysize(ssl_writes)); |
| 14439 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14440 | |
| 14441 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14442 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14443 | |
| 14444 | // Set up HTTP request. |
| 14445 | |
| 14446 | HttpRequestInfo http_request; |
| 14447 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14448 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14449 | |
| 14450 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14451 | MockWrite( |
| 14452 | "GET / HTTP/1.1\r\n" |
| 14453 | "Host: www.example.org\r\n" |
| 14454 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14455 | }; |
| 14456 | MockRead http_reads[] = { |
| 14457 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14458 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14459 | MockRead("falafel"), |
| 14460 | MockRead(SYNCHRONOUS, OK), |
| 14461 | }; |
| 14462 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14463 | http_writes, arraysize(http_writes)); |
| 14464 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14465 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14466 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14467 | |
| 14468 | // Start the SSL request. |
| 14469 | TestCompletionCallback ssl_callback; |
| 14470 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14471 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14472 | ASSERT_EQ(ERR_IO_PENDING, |
| 14473 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14474 | BoundNetLog())); |
| 14475 | |
| 14476 | // Start the HTTP request. Pool should stall. |
| 14477 | TestCompletionCallback http_callback; |
| 14478 | scoped_ptr<HttpTransaction> http_trans( |
| 14479 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14480 | ASSERT_EQ(ERR_IO_PENDING, |
| 14481 | http_trans->Start(&http_request, http_callback.callback(), |
| 14482 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14483 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14484 | |
| 14485 | // Wait for response from SSL request. |
| 14486 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14487 | std::string response_data; |
| 14488 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14489 | EXPECT_EQ("hello world", response_data); |
| 14490 | |
| 14491 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14492 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14493 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14494 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14495 | |
| 14496 | // The HTTP request can now complete. |
| 14497 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14498 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14499 | EXPECT_EQ("falafel", response_data); |
| 14500 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14501 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14502 | } |
| 14503 | |
| 14504 | // Tests that when a SSL connection is established but there's no corresponding |
| 14505 | // request that needs it, the new socket is closed if the transport socket pool |
| 14506 | // is stalled on the global socket limit. |
| 14507 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14508 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14509 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14510 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14511 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14512 | |
| 14513 | // Set up an ssl request. |
| 14514 | |
| 14515 | HttpRequestInfo ssl_request; |
| 14516 | ssl_request.method = "GET"; |
| 14517 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14518 | |
| 14519 | // No data will be sent on the SSL socket. |
| 14520 | StaticSocketDataProvider ssl_data; |
| 14521 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14522 | |
| 14523 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14525 | |
| 14526 | // Set up HTTP request. |
| 14527 | |
| 14528 | HttpRequestInfo http_request; |
| 14529 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14530 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14531 | |
| 14532 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14533 | MockWrite( |
| 14534 | "GET / HTTP/1.1\r\n" |
| 14535 | "Host: www.example.org\r\n" |
| 14536 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14537 | }; |
| 14538 | MockRead http_reads[] = { |
| 14539 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14540 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14541 | MockRead("falafel"), |
| 14542 | MockRead(SYNCHRONOUS, OK), |
| 14543 | }; |
| 14544 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14545 | http_writes, arraysize(http_writes)); |
| 14546 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14547 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14548 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14549 | |
| 14550 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14551 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14552 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14553 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14554 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 14555 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14556 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14557 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14558 | |
| 14559 | // Start the HTTP request. Pool should stall. |
| 14560 | TestCompletionCallback http_callback; |
| 14561 | scoped_ptr<HttpTransaction> http_trans( |
| 14562 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14563 | ASSERT_EQ(ERR_IO_PENDING, |
| 14564 | http_trans->Start(&http_request, http_callback.callback(), |
| 14565 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14566 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14567 | |
| 14568 | // The SSL connection will automatically be closed once the connection is |
| 14569 | // established, to let the HTTP request start. |
| 14570 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14571 | std::string response_data; |
| 14572 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14573 | EXPECT_EQ("falafel", response_data); |
| 14574 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14575 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14576 | } |
| 14577 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14578 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 14579 | ScopedVector<UploadElementReader> element_readers; |
| 14580 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14581 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14582 | |
| 14583 | HttpRequestInfo request; |
| 14584 | request.method = "POST"; |
| 14585 | request.url = GURL("http://www.foo.com/"); |
| 14586 | request.upload_data_stream = &upload_data_stream; |
| 14587 | request.load_flags = 0; |
| 14588 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14589 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14590 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14592 | // Send headers successfully, but get an error while sending the body. |
| 14593 | MockWrite data_writes[] = { |
| 14594 | MockWrite("POST / HTTP/1.1\r\n" |
| 14595 | "Host: www.foo.com\r\n" |
| 14596 | "Connection: keep-alive\r\n" |
| 14597 | "Content-Length: 3\r\n\r\n"), |
| 14598 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14599 | }; |
| 14600 | |
| 14601 | MockRead data_reads[] = { |
| 14602 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14603 | MockRead("hello world"), |
| 14604 | MockRead(SYNCHRONOUS, OK), |
| 14605 | }; |
| 14606 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14607 | arraysize(data_writes)); |
| 14608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14609 | |
| 14610 | TestCompletionCallback callback; |
| 14611 | |
| 14612 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14613 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14614 | |
| 14615 | rv = callback.WaitForResult(); |
| 14616 | EXPECT_EQ(OK, rv); |
| 14617 | |
| 14618 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14619 | ASSERT_TRUE(response != NULL); |
| 14620 | |
| 14621 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14622 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14623 | |
| 14624 | std::string response_data; |
| 14625 | rv = ReadTransaction(trans.get(), &response_data); |
| 14626 | EXPECT_EQ(OK, rv); |
| 14627 | EXPECT_EQ("hello world", response_data); |
| 14628 | } |
| 14629 | |
| 14630 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14631 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14632 | TEST_P(HttpNetworkTransactionTest, |
| 14633 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14634 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14635 | MockWrite data_writes[] = { |
| 14636 | MockWrite("GET / HTTP/1.1\r\n" |
| 14637 | "Host: www.foo.com\r\n" |
| 14638 | "Connection: keep-alive\r\n\r\n"), |
| 14639 | MockWrite("POST / HTTP/1.1\r\n" |
| 14640 | "Host: www.foo.com\r\n" |
| 14641 | "Connection: keep-alive\r\n" |
| 14642 | "Content-Length: 3\r\n\r\n"), |
| 14643 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14644 | }; |
| 14645 | |
| 14646 | MockRead data_reads[] = { |
| 14647 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14648 | "Content-Length: 14\r\n\r\n"), |
| 14649 | MockRead("first response"), |
| 14650 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14651 | "Content-Length: 15\r\n\r\n"), |
| 14652 | MockRead("second response"), |
| 14653 | MockRead(SYNCHRONOUS, OK), |
| 14654 | }; |
| 14655 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14656 | arraysize(data_writes)); |
| 14657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14658 | |
| 14659 | TestCompletionCallback callback; |
| 14660 | HttpRequestInfo request1; |
| 14661 | request1.method = "GET"; |
| 14662 | request1.url = GURL("http://www.foo.com/"); |
| 14663 | request1.load_flags = 0; |
| 14664 | |
| 14665 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14667 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14668 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14669 | |
| 14670 | rv = callback.WaitForResult(); |
| 14671 | EXPECT_EQ(OK, rv); |
| 14672 | |
| 14673 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14674 | ASSERT_TRUE(response1 != NULL); |
| 14675 | |
| 14676 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14677 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14678 | |
| 14679 | std::string response_data1; |
| 14680 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14681 | EXPECT_EQ(OK, rv); |
| 14682 | EXPECT_EQ("first response", response_data1); |
| 14683 | // Delete the transaction to release the socket back into the socket pool. |
| 14684 | trans1.reset(); |
| 14685 | |
| 14686 | ScopedVector<UploadElementReader> element_readers; |
| 14687 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14688 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14689 | |
| 14690 | HttpRequestInfo request2; |
| 14691 | request2.method = "POST"; |
| 14692 | request2.url = GURL("http://www.foo.com/"); |
| 14693 | request2.upload_data_stream = &upload_data_stream; |
| 14694 | request2.load_flags = 0; |
| 14695 | |
| 14696 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14697 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14698 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14699 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14700 | |
| 14701 | rv = callback.WaitForResult(); |
| 14702 | EXPECT_EQ(OK, rv); |
| 14703 | |
| 14704 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14705 | ASSERT_TRUE(response2 != NULL); |
| 14706 | |
| 14707 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14708 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14709 | |
| 14710 | std::string response_data2; |
| 14711 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14712 | EXPECT_EQ(OK, rv); |
| 14713 | EXPECT_EQ("second response", response_data2); |
| 14714 | } |
| 14715 | |
| 14716 | TEST_P(HttpNetworkTransactionTest, |
| 14717 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14718 | ScopedVector<UploadElementReader> element_readers; |
| 14719 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14720 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14721 | |
| 14722 | HttpRequestInfo request; |
| 14723 | request.method = "POST"; |
| 14724 | request.url = GURL("http://www.foo.com/"); |
| 14725 | request.upload_data_stream = &upload_data_stream; |
| 14726 | request.load_flags = 0; |
| 14727 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14728 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14729 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14730 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14731 | // Send headers successfully, but get an error while sending the body. |
| 14732 | MockWrite data_writes[] = { |
| 14733 | MockWrite("POST / HTTP/1.1\r\n" |
| 14734 | "Host: www.foo.com\r\n" |
| 14735 | "Connection: keep-alive\r\n" |
| 14736 | "Content-Length: 3\r\n\r\n" |
| 14737 | "fo"), |
| 14738 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14739 | }; |
| 14740 | |
| 14741 | MockRead data_reads[] = { |
| 14742 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14743 | MockRead("hello world"), |
| 14744 | MockRead(SYNCHRONOUS, OK), |
| 14745 | }; |
| 14746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14747 | arraysize(data_writes)); |
| 14748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14749 | |
| 14750 | TestCompletionCallback callback; |
| 14751 | |
| 14752 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14754 | |
| 14755 | rv = callback.WaitForResult(); |
| 14756 | EXPECT_EQ(OK, rv); |
| 14757 | |
| 14758 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14759 | ASSERT_TRUE(response != NULL); |
| 14760 | |
| 14761 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14762 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14763 | |
| 14764 | std::string response_data; |
| 14765 | rv = ReadTransaction(trans.get(), &response_data); |
| 14766 | EXPECT_EQ(OK, rv); |
| 14767 | EXPECT_EQ("hello world", response_data); |
| 14768 | } |
| 14769 | |
| 14770 | // This tests the more common case than the previous test, where headers and |
| 14771 | // body are not merged into a single request. |
| 14772 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14773 | ScopedVector<UploadElementReader> element_readers; |
| 14774 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14775 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14776 | |
| 14777 | HttpRequestInfo request; |
| 14778 | request.method = "POST"; |
| 14779 | request.url = GURL("http://www.foo.com/"); |
| 14780 | request.upload_data_stream = &upload_data_stream; |
| 14781 | request.load_flags = 0; |
| 14782 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14783 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14784 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14785 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14786 | // Send headers successfully, but get an error while sending the body. |
| 14787 | MockWrite data_writes[] = { |
| 14788 | MockWrite("POST / HTTP/1.1\r\n" |
| 14789 | "Host: www.foo.com\r\n" |
| 14790 | "Connection: keep-alive\r\n" |
| 14791 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14792 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14793 | }; |
| 14794 | |
| 14795 | MockRead data_reads[] = { |
| 14796 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14797 | MockRead("hello world"), |
| 14798 | MockRead(SYNCHRONOUS, OK), |
| 14799 | }; |
| 14800 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14801 | arraysize(data_writes)); |
| 14802 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14803 | |
| 14804 | TestCompletionCallback callback; |
| 14805 | |
| 14806 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14808 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14809 | // they can't be merged with the body in a single send. Not currently |
| 14810 | // necessary since a chunked body is never merged with headers, but this makes |
| 14811 | // the test more future proof. |
| 14812 | base::RunLoop().RunUntilIdle(); |
| 14813 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14814 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14815 | |
| 14816 | rv = callback.WaitForResult(); |
| 14817 | EXPECT_EQ(OK, rv); |
| 14818 | |
| 14819 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14820 | ASSERT_TRUE(response != NULL); |
| 14821 | |
| 14822 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14823 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14824 | |
| 14825 | std::string response_data; |
| 14826 | rv = ReadTransaction(trans.get(), &response_data); |
| 14827 | EXPECT_EQ(OK, rv); |
| 14828 | EXPECT_EQ("hello world", response_data); |
| 14829 | } |
| 14830 | |
| 14831 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 14832 | ScopedVector<UploadElementReader> element_readers; |
| 14833 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14834 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14835 | |
| 14836 | HttpRequestInfo request; |
| 14837 | request.method = "POST"; |
| 14838 | request.url = GURL("http://www.foo.com/"); |
| 14839 | request.upload_data_stream = &upload_data_stream; |
| 14840 | request.load_flags = 0; |
| 14841 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14842 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14843 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14844 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14845 | |
| 14846 | MockWrite data_writes[] = { |
| 14847 | MockWrite("POST / HTTP/1.1\r\n" |
| 14848 | "Host: www.foo.com\r\n" |
| 14849 | "Connection: keep-alive\r\n" |
| 14850 | "Content-Length: 3\r\n\r\n"), |
| 14851 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14852 | }; |
| 14853 | |
| 14854 | MockRead data_reads[] = { |
| 14855 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14856 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14857 | MockRead("hello world"), |
| 14858 | MockRead(SYNCHRONOUS, OK), |
| 14859 | }; |
| 14860 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14861 | arraysize(data_writes)); |
| 14862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14863 | |
| 14864 | TestCompletionCallback callback; |
| 14865 | |
| 14866 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14868 | |
| 14869 | rv = callback.WaitForResult(); |
| 14870 | EXPECT_EQ(OK, rv); |
| 14871 | |
| 14872 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14873 | ASSERT_TRUE(response != NULL); |
| 14874 | |
| 14875 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14876 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14877 | |
| 14878 | std::string response_data; |
| 14879 | rv = ReadTransaction(trans.get(), &response_data); |
| 14880 | EXPECT_EQ(OK, rv); |
| 14881 | EXPECT_EQ("hello world", response_data); |
| 14882 | } |
| 14883 | |
| 14884 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14885 | ScopedVector<UploadElementReader> element_readers; |
| 14886 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14887 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14888 | |
| 14889 | HttpRequestInfo request; |
| 14890 | request.method = "POST"; |
| 14891 | request.url = GURL("http://www.foo.com/"); |
| 14892 | request.upload_data_stream = &upload_data_stream; |
| 14893 | request.load_flags = 0; |
| 14894 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14895 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14896 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14898 | // Send headers successfully, but get an error while sending the body. |
| 14899 | MockWrite data_writes[] = { |
| 14900 | MockWrite("POST / HTTP/1.1\r\n" |
| 14901 | "Host: www.foo.com\r\n" |
| 14902 | "Connection: keep-alive\r\n" |
| 14903 | "Content-Length: 3\r\n\r\n"), |
| 14904 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14905 | }; |
| 14906 | |
| 14907 | MockRead data_reads[] = { |
| 14908 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14909 | MockRead("hello world"), |
| 14910 | MockRead(SYNCHRONOUS, OK), |
| 14911 | }; |
| 14912 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14913 | arraysize(data_writes)); |
| 14914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14915 | |
| 14916 | TestCompletionCallback callback; |
| 14917 | |
| 14918 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14920 | |
| 14921 | rv = callback.WaitForResult(); |
| 14922 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14923 | } |
| 14924 | |
| 14925 | TEST_P(HttpNetworkTransactionTest, |
| 14926 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14927 | ScopedVector<UploadElementReader> element_readers; |
| 14928 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14929 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14930 | |
| 14931 | HttpRequestInfo request; |
| 14932 | request.method = "POST"; |
| 14933 | request.url = GURL("http://www.foo.com/"); |
| 14934 | request.upload_data_stream = &upload_data_stream; |
| 14935 | request.load_flags = 0; |
| 14936 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14937 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14938 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14939 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14940 | // Send headers successfully, but get an error while sending the body. |
| 14941 | MockWrite data_writes[] = { |
| 14942 | MockWrite("POST / HTTP/1.1\r\n" |
| 14943 | "Host: www.foo.com\r\n" |
| 14944 | "Connection: keep-alive\r\n" |
| 14945 | "Content-Length: 3\r\n\r\n"), |
| 14946 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14947 | }; |
| 14948 | |
| 14949 | MockRead data_reads[] = { |
| 14950 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14951 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14952 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14953 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14954 | MockRead(SYNCHRONOUS, OK), |
| 14955 | }; |
| 14956 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14957 | arraysize(data_writes)); |
| 14958 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14959 | |
| 14960 | TestCompletionCallback callback; |
| 14961 | |
| 14962 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14963 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14964 | |
| 14965 | rv = callback.WaitForResult(); |
| 14966 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14967 | } |
| 14968 | |
| 14969 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14970 | ScopedVector<UploadElementReader> element_readers; |
| 14971 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14972 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14973 | |
| 14974 | HttpRequestInfo request; |
| 14975 | request.method = "POST"; |
| 14976 | request.url = GURL("http://www.foo.com/"); |
| 14977 | request.upload_data_stream = &upload_data_stream; |
| 14978 | request.load_flags = 0; |
| 14979 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14980 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14981 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14982 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14983 | // Send headers successfully, but get an error while sending the body. |
| 14984 | MockWrite data_writes[] = { |
| 14985 | MockWrite("POST / HTTP/1.1\r\n" |
| 14986 | "Host: www.foo.com\r\n" |
| 14987 | "Connection: keep-alive\r\n" |
| 14988 | "Content-Length: 3\r\n\r\n"), |
| 14989 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14990 | }; |
| 14991 | |
| 14992 | MockRead data_reads[] = { |
| 14993 | MockRead("HTTP 0.9 rocks!"), |
| 14994 | MockRead(SYNCHRONOUS, OK), |
| 14995 | }; |
| 14996 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14997 | arraysize(data_writes)); |
| 14998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14999 | |
| 15000 | TestCompletionCallback callback; |
| 15001 | |
| 15002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15004 | |
| 15005 | rv = callback.WaitForResult(); |
| 15006 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15007 | } |
| 15008 | |
| 15009 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 15010 | ScopedVector<UploadElementReader> element_readers; |
| 15011 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15012 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15013 | |
| 15014 | HttpRequestInfo request; |
| 15015 | request.method = "POST"; |
| 15016 | request.url = GURL("http://www.foo.com/"); |
| 15017 | request.upload_data_stream = &upload_data_stream; |
| 15018 | request.load_flags = 0; |
| 15019 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15020 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15023 | // Send headers successfully, but get an error while sending the body. |
| 15024 | MockWrite data_writes[] = { |
| 15025 | MockWrite("POST / HTTP/1.1\r\n" |
| 15026 | "Host: www.foo.com\r\n" |
| 15027 | "Connection: keep-alive\r\n" |
| 15028 | "Content-Length: 3\r\n\r\n"), |
| 15029 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15030 | }; |
| 15031 | |
| 15032 | MockRead data_reads[] = { |
| 15033 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15034 | MockRead(SYNCHRONOUS, OK), |
| 15035 | }; |
| 15036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15037 | arraysize(data_writes)); |
| 15038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15039 | |
| 15040 | TestCompletionCallback callback; |
| 15041 | |
| 15042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15044 | |
| 15045 | rv = callback.WaitForResult(); |
| 15046 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15047 | } |
| 15048 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15049 | // Verify that proxy headers are not sent to the destination server when |
| 15050 | // establishing a tunnel for a secure WebSocket connection. |
| 15051 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15052 | HttpRequestInfo request; |
| 15053 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15054 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15055 | AddWebSocketHeaders(&request.extra_headers); |
| 15056 | |
| 15057 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15058 | session_deps_.proxy_service = |
| 15059 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15060 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15061 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15062 | |
| 15063 | // Since a proxy is configured, try to establish a tunnel. |
| 15064 | MockWrite data_writes[] = { |
| 15065 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15066 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15067 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15068 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15069 | |
| 15070 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15071 | // be issuing -- the final header line contains the credentials. |
| 15072 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15073 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15074 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15075 | "Proxy-Connection: keep-alive\r\n" |
| 15076 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15077 | |
| 15078 | MockWrite( |
| 15079 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15080 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15081 | "Connection: Upgrade\r\n" |
| 15082 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15083 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15084 | "Sec-WebSocket-Version: 13\r\n" |
| 15085 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15086 | }; |
| 15087 | |
| 15088 | // The proxy responds to the connect with a 407, using a persistent |
| 15089 | // connection. |
| 15090 | MockRead data_reads[] = { |
| 15091 | // No credentials. |
| 15092 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15093 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15094 | MockRead("Content-Length: 0\r\n"), |
| 15095 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15096 | |
| 15097 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15098 | |
| 15099 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15100 | MockRead("Upgrade: websocket\r\n"), |
| 15101 | MockRead("Connection: Upgrade\r\n"), |
| 15102 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15103 | }; |
| 15104 | |
| 15105 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15106 | arraysize(data_writes)); |
| 15107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15108 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15110 | |
| 15111 | scoped_ptr<HttpTransaction> trans( |
| 15112 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15113 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15114 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15115 | &websocket_stream_create_helper); |
| 15116 | |
| 15117 | { |
| 15118 | TestCompletionCallback callback; |
| 15119 | |
| 15120 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15122 | |
| 15123 | rv = callback.WaitForResult(); |
| 15124 | EXPECT_EQ(OK, rv); |
| 15125 | } |
| 15126 | |
| 15127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15128 | ASSERT_TRUE(response); |
| 15129 | ASSERT_TRUE(response->headers.get()); |
| 15130 | EXPECT_EQ(407, response->headers->response_code()); |
| 15131 | |
| 15132 | { |
| 15133 | TestCompletionCallback callback; |
| 15134 | |
| 15135 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15136 | callback.callback()); |
| 15137 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15138 | |
| 15139 | rv = callback.WaitForResult(); |
| 15140 | EXPECT_EQ(OK, rv); |
| 15141 | } |
| 15142 | |
| 15143 | response = trans->GetResponseInfo(); |
| 15144 | ASSERT_TRUE(response); |
| 15145 | ASSERT_TRUE(response->headers.get()); |
| 15146 | |
| 15147 | EXPECT_EQ(101, response->headers->response_code()); |
| 15148 | |
| 15149 | trans.reset(); |
| 15150 | session->CloseAllConnections(); |
| 15151 | } |
| 15152 | |
| 15153 | // Verify that proxy headers are not sent to the destination server when |
| 15154 | // establishing a tunnel for an insecure WebSocket connection. |
| 15155 | // This requires the authentication info to be injected into the auth cache |
| 15156 | // due to crbug.com/395064 |
| 15157 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15158 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15159 | HttpRequestInfo request; |
| 15160 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15161 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15162 | AddWebSocketHeaders(&request.extra_headers); |
| 15163 | |
| 15164 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15165 | session_deps_.proxy_service = |
| 15166 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15167 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15168 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15169 | |
| 15170 | MockWrite data_writes[] = { |
| 15171 | // Try to establish a tunnel for the WebSocket connection, with |
| 15172 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15173 | // they cannot and will not use the same TCP/IP connection as the |
| 15174 | // preflight HTTP request. |
| 15175 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15176 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15177 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15178 | "Proxy-Connection: keep-alive\r\n" |
| 15179 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15180 | |
| 15181 | MockWrite( |
| 15182 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15183 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15184 | "Connection: Upgrade\r\n" |
| 15185 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15186 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15187 | "Sec-WebSocket-Version: 13\r\n" |
| 15188 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15189 | }; |
| 15190 | |
| 15191 | MockRead data_reads[] = { |
| 15192 | // HTTP CONNECT with credentials. |
| 15193 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15194 | |
| 15195 | // WebSocket connection established inside tunnel. |
| 15196 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15197 | MockRead("Upgrade: websocket\r\n"), |
| 15198 | MockRead("Connection: Upgrade\r\n"), |
| 15199 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15200 | }; |
| 15201 | |
| 15202 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15203 | arraysize(data_writes)); |
| 15204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15205 | |
| 15206 | session->http_auth_cache()->Add( |
| 15207 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15208 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15209 | |
| 15210 | scoped_ptr<HttpTransaction> trans( |
| 15211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15212 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15213 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15214 | &websocket_stream_create_helper); |
| 15215 | |
| 15216 | TestCompletionCallback callback; |
| 15217 | |
| 15218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15220 | |
| 15221 | rv = callback.WaitForResult(); |
| 15222 | EXPECT_EQ(OK, rv); |
| 15223 | |
| 15224 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15225 | ASSERT_TRUE(response); |
| 15226 | ASSERT_TRUE(response->headers.get()); |
| 15227 | |
| 15228 | EXPECT_EQ(101, response->headers->response_code()); |
| 15229 | |
| 15230 | trans.reset(); |
| 15231 | session->CloseAllConnections(); |
| 15232 | } |
| 15233 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15234 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
| 15235 | ScopedVector<UploadElementReader> element_readers; |
| 15236 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15237 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 15238 | |
| 15239 | HttpRequestInfo request; |
| 15240 | request.method = "POST"; |
| 15241 | request.url = GURL("http://www.foo.com/"); |
| 15242 | request.upload_data_stream = &upload_data_stream; |
| 15243 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15244 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15245 | scoped_ptr<HttpTransaction> trans( |
| 15246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15247 | MockWrite data_writes[] = { |
| 15248 | MockWrite("POST / HTTP/1.1\r\n" |
| 15249 | "Host: www.foo.com\r\n" |
| 15250 | "Connection: keep-alive\r\n" |
| 15251 | "Content-Length: 3\r\n\r\n"), |
| 15252 | MockWrite("foo"), |
| 15253 | }; |
| 15254 | |
| 15255 | MockRead data_reads[] = { |
| 15256 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15257 | MockRead(SYNCHRONOUS, OK), |
| 15258 | }; |
| 15259 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15260 | arraysize(data_writes)); |
| 15261 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15262 | |
| 15263 | TestCompletionCallback callback; |
| 15264 | |
| 15265 | EXPECT_EQ(ERR_IO_PENDING, |
| 15266 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15267 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15268 | |
| 15269 | std::string response_data; |
| 15270 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15271 | |
| 15272 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15273 | trans->GetTotalSentBytes()); |
| 15274 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15275 | trans->GetTotalReceivedBytes()); |
| 15276 | } |
| 15277 | |
| 15278 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
| 15279 | ScopedVector<UploadElementReader> element_readers; |
| 15280 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15281 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 15282 | |
| 15283 | HttpRequestInfo request; |
| 15284 | request.method = "POST"; |
| 15285 | request.url = GURL("http://www.foo.com/"); |
| 15286 | request.upload_data_stream = &upload_data_stream; |
| 15287 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15288 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15289 | scoped_ptr<HttpTransaction> trans( |
| 15290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15291 | MockWrite data_writes[] = { |
| 15292 | MockWrite("POST / HTTP/1.1\r\n" |
| 15293 | "Host: www.foo.com\r\n" |
| 15294 | "Connection: keep-alive\r\n" |
| 15295 | "Content-Length: 3\r\n\r\n"), |
| 15296 | MockWrite("foo"), |
| 15297 | }; |
| 15298 | |
| 15299 | MockRead data_reads[] = { |
| 15300 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15301 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15302 | MockRead(SYNCHRONOUS, OK), |
| 15303 | }; |
| 15304 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15305 | arraysize(data_writes)); |
| 15306 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15307 | |
| 15308 | TestCompletionCallback callback; |
| 15309 | |
| 15310 | EXPECT_EQ(ERR_IO_PENDING, |
| 15311 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15312 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15313 | |
| 15314 | std::string response_data; |
| 15315 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15316 | |
| 15317 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15318 | trans->GetTotalSentBytes()); |
| 15319 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15320 | trans->GetTotalReceivedBytes()); |
| 15321 | } |
| 15322 | |
| 15323 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
| 15324 | ScopedVector<UploadElementReader> element_readers; |
| 15325 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15326 | ChunkedUploadDataStream upload_data_stream(0); |
| 15327 | |
| 15328 | HttpRequestInfo request; |
| 15329 | request.method = "POST"; |
| 15330 | request.url = GURL("http://www.foo.com/"); |
| 15331 | request.upload_data_stream = &upload_data_stream; |
| 15332 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15333 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15334 | scoped_ptr<HttpTransaction> trans( |
| 15335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15336 | // Send headers successfully, but get an error while sending the body. |
| 15337 | MockWrite data_writes[] = { |
| 15338 | MockWrite("POST / HTTP/1.1\r\n" |
| 15339 | "Host: www.foo.com\r\n" |
| 15340 | "Connection: keep-alive\r\n" |
| 15341 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15342 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15343 | }; |
| 15344 | |
| 15345 | MockRead data_reads[] = { |
| 15346 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15347 | MockRead(SYNCHRONOUS, OK), |
| 15348 | }; |
| 15349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15350 | arraysize(data_writes)); |
| 15351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15352 | |
| 15353 | TestCompletionCallback callback; |
| 15354 | |
| 15355 | EXPECT_EQ(ERR_IO_PENDING, |
| 15356 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15357 | |
| 15358 | base::RunLoop().RunUntilIdle(); |
| 15359 | upload_data_stream.AppendData("f", 1, false); |
| 15360 | |
| 15361 | base::RunLoop().RunUntilIdle(); |
| 15362 | upload_data_stream.AppendData("oo", 2, true); |
| 15363 | |
| 15364 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15365 | |
| 15366 | std::string response_data; |
| 15367 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15368 | |
| 15369 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15370 | trans->GetTotalSentBytes()); |
| 15371 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15372 | trans->GetTotalReceivedBytes()); |
| 15373 | } |
| 15374 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15375 | } // namespace net |