[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 35 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 37 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 38 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 39 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 40 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 41 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 42 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 81 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 82 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 84 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 85 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 87 | using base::ASCIIToUTF16; |
| 88 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 89 | //----------------------------------------------------------------------------- |
| 90 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 91 | namespace net { |
| 92 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 93 | namespace { |
| 94 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 95 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 96 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 97 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 98 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 99 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 100 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 101 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 102 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 103 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 104 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 105 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 106 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 107 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 108 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 109 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 110 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 111 | } |
| 112 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 113 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 114 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 115 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 116 | } |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 119 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 120 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 123 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 124 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 125 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 126 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | if (!params) |
| 128 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 129 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 130 | if (!params->GetList("headers", &header_list)) |
| 131 | return false; |
| 132 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 133 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 134 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 139 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 144 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 145 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
| 150 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 152 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 154 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 158 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 159 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 161 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 164 | |
| 165 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 166 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 169 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 171 | load_timing_info.send_start); |
| 172 | |
| 173 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 175 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 177 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 178 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 182 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
| 189 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 191 | load_timing_info.proxy_resolve_end); |
| 192 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 193 | load_timing_info.send_start); |
| 194 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 203 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | int connect_timing_flags) { |
| 206 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | |
| 209 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 211 | load_timing_info.proxy_resolve_end); |
| 212 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 213 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 214 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 215 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 217 | load_timing_info.send_start); |
| 218 | |
| 219 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 221 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 223 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 225 | } |
| 226 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 227 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 228 | headers->SetHeader("Connection", "Upgrade"); |
| 229 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 230 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 231 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 232 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 233 | } |
| 234 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 235 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 236 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 237 | } |
| 238 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 239 | } // namespace |
| 240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 241 | class HttpNetworkTransactionTest |
| 242 | : public PlatformTest, |
| 243 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 245 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 246 | // Important to restore the per-pool limit first, since the pool limit must |
| 247 | // always be greater than group limit, and the tests reduce both limits. |
| 248 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 250 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 251 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 252 | } |
| 253 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 254 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 255 | HttpNetworkTransactionTest() |
| 256 | : spdy_util_(GetParam()), |
| 257 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 258 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 260 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 261 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 262 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 263 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 264 | struct SimpleGetHelperResult { |
| 265 | int rv; |
| 266 | std::string status_line; |
| 267 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 268 | int64_t total_received_bytes; |
| 269 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 270 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 271 | ConnectionAttempts connection_attempts; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 272 | }; |
| 273 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 274 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 275 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 276 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 277 | } |
| 278 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 279 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 280 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 281 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 282 | // Empty the current queue. |
[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 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 285 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 286 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 287 | } |
| 288 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 289 | const char* GetAlternateProtocolFromParam() { |
| 290 | return |
| 291 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 292 | } |
| 293 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 294 | std::string GetAlternativeServiceHttpHeader() { |
| 295 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 296 | "=\"www.example.com:443\"\r\n"; |
| 297 | } |
| 298 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 299 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 300 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 301 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 304 | // Either |write_failure| specifies a write failure or |read_failure| |
| 305 | // specifies a read failure when using a reused socket. In either case, the |
| 306 | // failure should cause the network transaction to resend the request, and the |
| 307 | // other argument should be NULL. |
| 308 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 309 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 310 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 311 | // Either |write_failure| specifies a write failure or |read_failure| |
| 312 | // specifies a read failure when using a reused socket. In either case, the |
| 313 | // failure should cause the network transaction to resend the request, and the |
| 314 | // other argument should be NULL. |
| 315 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 316 | const MockRead* read_failure, |
| 317 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 318 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 319 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 320 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 321 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 322 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | HttpRequestInfo request; |
| 324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 325 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 326 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 327 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 328 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 329 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 331 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 333 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 334 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 335 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 336 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 338 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 339 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 340 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 341 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 342 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 343 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 344 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 345 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 346 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 347 | |
| 348 | // Even in the failure cases that use this function, connections are always |
| 349 | // successfully established before the error. |
| 350 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 351 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 352 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | if (out.rv != OK) |
| 354 | return out; |
| 355 | |
| 356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 357 | // Can't use ASSERT_* inside helper functions like this, so |
| 358 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 359 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 360 | out.rv = ERR_UNEXPECTED; |
| 361 | return out; |
| 362 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 363 | out.status_line = response->headers->GetStatusLine(); |
| 364 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 365 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 366 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 367 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 368 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 369 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 370 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 371 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 372 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 373 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 374 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 375 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 376 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 377 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 378 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 379 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 380 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 381 | std::string line; |
| 382 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 383 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 384 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 385 | HttpRequestHeaders request_headers; |
| 386 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 387 | std::string value; |
| 388 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 389 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 390 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 391 | EXPECT_EQ("keep-alive", value); |
| 392 | |
| 393 | std::string response_headers; |
| 394 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 395 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 396 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 397 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 398 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 399 | // The total number of sent bytes should not have changed. |
| 400 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 401 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 402 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 403 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 404 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 405 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 406 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 407 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 408 | MockWrite data_writes[] = { |
| 409 | MockWrite("GET / HTTP/1.1\r\n" |
| 410 | "Host: www.example.org\r\n" |
| 411 | "Connection: keep-alive\r\n\r\n"), |
| 412 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 413 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 414 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 415 | arraysize(data_writes)); |
| 416 | StaticSocketDataProvider* data[] = {&reads}; |
| 417 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 418 | |
| 419 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 420 | out.total_sent_bytes); |
| 421 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 422 | } |
| 423 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 424 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 425 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 426 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 427 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 428 | |
| 429 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 430 | |
| 431 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 432 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 433 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 434 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 435 | |
| 436 | // Original socket limits. Some tests set these. Safest to always restore |
| 437 | // them once each test has been run. |
| 438 | int old_max_group_sockets_; |
| 439 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 440 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 441 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 442 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 443 | HttpNetworkTransactionTest, |
| 444 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 445 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 446 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 447 | namespace { |
| 448 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 449 | class BeforeNetworkStartHandler { |
| 450 | public: |
| 451 | explicit BeforeNetworkStartHandler(bool defer) |
| 452 | : defer_on_before_network_start_(defer), |
| 453 | observed_before_network_start_(false) {} |
| 454 | |
| 455 | void OnBeforeNetworkStart(bool* defer) { |
| 456 | *defer = defer_on_before_network_start_; |
| 457 | observed_before_network_start_ = true; |
| 458 | } |
| 459 | |
| 460 | bool observed_before_network_start() const { |
| 461 | return observed_before_network_start_; |
| 462 | } |
| 463 | |
| 464 | private: |
| 465 | const bool defer_on_before_network_start_; |
| 466 | bool observed_before_network_start_; |
| 467 | |
| 468 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 469 | }; |
| 470 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 471 | class BeforeProxyHeadersSentHandler { |
| 472 | public: |
| 473 | BeforeProxyHeadersSentHandler() |
| 474 | : observed_before_proxy_headers_sent_(false) {} |
| 475 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 476 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 477 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 478 | observed_before_proxy_headers_sent_ = true; |
| 479 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 480 | } |
| 481 | |
| 482 | bool observed_before_proxy_headers_sent() const { |
| 483 | return observed_before_proxy_headers_sent_; |
| 484 | } |
| 485 | |
| 486 | std::string observed_proxy_server_uri() const { |
| 487 | return observed_proxy_server_uri_; |
| 488 | } |
| 489 | |
| 490 | private: |
| 491 | bool observed_before_proxy_headers_sent_; |
| 492 | std::string observed_proxy_server_uri_; |
| 493 | |
| 494 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 495 | }; |
| 496 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 497 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 498 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 499 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 500 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 501 | const int sizeof_row = strlen(row); |
| 502 | const int num_rows = static_cast<int>( |
| 503 | ceil(static_cast<float>(size) / sizeof_row)); |
| 504 | const int sizeof_data = num_rows * sizeof_row; |
| 505 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 506 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 507 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 508 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 509 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 510 | } |
| 511 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 512 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 513 | // Alternative functions that eliminate randomness and dependency on the local |
| 514 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 515 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 516 | static const uint8 bytes[] = { |
| 517 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 518 | }; |
| 519 | static size_t current_byte = 0; |
| 520 | for (size_t i = 0; i < n; ++i) { |
| 521 | output[i] = bytes[current_byte++]; |
| 522 | current_byte %= arraysize(bytes); |
| 523 | } |
| 524 | } |
| 525 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 526 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 527 | static const uint8 bytes[] = { |
| 528 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 529 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 530 | }; |
| 531 | static size_t current_byte = 0; |
| 532 | for (size_t i = 0; i < n; ++i) { |
| 533 | output[i] = bytes[current_byte++]; |
| 534 | current_byte %= arraysize(bytes); |
| 535 | } |
| 536 | } |
| 537 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 538 | std::string MockGetHostName() { |
| 539 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 540 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 541 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 542 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 543 | template<typename ParentPool> |
| 544 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 545 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 546 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 547 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 548 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 549 | const std::string last_group_name_received() const { |
| 550 | return last_group_name_; |
| 551 | } |
| 552 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 553 | int RequestSocket(const std::string& group_name, |
| 554 | const void* socket_params, |
| 555 | RequestPriority priority, |
| 556 | ClientSocketHandle* handle, |
| 557 | const CompletionCallback& callback, |
| 558 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 559 | last_group_name_ = group_name; |
| 560 | return ERR_IO_PENDING; |
| 561 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 562 | void CancelRequest(const std::string& group_name, |
| 563 | ClientSocketHandle* handle) override {} |
| 564 | void ReleaseSocket(const std::string& group_name, |
| 565 | scoped_ptr<StreamSocket> socket, |
| 566 | int id) override {} |
| 567 | void CloseIdleSockets() override {} |
| 568 | int IdleSocketCount() const override { return 0; } |
| 569 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 570 | return 0; |
| 571 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 572 | LoadState GetLoadState(const std::string& group_name, |
| 573 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 574 | return LOAD_STATE_IDLE; |
| 575 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 576 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 577 | return base::TimeDelta(); |
| 578 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 579 | |
| 580 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 581 | std::string last_group_name_; |
| 582 | }; |
| 583 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 584 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 585 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 586 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 587 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 588 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 589 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 590 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 591 | CaptureGroupNameSSLSocketPool; |
| 592 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 593 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 594 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 595 | HostResolver* host_resolver, |
| 596 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 597 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 598 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 599 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 600 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 601 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 602 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 603 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 604 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 605 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 606 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 607 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 608 | CaptureGroupNameSSLSocketPool::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) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 611 | : SSLClientSocketPool(0, |
| 612 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 613 | cert_verifier, |
| 614 | NULL, |
| 615 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 616 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 617 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 618 | std::string(), |
| 619 | NULL, |
| 620 | NULL, |
| 621 | NULL, |
| 622 | NULL, |
| 623 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 624 | NULL) { |
| 625 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 626 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 627 | //----------------------------------------------------------------------------- |
| 628 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 629 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 630 | // configured for common cases. |
| 631 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 632 | if (!auth_challenge) |
| 633 | return false; |
| 634 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 635 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 636 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 637 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 642 | if (!auth_challenge) |
| 643 | return false; |
| 644 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 645 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 646 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 647 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 652 | if (!auth_challenge) |
| 653 | return false; |
| 654 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 655 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 656 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 657 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 658 | return true; |
| 659 | } |
| 660 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 661 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 662 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 663 | if (!auth_challenge) |
| 664 | return false; |
| 665 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 666 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 667 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 668 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 669 | return true; |
| 670 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 671 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 672 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 673 | } // namespace |
| 674 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 675 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 676 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 677 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 678 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | } |
| 680 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 681 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 682 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 683 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 684 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 686 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 687 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 688 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 689 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 690 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 691 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 692 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 693 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 694 | EXPECT_EQ(0u, out.connection_attempts.size()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 698 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 699 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 700 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 701 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 702 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 703 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 704 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 705 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 706 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 707 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 708 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 709 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 713 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 715 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 717 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 718 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 719 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 720 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 721 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 722 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 723 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 724 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 728 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 730 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 731 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 732 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 733 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 734 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 735 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 736 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 737 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 738 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 739 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // 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] | 743 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 745 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 746 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 747 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 748 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 749 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 750 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 751 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 752 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 753 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 754 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 758 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 760 | MockRead("\n"), |
| 761 | MockRead("\n"), |
| 762 | MockRead("Q"), |
| 763 | MockRead("J"), |
| 764 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 765 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 766 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 767 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 768 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 769 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 770 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 771 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 772 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 773 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 777 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 779 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 780 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 781 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 782 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 783 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 784 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 786 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 787 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 788 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 789 | } |
| 790 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 791 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 792 | // persistent connection. The response should still terminate since a 204 |
| 793 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 794 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 795 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 796 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 797 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 798 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 799 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 800 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 801 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 802 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 803 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 804 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 805 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 806 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 807 | int64_t response_size = reads_size - strlen(junk); |
| 808 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 809 | } |
| 810 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 811 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 812 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 813 | std::string final_chunk = "0\r\n\r\n"; |
| 814 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 815 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 816 | MockRead data_reads[] = { |
| 817 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 818 | MockRead("5\r\nHello\r\n"), |
| 819 | MockRead("1\r\n"), |
| 820 | MockRead(" \r\n"), |
| 821 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 822 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 823 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 824 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 825 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 826 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 827 | EXPECT_EQ(OK, out.rv); |
| 828 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 829 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 830 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 831 | int64_t response_size = reads_size - extra_data.size(); |
| 832 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 833 | } |
| 834 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 835 | // Next tests deal with http://crbug.com/56344. |
| 836 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 837 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 838 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 839 | MockRead data_reads[] = { |
| 840 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 841 | MockRead("Content-Length: 10\r\n"), |
| 842 | MockRead("Content-Length: 5\r\n\r\n"), |
| 843 | }; |
| 844 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 845 | arraysize(data_reads)); |
| 846 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 847 | } |
| 848 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 849 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 850 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 851 | MockRead data_reads[] = { |
| 852 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 853 | MockRead("Content-Length: 5\r\n"), |
| 854 | MockRead("Content-Length: 5\r\n\r\n"), |
| 855 | MockRead("Hello"), |
| 856 | }; |
| 857 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 858 | arraysize(data_reads)); |
| 859 | EXPECT_EQ(OK, out.rv); |
| 860 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 861 | EXPECT_EQ("Hello", out.response_data); |
| 862 | } |
| 863 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 864 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 865 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 866 | // More than 2 dupes. |
| 867 | { |
| 868 | MockRead data_reads[] = { |
| 869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 870 | MockRead("Content-Length: 5\r\n"), |
| 871 | MockRead("Content-Length: 5\r\n"), |
| 872 | MockRead("Content-Length: 5\r\n\r\n"), |
| 873 | MockRead("Hello"), |
| 874 | }; |
| 875 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 876 | arraysize(data_reads)); |
| 877 | EXPECT_EQ(OK, out.rv); |
| 878 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 879 | EXPECT_EQ("Hello", out.response_data); |
| 880 | } |
| 881 | // HTTP/1.0 |
| 882 | { |
| 883 | MockRead data_reads[] = { |
| 884 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 885 | MockRead("Content-Length: 5\r\n"), |
| 886 | MockRead("Content-Length: 5\r\n"), |
| 887 | MockRead("Content-Length: 5\r\n\r\n"), |
| 888 | MockRead("Hello"), |
| 889 | }; |
| 890 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 891 | arraysize(data_reads)); |
| 892 | EXPECT_EQ(OK, out.rv); |
| 893 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 894 | EXPECT_EQ("Hello", out.response_data); |
| 895 | } |
| 896 | // 2 dupes and one mismatched. |
| 897 | { |
| 898 | MockRead data_reads[] = { |
| 899 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 900 | MockRead("Content-Length: 10\r\n"), |
| 901 | MockRead("Content-Length: 10\r\n"), |
| 902 | MockRead("Content-Length: 5\r\n\r\n"), |
| 903 | }; |
| 904 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 905 | arraysize(data_reads)); |
| 906 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 907 | } |
| 908 | } |
| 909 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 910 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 911 | MultipleContentLengthHeadersTransferEncoding) { |
| 912 | MockRead data_reads[] = { |
| 913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 914 | MockRead("Content-Length: 666\r\n"), |
| 915 | MockRead("Content-Length: 1337\r\n"), |
| 916 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 917 | MockRead("5\r\nHello\r\n"), |
| 918 | MockRead("1\r\n"), |
| 919 | MockRead(" \r\n"), |
| 920 | MockRead("5\r\nworld\r\n"), |
| 921 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 922 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 923 | }; |
| 924 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 925 | arraysize(data_reads)); |
| 926 | EXPECT_EQ(OK, out.rv); |
| 927 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 928 | EXPECT_EQ("Hello world", out.response_data); |
| 929 | } |
| 930 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 931 | // Next tests deal with http://crbug.com/98895. |
| 932 | |
| 933 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 934 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 935 | MockRead data_reads[] = { |
| 936 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 937 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 938 | MockRead("Content-Length: 5\r\n\r\n"), |
| 939 | MockRead("Hello"), |
| 940 | }; |
| 941 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 942 | arraysize(data_reads)); |
| 943 | EXPECT_EQ(OK, out.rv); |
| 944 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 945 | EXPECT_EQ("Hello", out.response_data); |
| 946 | } |
| 947 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 948 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 949 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 950 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 951 | MockRead data_reads[] = { |
| 952 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 953 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 954 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 955 | MockRead("Content-Length: 5\r\n\r\n"), |
| 956 | MockRead("Hello"), |
| 957 | }; |
| 958 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 959 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 960 | EXPECT_EQ(OK, out.rv); |
| 961 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 962 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 966 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 967 | MockRead data_reads[] = { |
| 968 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 969 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 970 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 971 | MockRead("Content-Length: 5\r\n\r\n"), |
| 972 | MockRead("Hello"), |
| 973 | }; |
| 974 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 975 | arraysize(data_reads)); |
| 976 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 977 | } |
| 978 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 979 | // Checks that two identical Location headers result in no error. |
| 980 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 981 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 982 | MockRead data_reads[] = { |
| 983 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 984 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 985 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 986 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 987 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 988 | }; |
| 989 | |
| 990 | HttpRequestInfo request; |
| 991 | request.method = "GET"; |
| 992 | request.url = GURL("http://redirect.com/"); |
| 993 | request.load_flags = 0; |
| 994 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 995 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 996 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 998 | |
| 999 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1002 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1004 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1005 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1006 | |
| 1007 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1008 | |
| 1009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1010 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1011 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1012 | std::string url; |
| 1013 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1014 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1015 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1016 | } |
| 1017 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1018 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1019 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1020 | MockRead data_reads[] = { |
| 1021 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1022 | MockRead("Location: http://good.com/\r\n"), |
| 1023 | MockRead("Location: http://evil.com/\r\n"), |
| 1024 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1026 | }; |
| 1027 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1028 | arraysize(data_reads)); |
| 1029 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1030 | } |
| 1031 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1032 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1033 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1034 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1035 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1036 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1037 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1038 | request.load_flags = 0; |
| 1039 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1040 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1041 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1043 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1044 | trans->SetBeforeProxyHeadersSentCallback( |
| 1045 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1046 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1047 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1048 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1049 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1050 | "Host: www.example.org\r\n" |
| 1051 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1052 | }; |
| 1053 | MockRead data_reads1[] = { |
| 1054 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1055 | MockRead("Server: Blah\r\n"), |
| 1056 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1057 | |
| 1058 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1059 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1060 | }; |
| 1061 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1062 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1063 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1064 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1066 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1068 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1070 | |
| 1071 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1072 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1075 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1076 | |
| 1077 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1078 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1079 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1080 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1081 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1082 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1083 | |
| 1084 | std::string server_header; |
| 1085 | void* iter = NULL; |
| 1086 | bool has_server_header = response->headers->EnumerateHeader( |
| 1087 | &iter, "Server", &server_header); |
| 1088 | EXPECT_TRUE(has_server_header); |
| 1089 | EXPECT_EQ("Blah", server_header); |
| 1090 | |
| 1091 | // Reading should give EOF right away, since there is no message body |
| 1092 | // (despite non-zero content-length). |
| 1093 | std::string response_data; |
| 1094 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1095 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1096 | EXPECT_EQ("", response_data); |
| 1097 | } |
| 1098 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1099 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1100 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | |
| 1102 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1103 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1104 | MockRead("hello"), |
| 1105 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1106 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1107 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1109 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1111 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1112 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1113 | "hello", "world" |
| 1114 | }; |
| 1115 | |
| 1116 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1117 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1119 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1120 | request.load_flags = 0; |
| 1121 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1122 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1125 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1127 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1129 | |
| 1130 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1131 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1132 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1134 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1135 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1136 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1137 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1138 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1139 | |
| 1140 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1141 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1142 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1143 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1147 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1148 | ScopedVector<UploadElementReader> element_readers; |
| 1149 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1150 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1151 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1152 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | request.method = "POST"; |
| 1154 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1155 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | request.load_flags = 0; |
| 1157 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1158 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1159 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1160 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1161 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1162 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1163 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1164 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1165 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1166 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1168 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1169 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1171 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1173 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | |
| 1176 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1179 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1180 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1181 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1182 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1183 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1184 | |
| 1185 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1186 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1187 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1188 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1191 | // This test is almost the same as Ignores100 above, but the response contains |
| 1192 | // 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] | 1193 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1194 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1195 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1196 | request.method = "GET"; |
| 1197 | request.url = GURL("http://www.foo.com/"); |
| 1198 | request.load_flags = 0; |
| 1199 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1200 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1201 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1203 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1204 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1205 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1206 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1207 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1208 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1209 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1210 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1211 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1213 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1215 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1216 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1217 | |
| 1218 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1219 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1220 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1221 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1222 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1223 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1224 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1225 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1226 | |
| 1227 | std::string response_data; |
| 1228 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1229 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1230 | EXPECT_EQ("hello world", response_data); |
| 1231 | } |
| 1232 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1233 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1234 | HttpRequestInfo request; |
| 1235 | request.method = "POST"; |
| 1236 | request.url = GURL("http://www.foo.com/"); |
| 1237 | request.load_flags = 0; |
| 1238 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1239 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1240 | scoped_ptr<HttpTransaction> trans( |
| 1241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1242 | |
| 1243 | MockRead data_reads[] = { |
| 1244 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1245 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1246 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1249 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1250 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1251 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1252 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1254 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1255 | rv = callback.WaitForResult(); |
| 1256 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1257 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1258 | std::string response_data; |
| 1259 | rv = ReadTransaction(trans.get(), &response_data); |
| 1260 | EXPECT_EQ(OK, rv); |
| 1261 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1262 | } |
| 1263 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1264 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | HttpRequestInfo request; |
| 1266 | request.method = "POST"; |
| 1267 | request.url = GURL("http://www.foo.com/"); |
| 1268 | request.load_flags = 0; |
| 1269 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1270 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1271 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1273 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1274 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1275 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1276 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1280 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1282 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1283 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1284 | |
| 1285 | rv = callback.WaitForResult(); |
| 1286 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1287 | } |
| 1288 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1289 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1290 | const MockWrite* write_failure, |
| 1291 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1292 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | request.method = "GET"; |
| 1294 | request.url = GURL("http://www.foo.com/"); |
| 1295 | request.load_flags = 0; |
| 1296 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1297 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1298 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1299 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1300 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1301 | // Written data for successfully sending both requests. |
| 1302 | MockWrite data1_writes[] = { |
| 1303 | MockWrite("GET / HTTP/1.1\r\n" |
| 1304 | "Host: www.foo.com\r\n" |
| 1305 | "Connection: keep-alive\r\n\r\n"), |
| 1306 | MockWrite("GET / HTTP/1.1\r\n" |
| 1307 | "Host: www.foo.com\r\n" |
| 1308 | "Connection: keep-alive\r\n\r\n") |
| 1309 | }; |
| 1310 | |
| 1311 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1313 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1314 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1315 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1317 | |
| 1318 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1319 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1320 | data1_writes[1] = *write_failure; |
| 1321 | } else { |
| 1322 | ASSERT_TRUE(read_failure); |
| 1323 | data1_reads[2] = *read_failure; |
| 1324 | } |
| 1325 | |
| 1326 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1327 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1328 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | |
| 1330 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1331 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1332 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1333 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1335 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1336 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1338 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | "hello", "world" |
| 1340 | }; |
| 1341 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1342 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1344 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1346 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1347 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1349 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | |
| 1352 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1353 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1355 | LoadTimingInfo load_timing_info; |
| 1356 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1357 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1358 | if (i == 0) { |
| 1359 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1360 | } else { |
| 1361 | // The second request should be using a new socket. |
| 1362 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1363 | } |
| 1364 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1365 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1366 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1368 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1369 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | |
| 1371 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1372 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1373 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1374 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | } |
| 1376 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1378 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1379 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1380 | const MockRead* read_failure, |
| 1381 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1382 | HttpRequestInfo request; |
| 1383 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1384 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1385 | request.load_flags = 0; |
| 1386 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1387 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1388 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1389 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1390 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1391 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1392 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1393 | if (use_spdy) { |
| 1394 | ssl1.SetNextProto(GetParam()); |
| 1395 | ssl2.SetNextProto(GetParam()); |
| 1396 | } |
| 1397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1399 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1400 | // SPDY versions of the request and response. |
| 1401 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1402 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1403 | scoped_ptr<SpdyFrame> spdy_response( |
| 1404 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1405 | scoped_ptr<SpdyFrame> spdy_data( |
| 1406 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1407 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1408 | // HTTP/1.1 versions of the request and response. |
| 1409 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1410 | "Host: www.foo.com\r\n" |
| 1411 | "Connection: keep-alive\r\n\r\n"; |
| 1412 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1413 | const char kHttpData[] = "hello"; |
| 1414 | |
| 1415 | std::vector<MockRead> data1_reads; |
| 1416 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1417 | if (write_failure) { |
| 1418 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1419 | data1_writes.push_back(*write_failure); |
| 1420 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | } else { |
| 1422 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1423 | if (use_spdy) { |
| 1424 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1425 | } else { |
| 1426 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1427 | } |
| 1428 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1429 | } |
| 1430 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1431 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1432 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1433 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1434 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1435 | std::vector<MockRead> data2_reads; |
| 1436 | std::vector<MockWrite> data2_writes; |
| 1437 | |
| 1438 | if (use_spdy) { |
| 1439 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1440 | |
| 1441 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1442 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1443 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1444 | } else { |
| 1445 | data2_writes.push_back( |
| 1446 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1447 | |
| 1448 | data2_reads.push_back( |
| 1449 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1450 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1451 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1452 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1453 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1454 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1455 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1456 | |
| 1457 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1458 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1459 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1460 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1461 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1462 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1463 | // Wait for the preconnect to complete. |
| 1464 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1465 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1466 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | |
| 1468 | // Make the request. |
| 1469 | TestCompletionCallback callback; |
| 1470 | |
| 1471 | scoped_ptr<HttpTransaction> trans( |
| 1472 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1473 | |
| 1474 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1475 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1476 | |
| 1477 | rv = callback.WaitForResult(); |
| 1478 | EXPECT_EQ(OK, rv); |
| 1479 | |
| 1480 | LoadTimingInfo load_timing_info; |
| 1481 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1482 | TestLoadTimingNotReused( |
| 1483 | load_timing_info, |
| 1484 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1485 | |
| 1486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1487 | ASSERT_TRUE(response != NULL); |
| 1488 | |
| 1489 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1490 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1491 | |
| 1492 | std::string response_data; |
| 1493 | rv = ReadTransaction(trans.get(), &response_data); |
| 1494 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1495 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1496 | } |
| 1497 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1498 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1499 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1500 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1501 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1502 | } |
| 1503 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1504 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1505 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1506 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1507 | } |
| 1508 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1509 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1510 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1511 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1512 | } |
| 1513 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1514 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1515 | // if the socket was a reused keep alive socket. |
| 1516 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1517 | MockRead read_failure(SYNCHRONOUS, |
| 1518 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1519 | "Connection: Keep-Alive\r\n" |
| 1520 | "Content-Length: 6\r\n\r\n" |
| 1521 | "Pickle"); |
| 1522 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1523 | } |
| 1524 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1525 | TEST_P(HttpNetworkTransactionTest, |
| 1526 | PreconnectErrorNotConnectedOnWrite) { |
| 1527 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1528 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1532 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1533 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1537 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1538 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1539 | } |
| 1540 | |
| 1541 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1542 | MockRead read_failure(ASYNC, OK); // EOF |
| 1543 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1544 | } |
| 1545 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1546 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1547 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1548 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1549 | MockRead read_failure(SYNCHRONOUS, |
| 1550 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1551 | "Connection: Keep-Alive\r\n" |
| 1552 | "Content-Length: 6\r\n\r\n" |
| 1553 | "Pickle"); |
| 1554 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1555 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1556 | } |
| 1557 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1558 | TEST_P(HttpNetworkTransactionTest, |
| 1559 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1560 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1561 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1562 | } |
| 1563 | |
| 1564 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1565 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1566 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1567 | } |
| 1568 | |
| 1569 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1570 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1571 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1572 | } |
| 1573 | |
| 1574 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1575 | MockRead read_failure(ASYNC, OK); // EOF |
| 1576 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1577 | } |
| 1578 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1579 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1580 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1582 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1583 | request.load_flags = 0; |
| 1584 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1585 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1586 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1587 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1588 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1589 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1590 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1591 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1592 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1593 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1594 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1595 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1598 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1600 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1601 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1602 | |
| 1603 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1604 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | // What do various browsers do when the server closes a non-keepalive |
| 1608 | // connection without sending any response header or body? |
| 1609 | // |
| 1610 | // IE7: error page |
| 1611 | // Safari 3.1.2 (Windows): error page |
| 1612 | // Firefox 3.0.1: blank page |
| 1613 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1614 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1615 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1616 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1617 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1618 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1619 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1620 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1621 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1622 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1623 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1624 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1625 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1626 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1627 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1628 | // Test that network access can be deferred and resumed. |
| 1629 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1630 | HttpRequestInfo request; |
| 1631 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1632 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1633 | request.load_flags = 0; |
| 1634 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1635 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1636 | scoped_ptr<HttpTransaction> trans( |
| 1637 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1638 | |
| 1639 | // Defer on OnBeforeNetworkStart. |
| 1640 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1641 | trans->SetBeforeNetworkStartCallback( |
| 1642 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1643 | base::Unretained(&net_start_handler))); |
| 1644 | |
| 1645 | MockRead data_reads[] = { |
| 1646 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1647 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1648 | MockRead("hello"), |
| 1649 | MockRead(SYNCHRONOUS, 0), |
| 1650 | }; |
| 1651 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1653 | |
| 1654 | TestCompletionCallback callback; |
| 1655 | |
| 1656 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1657 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1658 | base::MessageLoop::current()->RunUntilIdle(); |
| 1659 | |
| 1660 | // Should have deferred for network start. |
| 1661 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1662 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1663 | |
| 1664 | trans->ResumeNetworkStart(); |
| 1665 | rv = callback.WaitForResult(); |
| 1666 | EXPECT_EQ(OK, rv); |
| 1667 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1668 | |
| 1669 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1670 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1671 | if (rv == ERR_IO_PENDING) |
| 1672 | rv = callback.WaitForResult(); |
| 1673 | EXPECT_EQ(5, rv); |
| 1674 | trans.reset(); |
| 1675 | } |
| 1676 | |
| 1677 | // Test that network use can be deferred and canceled. |
| 1678 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1679 | HttpRequestInfo request; |
| 1680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1681 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1682 | request.load_flags = 0; |
| 1683 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1684 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1685 | scoped_ptr<HttpTransaction> trans( |
| 1686 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1687 | |
| 1688 | // Defer on OnBeforeNetworkStart. |
| 1689 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1690 | trans->SetBeforeNetworkStartCallback( |
| 1691 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1692 | base::Unretained(&net_start_handler))); |
| 1693 | |
| 1694 | TestCompletionCallback callback; |
| 1695 | |
| 1696 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1697 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1698 | base::MessageLoop::current()->RunUntilIdle(); |
| 1699 | |
| 1700 | // Should have deferred for network start. |
| 1701 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1702 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1703 | } |
| 1704 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1705 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1706 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1707 | // destructor in such situations. |
| 1708 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1709 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1710 | HttpRequestInfo request; |
| 1711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1712 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1713 | request.load_flags = 0; |
| 1714 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1715 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1716 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1718 | |
| 1719 | MockRead data_reads[] = { |
| 1720 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1721 | MockRead("Connection: keep-alive\r\n"), |
| 1722 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1723 | MockRead("hello"), |
| 1724 | MockRead(SYNCHRONOUS, 0), |
| 1725 | }; |
| 1726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1727 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1728 | |
| 1729 | TestCompletionCallback callback; |
| 1730 | |
| 1731 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1733 | |
| 1734 | rv = callback.WaitForResult(); |
| 1735 | EXPECT_EQ(OK, rv); |
| 1736 | |
| 1737 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1738 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1739 | if (rv == ERR_IO_PENDING) |
| 1740 | rv = callback.WaitForResult(); |
| 1741 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1742 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1743 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1744 | |
| 1745 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1746 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1747 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1748 | } |
| 1749 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1750 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | HttpRequestInfo request; |
| 1752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1753 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1754 | request.load_flags = 0; |
| 1755 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1756 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1757 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1758 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1759 | |
| 1760 | MockRead data_reads[] = { |
| 1761 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1762 | MockRead("Connection: keep-alive\r\n"), |
| 1763 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1764 | MockRead(SYNCHRONOUS, 0), |
| 1765 | }; |
| 1766 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1768 | |
| 1769 | TestCompletionCallback callback; |
| 1770 | |
| 1771 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1773 | |
| 1774 | rv = callback.WaitForResult(); |
| 1775 | EXPECT_EQ(OK, rv); |
| 1776 | |
| 1777 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1778 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1779 | if (rv == ERR_IO_PENDING) |
| 1780 | rv = callback.WaitForResult(); |
| 1781 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1782 | |
| 1783 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1784 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1785 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1786 | } |
| 1787 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1788 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1789 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1790 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1791 | HttpRequestInfo request; |
| 1792 | request.method = "GET"; |
| 1793 | request.url = GURL("http://www.foo.com/"); |
| 1794 | request.load_flags = 0; |
| 1795 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1796 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1797 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1798 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1799 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1800 | // Note that because all these reads happen in the same |
| 1801 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1802 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1803 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1804 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1805 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1806 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1807 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1808 | "Content-Length: 0\r\n\r\n"), |
| 1809 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1810 | "Content-Length: 5\r\n\r\n" |
| 1811 | "hello"), |
| 1812 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1813 | "Content-Length: 0\r\n\r\n"), |
| 1814 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1815 | "Content-Length: 5\r\n\r\n" |
| 1816 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1817 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1818 | MockRead("hello"), |
| 1819 | }; |
| 1820 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1822 | |
| 1823 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1824 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1825 | }; |
| 1826 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1827 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1828 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1829 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1830 | std::string response_lines[kNumUnreadBodies]; |
| 1831 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1832 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1833 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1834 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1835 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1839 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1840 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1841 | |
| 1842 | rv = callback.WaitForResult(); |
| 1843 | EXPECT_EQ(OK, rv); |
| 1844 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1845 | LoadTimingInfo load_timing_info; |
| 1846 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1847 | if (i == 0) { |
| 1848 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1849 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1850 | } else { |
| 1851 | TestLoadTimingReused(load_timing_info); |
| 1852 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1853 | } |
| 1854 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1855 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1856 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1857 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1858 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1859 | response_lines[i] = response->headers->GetStatusLine(); |
| 1860 | |
| 1861 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1862 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1863 | |
| 1864 | const char* const kStatusLines[] = { |
| 1865 | "HTTP/1.1 204 No Content", |
| 1866 | "HTTP/1.1 205 Reset Content", |
| 1867 | "HTTP/1.1 304 Not Modified", |
| 1868 | "HTTP/1.1 302 Found", |
| 1869 | "HTTP/1.1 302 Found", |
| 1870 | "HTTP/1.1 301 Moved Permanently", |
| 1871 | "HTTP/1.1 301 Moved Permanently", |
| 1872 | }; |
| 1873 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1874 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1875 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1876 | |
| 1877 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1878 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1880 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1881 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1883 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1884 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1885 | rv = callback.WaitForResult(); |
| 1886 | EXPECT_EQ(OK, rv); |
| 1887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1888 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1889 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1890 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1891 | std::string response_data; |
| 1892 | rv = ReadTransaction(trans.get(), &response_data); |
| 1893 | EXPECT_EQ(OK, rv); |
| 1894 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1895 | } |
| 1896 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1897 | // Test the request-challenge-retry sequence for basic auth. |
| 1898 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1899 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1900 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1902 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1903 | request.load_flags = 0; |
| 1904 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1905 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1906 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 1907 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1908 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1909 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1910 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1911 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1912 | MockWrite( |
| 1913 | "GET / HTTP/1.1\r\n" |
| 1914 | "Host: www.example.org\r\n" |
| 1915 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1916 | }; |
| 1917 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1918 | MockRead data_reads1[] = { |
| 1919 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1920 | // Give a couple authenticate options (only the middle one is actually |
| 1921 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1922 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1923 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1924 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1925 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1926 | // Large content-length -- won't matter, as connection will be reset. |
| 1927 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1928 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1929 | }; |
| 1930 | |
| 1931 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1932 | // be issuing -- the final header line contains the credentials. |
| 1933 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1934 | MockWrite( |
| 1935 | "GET / HTTP/1.1\r\n" |
| 1936 | "Host: www.example.org\r\n" |
| 1937 | "Connection: keep-alive\r\n" |
| 1938 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1939 | }; |
| 1940 | |
| 1941 | // Lastly, the server responds with the actual content. |
| 1942 | MockRead data_reads2[] = { |
| 1943 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1944 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1945 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1946 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1947 | }; |
| 1948 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1949 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1950 | data_writes1, arraysize(data_writes1)); |
| 1951 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1952 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1953 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1954 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1956 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1958 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1959 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1960 | |
| 1961 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1962 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1963 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1964 | LoadTimingInfo load_timing_info1; |
| 1965 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1966 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1967 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1968 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 1969 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 1970 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1971 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1972 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1973 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1974 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1975 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1977 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1979 | rv = trans->RestartWithAuth( |
| 1980 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1981 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1982 | |
| 1983 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1984 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1985 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1986 | LoadTimingInfo load_timing_info2; |
| 1987 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1988 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1989 | // The load timing after restart should have a new socket ID, and times after |
| 1990 | // those of the first load timing. |
| 1991 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1992 | load_timing_info2.connect_timing.connect_start); |
| 1993 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1994 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1995 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 1996 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 1997 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1998 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1999 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2000 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2001 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2002 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2003 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2004 | } |
| 2005 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2006 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2007 | HttpRequestInfo request; |
| 2008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2009 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2010 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2011 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2012 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2013 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2014 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2015 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2016 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2017 | MockWrite( |
| 2018 | "GET / HTTP/1.1\r\n" |
| 2019 | "Host: www.example.org\r\n" |
| 2020 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2021 | }; |
| 2022 | |
| 2023 | MockRead data_reads[] = { |
| 2024 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2025 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2026 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2027 | // Large content-length -- won't matter, as connection will be reset. |
| 2028 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2029 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2030 | }; |
| 2031 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2032 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2033 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2034 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2035 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2037 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2038 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2039 | |
| 2040 | rv = callback.WaitForResult(); |
| 2041 | EXPECT_EQ(0, rv); |
| 2042 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2043 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2044 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2045 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2046 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2047 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2049 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2050 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2051 | } |
| 2052 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2053 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2054 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2055 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2056 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2058 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2059 | request.load_flags = 0; |
| 2060 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2061 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2062 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2063 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2064 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2065 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2066 | MockWrite( |
| 2067 | "GET / HTTP/1.1\r\n" |
| 2068 | "Host: www.example.org\r\n" |
| 2069 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2070 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2071 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2072 | // be issuing -- the final header line contains the credentials. |
| 2073 | MockWrite( |
| 2074 | "GET / HTTP/1.1\r\n" |
| 2075 | "Host: www.example.org\r\n" |
| 2076 | "Connection: keep-alive\r\n" |
| 2077 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2078 | }; |
| 2079 | |
| 2080 | MockRead data_reads1[] = { |
| 2081 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2082 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2083 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2084 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2085 | MockRead("Unauthorized\r\n"), |
| 2086 | |
| 2087 | // Lastly, the server responds with the actual content. |
| 2088 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2089 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2090 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2091 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2092 | }; |
| 2093 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2094 | // If there is a regression where we disconnect a Keep-Alive |
| 2095 | // connection during an auth roundtrip, we'll end up reading this. |
| 2096 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2097 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2098 | }; |
| 2099 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2100 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2101 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2102 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2103 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2104 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2105 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2107 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2108 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2109 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2110 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2111 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2113 | |
| 2114 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2115 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2116 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2117 | LoadTimingInfo load_timing_info1; |
| 2118 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2119 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2120 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2122 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2123 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2125 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2127 | rv = trans->RestartWithAuth( |
| 2128 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2129 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2130 | |
| 2131 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2132 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2133 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2134 | LoadTimingInfo load_timing_info2; |
| 2135 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2136 | TestLoadTimingReused(load_timing_info2); |
| 2137 | // The load timing after restart should have the same socket ID, and times |
| 2138 | // those of the first load timing. |
| 2139 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2140 | load_timing_info2.send_start); |
| 2141 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2142 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2143 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2144 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2145 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2146 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2147 | |
| 2148 | std::string response_data; |
| 2149 | rv = ReadTransaction(trans.get(), &response_data); |
| 2150 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2151 | |
| 2152 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2153 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2154 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2155 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2159 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2160 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2161 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2162 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2163 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2164 | request.load_flags = 0; |
| 2165 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2166 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2167 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2168 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2169 | MockWrite( |
| 2170 | "GET / HTTP/1.1\r\n" |
| 2171 | "Host: www.example.org\r\n" |
| 2172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2173 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2174 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2175 | // be issuing -- the final header line contains the credentials. |
| 2176 | MockWrite( |
| 2177 | "GET / HTTP/1.1\r\n" |
| 2178 | "Host: www.example.org\r\n" |
| 2179 | "Connection: keep-alive\r\n" |
| 2180 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2181 | }; |
| 2182 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2183 | MockRead data_reads1[] = { |
| 2184 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2185 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2186 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | |
| 2188 | // Lastly, the server responds with the actual content. |
| 2189 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2190 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2191 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2192 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2193 | }; |
| 2194 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2195 | // An incorrect reconnect would cause this to be read. |
| 2196 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2197 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2198 | }; |
| 2199 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2200 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2201 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2202 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2203 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2204 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2205 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2207 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2208 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2209 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2211 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2212 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2213 | |
| 2214 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2215 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2216 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2217 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2218 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2219 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2221 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2223 | rv = trans->RestartWithAuth( |
| 2224 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2226 | |
| 2227 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2228 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2229 | |
| 2230 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2231 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2232 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2233 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2237 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2238 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2239 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2240 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2241 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2242 | request.load_flags = 0; |
| 2243 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2244 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2245 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2246 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2247 | MockWrite( |
| 2248 | "GET / HTTP/1.1\r\n" |
| 2249 | "Host: www.example.org\r\n" |
| 2250 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2251 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2252 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2253 | // be issuing -- the final header line contains the credentials. |
| 2254 | MockWrite( |
| 2255 | "GET / HTTP/1.1\r\n" |
| 2256 | "Host: www.example.org\r\n" |
| 2257 | "Connection: keep-alive\r\n" |
| 2258 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2259 | }; |
| 2260 | |
| 2261 | // Respond with 5 kb of response body. |
| 2262 | std::string large_body_string("Unauthorized"); |
| 2263 | large_body_string.append(5 * 1024, ' '); |
| 2264 | large_body_string.append("\r\n"); |
| 2265 | |
| 2266 | MockRead data_reads1[] = { |
| 2267 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2268 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2269 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2270 | // 5134 = 12 + 5 * 1024 + 2 |
| 2271 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2272 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | |
| 2274 | // Lastly, the server responds with the actual content. |
| 2275 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2276 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2277 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2278 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2279 | }; |
| 2280 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2281 | // An incorrect reconnect would cause this to be read. |
| 2282 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2283 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2284 | }; |
| 2285 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2286 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2287 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2288 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2289 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2290 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2291 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2293 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2294 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2295 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2296 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2297 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2299 | |
| 2300 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2301 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2302 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2303 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2304 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2305 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2307 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2309 | rv = trans->RestartWithAuth( |
| 2310 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2311 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2312 | |
| 2313 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2314 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2315 | |
| 2316 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2317 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2318 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2319 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2323 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2324 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2325 | HttpRequestInfo request; |
| 2326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2327 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2328 | request.load_flags = 0; |
| 2329 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2331 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2332 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2333 | MockWrite( |
| 2334 | "GET / HTTP/1.1\r\n" |
| 2335 | "Host: www.example.org\r\n" |
| 2336 | "Connection: keep-alive\r\n\r\n"), |
| 2337 | // This simulates the seemingly successful write to a closed connection |
| 2338 | // if the bug is not fixed. |
| 2339 | MockWrite( |
| 2340 | "GET / HTTP/1.1\r\n" |
| 2341 | "Host: www.example.org\r\n" |
| 2342 | "Connection: keep-alive\r\n" |
| 2343 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2344 | }; |
| 2345 | |
| 2346 | MockRead data_reads1[] = { |
| 2347 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2348 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2349 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2350 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2351 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2352 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2353 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2354 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2355 | }; |
| 2356 | |
| 2357 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2358 | // be issuing -- the final header line contains the credentials. |
| 2359 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2360 | MockWrite( |
| 2361 | "GET / HTTP/1.1\r\n" |
| 2362 | "Host: www.example.org\r\n" |
| 2363 | "Connection: keep-alive\r\n" |
| 2364 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2365 | }; |
| 2366 | |
| 2367 | // Lastly, the server responds with the actual content. |
| 2368 | MockRead data_reads2[] = { |
| 2369 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2370 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2371 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2372 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2373 | }; |
| 2374 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2375 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2376 | data_writes1, arraysize(data_writes1)); |
| 2377 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2378 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2379 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2380 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2382 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2383 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2384 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2386 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2387 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2388 | |
| 2389 | rv = callback1.WaitForResult(); |
| 2390 | EXPECT_EQ(OK, rv); |
| 2391 | |
| 2392 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2393 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2394 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2396 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2398 | rv = trans->RestartWithAuth( |
| 2399 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2401 | |
| 2402 | rv = callback2.WaitForResult(); |
| 2403 | EXPECT_EQ(OK, rv); |
| 2404 | |
| 2405 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2406 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2407 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2408 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2409 | } |
| 2410 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2411 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2412 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2413 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2414 | HttpRequestInfo request; |
| 2415 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2416 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2417 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2418 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2419 | |
| 2420 | // Configure against proxy server "myproxy:70". |
| 2421 | session_deps_.proxy_service.reset( |
| 2422 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2423 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2424 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2425 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2426 | |
| 2427 | // Since we have proxy, should try to establish tunnel. |
| 2428 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2429 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2430 | "Host: www.example.org\r\n" |
| 2431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2432 | }; |
| 2433 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2434 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2435 | // connection. |
| 2436 | MockRead data_reads1[] = { |
| 2437 | // No credentials. |
| 2438 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2439 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2440 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2441 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2442 | // Since the first connection couldn't be reused, need to establish another |
| 2443 | // once given credentials. |
| 2444 | MockWrite data_writes2[] = { |
| 2445 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2446 | // be issuing -- the final header line contains the credentials. |
| 2447 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2448 | "Host: www.example.org\r\n" |
| 2449 | "Proxy-Connection: keep-alive\r\n" |
| 2450 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2451 | |
| 2452 | MockWrite("GET / HTTP/1.1\r\n" |
| 2453 | "Host: www.example.org\r\n" |
| 2454 | "Connection: keep-alive\r\n\r\n"), |
| 2455 | }; |
| 2456 | |
| 2457 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2458 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2459 | |
| 2460 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2461 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2462 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2463 | MockRead(SYNCHRONOUS, "hello"), |
| 2464 | }; |
| 2465 | |
| 2466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2467 | data_writes1, arraysize(data_writes1)); |
| 2468 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2469 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2470 | data_writes2, arraysize(data_writes2)); |
| 2471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2472 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2474 | |
| 2475 | TestCompletionCallback callback1; |
| 2476 | |
| 2477 | scoped_ptr<HttpTransaction> trans( |
| 2478 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2479 | |
| 2480 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2482 | |
| 2483 | rv = callback1.WaitForResult(); |
| 2484 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2485 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2486 | log.GetEntries(&entries); |
| 2487 | size_t pos = ExpectLogContainsSomewhere( |
| 2488 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2489 | NetLog::PHASE_NONE); |
| 2490 | ExpectLogContainsSomewhere( |
| 2491 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2492 | NetLog::PHASE_NONE); |
| 2493 | |
| 2494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2495 | ASSERT_TRUE(response != NULL); |
| 2496 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2497 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2498 | EXPECT_EQ(407, response->headers->response_code()); |
| 2499 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2500 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2501 | |
| 2502 | LoadTimingInfo load_timing_info; |
| 2503 | // CONNECT requests and responses are handled at the connect job level, so |
| 2504 | // the transaction does not yet have a connection. |
| 2505 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2506 | |
| 2507 | TestCompletionCallback callback2; |
| 2508 | |
| 2509 | rv = |
| 2510 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2511 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2512 | |
| 2513 | rv = callback2.WaitForResult(); |
| 2514 | EXPECT_EQ(OK, rv); |
| 2515 | |
| 2516 | response = trans->GetResponseInfo(); |
| 2517 | ASSERT_TRUE(response != NULL); |
| 2518 | |
| 2519 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2520 | EXPECT_EQ(200, response->headers->response_code()); |
| 2521 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2522 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2523 | |
| 2524 | // The password prompt info should not be set. |
| 2525 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2526 | |
| 2527 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2528 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2529 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2530 | |
| 2531 | trans.reset(); |
| 2532 | session->CloseAllConnections(); |
| 2533 | } |
| 2534 | |
| 2535 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2536 | // that requires a restart when setting up an SSL tunnel. |
| 2537 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2538 | HttpRequestInfo request; |
| 2539 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2540 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2541 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2542 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2543 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2544 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2545 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2546 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2547 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2548 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2549 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2550 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2551 | // Since we have proxy, should try to establish tunnel. |
| 2552 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2553 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2554 | "Host: www.example.org\r\n" |
| 2555 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2556 | }; |
| 2557 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2558 | // The proxy responds to the connect with a 407, using a non-persistent |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2559 | // connection. |
| 2560 | MockRead data_reads1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2561 | // No credentials. |
| 2562 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2563 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2564 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2565 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2566 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2567 | MockWrite data_writes2[] = { |
| 2568 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2569 | // be issuing -- the final header line contains the credentials. |
| 2570 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2571 | "Host: www.example.org\r\n" |
| 2572 | "Proxy-Connection: keep-alive\r\n" |
| 2573 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2574 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2575 | MockWrite("GET / HTTP/1.1\r\n" |
| 2576 | "Host: www.example.org\r\n" |
| 2577 | "Connection: keep-alive\r\n\r\n"), |
| 2578 | }; |
| 2579 | |
| 2580 | MockRead data_reads2[] = { |
| 2581 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2582 | |
| 2583 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2584 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2585 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2586 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2587 | }; |
| 2588 | |
| 2589 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2590 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2591 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2592 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2593 | data_writes2, arraysize(data_writes2)); |
| 2594 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2595 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2598 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2599 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2600 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2601 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2603 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2605 | |
| 2606 | rv = callback1.WaitForResult(); |
| 2607 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2608 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2609 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2610 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2611 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2612 | NetLog::PHASE_NONE); |
| 2613 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2614 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2615 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2616 | NetLog::PHASE_NONE); |
| 2617 | |
| 2618 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2619 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2620 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2621 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2622 | EXPECT_EQ(407, response->headers->response_code()); |
| 2623 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2624 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2625 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2626 | LoadTimingInfo load_timing_info; |
| 2627 | // CONNECT requests and responses are handled at the connect job level, so |
| 2628 | // the transaction does not yet have a connection. |
| 2629 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2631 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2633 | rv = trans->RestartWithAuth( |
| 2634 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2635 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2636 | |
| 2637 | rv = callback2.WaitForResult(); |
| 2638 | EXPECT_EQ(OK, rv); |
| 2639 | |
| 2640 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2641 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2642 | |
| 2643 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2644 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2645 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2646 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2647 | |
| 2648 | // The password prompt info should not be set. |
| 2649 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2650 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2651 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2652 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2653 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2654 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2655 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2656 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2657 | } |
| 2658 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2659 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2660 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2661 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2662 | HttpRequestInfo request; |
| 2663 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2664 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2665 | // Ensure that proxy authentication is attempted even |
| 2666 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2667 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2668 | |
| 2669 | // Configure against proxy server "myproxy:70". |
| 2670 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2671 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2672 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2673 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2674 | |
| 2675 | scoped_ptr<HttpTransaction> trans( |
| 2676 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2677 | |
| 2678 | // Since we have proxy, should try to establish tunnel. |
| 2679 | MockWrite data_writes1[] = { |
| 2680 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2681 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2682 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2683 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2684 | |
| 2685 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2686 | // be issuing -- the final header line contains the credentials. |
| 2687 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2688 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2689 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2690 | "Proxy-Connection: keep-alive\r\n" |
| 2691 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2692 | }; |
| 2693 | |
| 2694 | // The proxy responds to the connect with a 407, using a persistent |
| 2695 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2696 | MockRead data_reads1[] = { |
| 2697 | // No credentials. |
| 2698 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2699 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2700 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2701 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2702 | MockRead("0123456789"), |
| 2703 | |
| 2704 | // Wrong credentials (wrong password). |
| 2705 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2706 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2707 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2708 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2709 | // No response body because the test stops reading here. |
| 2710 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2711 | }; |
| 2712 | |
| 2713 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2714 | data_writes1, arraysize(data_writes1)); |
| 2715 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2716 | |
| 2717 | TestCompletionCallback callback1; |
| 2718 | |
| 2719 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2720 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2721 | |
| 2722 | rv = callback1.WaitForResult(); |
| 2723 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2724 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2725 | log.GetEntries(&entries); |
| 2726 | size_t pos = ExpectLogContainsSomewhere( |
| 2727 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2728 | NetLog::PHASE_NONE); |
| 2729 | ExpectLogContainsSomewhere( |
| 2730 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2731 | NetLog::PHASE_NONE); |
| 2732 | |
| 2733 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2734 | ASSERT_TRUE(response); |
| 2735 | ASSERT_TRUE(response->headers); |
| 2736 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2737 | EXPECT_EQ(407, response->headers->response_code()); |
| 2738 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2739 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2740 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2741 | |
| 2742 | TestCompletionCallback callback2; |
| 2743 | |
| 2744 | // Wrong password (should be "bar"). |
| 2745 | rv = |
| 2746 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2747 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2748 | |
| 2749 | rv = callback2.WaitForResult(); |
| 2750 | EXPECT_EQ(OK, rv); |
| 2751 | |
| 2752 | response = trans->GetResponseInfo(); |
| 2753 | ASSERT_TRUE(response); |
| 2754 | ASSERT_TRUE(response->headers); |
| 2755 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2756 | EXPECT_EQ(407, response->headers->response_code()); |
| 2757 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2758 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2759 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2760 | |
| 2761 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2762 | // out of scope. |
| 2763 | session->CloseAllConnections(); |
| 2764 | } |
| 2765 | |
| 2766 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2767 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2768 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2769 | HttpRequestInfo request; |
| 2770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2771 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2772 | // Ensure that proxy authentication is attempted even |
| 2773 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2774 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2775 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2777 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2778 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2779 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2780 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2781 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2782 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2783 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2785 | // Since we have proxy, should try to establish tunnel. |
| 2786 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2787 | MockWrite( |
| 2788 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2789 | "Host: www.example.org\r\n" |
| 2790 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2791 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2792 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2793 | // be issuing -- the final header line contains the credentials. |
| 2794 | MockWrite( |
| 2795 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2796 | "Host: www.example.org\r\n" |
| 2797 | "Proxy-Connection: keep-alive\r\n" |
| 2798 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | }; |
| 2800 | |
| 2801 | // The proxy responds to the connect with a 407, using a persistent |
| 2802 | // connection. |
| 2803 | MockRead data_reads1[] = { |
| 2804 | // No credentials. |
| 2805 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2806 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2807 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2808 | MockRead("0123456789"), |
| 2809 | |
| 2810 | // Wrong credentials (wrong password). |
| 2811 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2812 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2813 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2814 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2815 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2816 | }; |
| 2817 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2818 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2819 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2820 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2822 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2824 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2826 | |
| 2827 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2828 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2829 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2830 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2831 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2832 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2833 | NetLog::PHASE_NONE); |
| 2834 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2835 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2836 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2837 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2839 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2840 | ASSERT_TRUE(response); |
| 2841 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2842 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2843 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2844 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2845 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2846 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2848 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2849 | |
| 2850 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2851 | rv = trans->RestartWithAuth( |
| 2852 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2854 | |
| 2855 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2856 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2857 | |
| 2858 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2859 | ASSERT_TRUE(response); |
| 2860 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2861 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2862 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2863 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2864 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2865 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2866 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2867 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2868 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2869 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2870 | } |
| 2871 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2872 | // Test the case a proxy closes a socket while the challenge body is being |
| 2873 | // drained. |
| 2874 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 2875 | HttpRequestInfo request; |
| 2876 | request.method = "GET"; |
| 2877 | request.url = GURL("https://www.example.org/"); |
| 2878 | // Ensure that proxy authentication is attempted even |
| 2879 | // when the no authentication data flag is set. |
| 2880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2881 | |
| 2882 | // Configure against proxy server "myproxy:70". |
| 2883 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2884 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2885 | |
| 2886 | scoped_ptr<HttpTransaction> trans( |
| 2887 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2888 | |
| 2889 | // Since we have proxy, should try to establish tunnel. |
| 2890 | MockWrite data_writes1[] = { |
| 2891 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2892 | "Host: www.example.org\r\n" |
| 2893 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2894 | }; |
| 2895 | |
| 2896 | // The proxy responds to the connect with a 407, using a persistent |
| 2897 | // connection. |
| 2898 | MockRead data_reads1[] = { |
| 2899 | // No credentials. |
| 2900 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2901 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2902 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 2903 | // Server hands up in the middle of the body. |
| 2904 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 2905 | }; |
| 2906 | |
| 2907 | MockWrite data_writes2[] = { |
| 2908 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2909 | // be issuing -- the final header line contains the credentials. |
| 2910 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2911 | "Host: www.example.org\r\n" |
| 2912 | "Proxy-Connection: keep-alive\r\n" |
| 2913 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2914 | |
| 2915 | MockWrite("GET / HTTP/1.1\r\n" |
| 2916 | "Host: www.example.org\r\n" |
| 2917 | "Connection: keep-alive\r\n\r\n"), |
| 2918 | }; |
| 2919 | |
| 2920 | MockRead data_reads2[] = { |
| 2921 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2922 | |
| 2923 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2924 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2925 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2926 | MockRead(SYNCHRONOUS, "hello"), |
| 2927 | }; |
| 2928 | |
| 2929 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2930 | data_writes1, arraysize(data_writes1)); |
| 2931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2932 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2933 | data_writes2, arraysize(data_writes2)); |
| 2934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2935 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2937 | |
| 2938 | TestCompletionCallback callback; |
| 2939 | |
| 2940 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2941 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2942 | |
| 2943 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2944 | ASSERT_TRUE(response); |
| 2945 | ASSERT_TRUE(response->headers); |
| 2946 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2947 | EXPECT_EQ(407, response->headers->response_code()); |
| 2948 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2949 | |
| 2950 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 2951 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2952 | |
| 2953 | response = trans->GetResponseInfo(); |
| 2954 | ASSERT_TRUE(response); |
| 2955 | ASSERT_TRUE(response->headers); |
| 2956 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2957 | EXPECT_EQ(200, response->headers->response_code()); |
| 2958 | std::string body; |
| 2959 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 2960 | EXPECT_EQ("hello", body); |
| 2961 | } |
| 2962 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2963 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2964 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2965 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2966 | HttpRequestInfo request; |
| 2967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2968 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2969 | request.load_flags = 0; |
| 2970 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2971 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2972 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2973 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 2974 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2975 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2976 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2978 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2979 | // Since we have proxy, should try to establish tunnel. |
| 2980 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2981 | MockWrite( |
| 2982 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2983 | "Host: www.example.org\r\n" |
| 2984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2985 | }; |
| 2986 | |
| 2987 | // The proxy responds to the connect with a 407. |
| 2988 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2989 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2990 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2991 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2992 | MockRead("0123456789"), // Should not be reached. |
| 2993 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2994 | }; |
| 2995 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2996 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2997 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3000 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3004 | |
| 3005 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3006 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3007 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3008 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3009 | ASSERT_TRUE(response); |
| 3010 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3011 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3012 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3013 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3014 | |
| 3015 | std::string response_data; |
| 3016 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3017 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3018 | |
| 3019 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3020 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3021 | } |
| 3022 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3023 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3024 | // caller when the proxy responds to CONNECT with 407. |
| 3025 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3026 | HttpRequestInfo request; |
| 3027 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3028 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3029 | request.load_flags = 0; |
| 3030 | |
| 3031 | // Configure against proxy server "myproxy:70". |
| 3032 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 3033 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3034 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3035 | |
| 3036 | scoped_ptr<HttpTransaction> trans( |
| 3037 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3038 | |
| 3039 | // Since we have proxy, should try to establish tunnel. |
| 3040 | MockWrite data_writes[] = { |
| 3041 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3042 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3043 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3044 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3045 | }; |
| 3046 | |
| 3047 | // The proxy responds to the connect with a 407. |
| 3048 | MockRead data_reads[] = { |
| 3049 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3050 | MockRead("X-Foo: bar\r\n"), |
| 3051 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3052 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3053 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3054 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3055 | }; |
| 3056 | |
| 3057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3058 | arraysize(data_writes)); |
| 3059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3060 | |
| 3061 | TestCompletionCallback callback; |
| 3062 | |
| 3063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3064 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3065 | |
| 3066 | rv = callback.WaitForResult(); |
| 3067 | EXPECT_EQ(OK, rv); |
| 3068 | |
| 3069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3070 | ASSERT_TRUE(response); |
| 3071 | ASSERT_TRUE(response->headers); |
| 3072 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3073 | EXPECT_EQ(407, response->headers->response_code()); |
| 3074 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3075 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3076 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3077 | |
| 3078 | std::string response_data; |
| 3079 | rv = ReadTransaction(trans.get(), &response_data); |
| 3080 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3081 | |
| 3082 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3083 | session->CloseAllConnections(); |
| 3084 | } |
| 3085 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3086 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3087 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3088 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3089 | HttpRequestInfo request; |
| 3090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3091 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3092 | request.load_flags = 0; |
| 3093 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3094 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3095 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3096 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3098 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3099 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3100 | MockWrite( |
| 3101 | "GET / HTTP/1.1\r\n" |
| 3102 | "Host: www.example.org\r\n" |
| 3103 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3104 | }; |
| 3105 | |
| 3106 | MockRead data_reads1[] = { |
| 3107 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3108 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3109 | // Large content-length -- won't matter, as connection will be reset. |
| 3110 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3111 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3112 | }; |
| 3113 | |
| 3114 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3115 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3118 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3120 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3122 | |
| 3123 | rv = callback.WaitForResult(); |
| 3124 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3125 | } |
| 3126 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3127 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3128 | // through a non-authenticating proxy. The request should fail with |
| 3129 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3130 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3131 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3132 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3133 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3134 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3135 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3136 | HttpRequestInfo request; |
| 3137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3138 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3139 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3140 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3141 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3142 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3143 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3144 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3145 | // Since we have proxy, should try to establish tunnel. |
| 3146 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3147 | MockWrite( |
| 3148 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3149 | "Host: www.example.org\r\n" |
| 3150 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3151 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3152 | MockWrite( |
| 3153 | "GET / HTTP/1.1\r\n" |
| 3154 | "Host: www.example.org\r\n" |
| 3155 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3156 | }; |
| 3157 | |
| 3158 | MockRead data_reads1[] = { |
| 3159 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3160 | |
| 3161 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3162 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3163 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3165 | }; |
| 3166 | |
| 3167 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3168 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3170 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3173 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3174 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3175 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3178 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3180 | |
| 3181 | rv = callback1.WaitForResult(); |
| 3182 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3183 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3184 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3185 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3186 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3187 | NetLog::PHASE_NONE); |
| 3188 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3189 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3190 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3191 | NetLog::PHASE_NONE); |
| 3192 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3193 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3194 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3195 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3196 | HttpRequestInfo request1; |
| 3197 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3198 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3199 | |
| 3200 | HttpRequestInfo request2; |
| 3201 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3202 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3203 | |
| 3204 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3205 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3206 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3207 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3208 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3209 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3210 | |
| 3211 | // Since we have proxy, should try to establish tunnel. |
| 3212 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3213 | MockWrite( |
| 3214 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3215 | "Host: www.example.org\r\n" |
| 3216 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3217 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3218 | MockWrite( |
| 3219 | "GET /1 HTTP/1.1\r\n" |
| 3220 | "Host: www.example.org\r\n" |
| 3221 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3222 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3223 | MockWrite( |
| 3224 | "GET /2 HTTP/1.1\r\n" |
| 3225 | "Host: www.example.org\r\n" |
| 3226 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3227 | }; |
| 3228 | |
| 3229 | // The proxy responds to the connect with a 407, using a persistent |
| 3230 | // connection. |
| 3231 | MockRead data_reads1[] = { |
| 3232 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3233 | |
| 3234 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3235 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3236 | MockRead(SYNCHRONOUS, "1"), |
| 3237 | |
| 3238 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3239 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3240 | MockRead(SYNCHRONOUS, "22"), |
| 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3246 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3248 | |
| 3249 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3250 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3252 | |
| 3253 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3255 | |
| 3256 | rv = callback1.WaitForResult(); |
| 3257 | EXPECT_EQ(OK, rv); |
| 3258 | |
| 3259 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3260 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3261 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3262 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3263 | |
| 3264 | LoadTimingInfo load_timing_info1; |
| 3265 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3266 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3267 | |
| 3268 | trans1.reset(); |
| 3269 | |
| 3270 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3271 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3273 | |
| 3274 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3276 | |
| 3277 | rv = callback2.WaitForResult(); |
| 3278 | EXPECT_EQ(OK, rv); |
| 3279 | |
| 3280 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3281 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3282 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3283 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3284 | |
| 3285 | LoadTimingInfo load_timing_info2; |
| 3286 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3287 | TestLoadTimingReused(load_timing_info2); |
| 3288 | |
| 3289 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3290 | |
| 3291 | trans2.reset(); |
| 3292 | session->CloseAllConnections(); |
| 3293 | } |
| 3294 | |
| 3295 | // 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] | 3296 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3297 | HttpRequestInfo request1; |
| 3298 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3299 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3300 | |
| 3301 | HttpRequestInfo request2; |
| 3302 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3303 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3304 | |
| 3305 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3306 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3307 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3308 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3309 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3310 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3311 | |
| 3312 | // Since we have proxy, should try to establish tunnel. |
| 3313 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3314 | MockWrite( |
| 3315 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3316 | "Host: www.example.org\r\n" |
| 3317 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3318 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3319 | MockWrite( |
| 3320 | "GET /1 HTTP/1.1\r\n" |
| 3321 | "Host: www.example.org\r\n" |
| 3322 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3323 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3324 | MockWrite( |
| 3325 | "GET /2 HTTP/1.1\r\n" |
| 3326 | "Host: www.example.org\r\n" |
| 3327 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3328 | }; |
| 3329 | |
| 3330 | // The proxy responds to the connect with a 407, using a persistent |
| 3331 | // connection. |
| 3332 | MockRead data_reads1[] = { |
| 3333 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3334 | |
| 3335 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3336 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3337 | MockRead(SYNCHRONOUS, "1"), |
| 3338 | |
| 3339 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3340 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3341 | MockRead(SYNCHRONOUS, "22"), |
| 3342 | }; |
| 3343 | |
| 3344 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3345 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3346 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3347 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3349 | |
| 3350 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3351 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3352 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3353 | |
| 3354 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3355 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3356 | |
| 3357 | rv = callback1.WaitForResult(); |
| 3358 | EXPECT_EQ(OK, rv); |
| 3359 | |
| 3360 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3361 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3362 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3363 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3364 | |
| 3365 | LoadTimingInfo load_timing_info1; |
| 3366 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3367 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3368 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3369 | |
| 3370 | trans1.reset(); |
| 3371 | |
| 3372 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3373 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3375 | |
| 3376 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3378 | |
| 3379 | rv = callback2.WaitForResult(); |
| 3380 | EXPECT_EQ(OK, rv); |
| 3381 | |
| 3382 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3383 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3384 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3385 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3386 | |
| 3387 | LoadTimingInfo load_timing_info2; |
| 3388 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3389 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3390 | |
| 3391 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3392 | |
| 3393 | trans2.reset(); |
| 3394 | session->CloseAllConnections(); |
| 3395 | } |
| 3396 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3397 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3398 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3399 | HttpRequestInfo request; |
| 3400 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3401 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3402 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3403 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3404 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3405 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3406 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3407 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3408 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3409 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3410 | // Since we have proxy, should use full url |
| 3411 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3412 | MockWrite( |
| 3413 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3414 | "Host: www.example.org\r\n" |
| 3415 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3416 | }; |
| 3417 | |
| 3418 | MockRead data_reads1[] = { |
| 3419 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3421 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3423 | }; |
| 3424 | |
| 3425 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3426 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3428 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3431 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3432 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3433 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3434 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3436 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3438 | |
| 3439 | rv = callback1.WaitForResult(); |
| 3440 | EXPECT_EQ(OK, rv); |
| 3441 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3442 | LoadTimingInfo load_timing_info; |
| 3443 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3444 | TestLoadTimingNotReused(load_timing_info, |
| 3445 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3446 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3448 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3449 | |
| 3450 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3451 | EXPECT_EQ(200, response->headers->response_code()); |
| 3452 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3453 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3454 | |
| 3455 | // The password prompt info should not be set. |
| 3456 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3457 | } |
| 3458 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3459 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3460 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3461 | HttpRequestInfo request; |
| 3462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3463 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3464 | request.load_flags = 0; |
| 3465 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3466 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3467 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3468 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3469 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3470 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3471 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3472 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3473 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3474 | scoped_ptr<SpdyFrame> req( |
| 3475 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3476 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3477 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3478 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3479 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3480 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3481 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3482 | }; |
| 3483 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3484 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3485 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3486 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3487 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3488 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3489 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3492 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3493 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3494 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3495 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3497 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3499 | |
| 3500 | rv = callback1.WaitForResult(); |
| 3501 | EXPECT_EQ(OK, rv); |
| 3502 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3503 | LoadTimingInfo load_timing_info; |
| 3504 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3505 | TestLoadTimingNotReused(load_timing_info, |
| 3506 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3507 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3508 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3509 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3510 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3511 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3512 | |
| 3513 | std::string response_data; |
| 3514 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3515 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3516 | } |
| 3517 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3518 | // Verifies that a session which races and wins against the owning transaction |
| 3519 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3520 | // Regression test for crbug.com/334413. |
| 3521 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3522 | HttpRequestInfo request; |
| 3523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3524 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3525 | request.load_flags = 0; |
| 3526 | |
| 3527 | // Configure SPDY proxy server "proxy:70". |
| 3528 | session_deps_.proxy_service.reset( |
| 3529 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3530 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3531 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3532 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3533 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3534 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3535 | scoped_ptr<SpdyFrame> req( |
| 3536 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3537 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3538 | |
| 3539 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3540 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3541 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3542 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3543 | }; |
| 3544 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3545 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3546 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3547 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3548 | |
| 3549 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3550 | ssl.SetNextProto(GetParam()); |
| 3551 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3552 | |
| 3553 | TestCompletionCallback callback1; |
| 3554 | |
| 3555 | scoped_ptr<HttpTransaction> trans( |
| 3556 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3557 | |
| 3558 | // Stall the hostname resolution begun by the transaction. |
| 3559 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3560 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3561 | |
| 3562 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3563 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3564 | |
| 3565 | // Race a session to the proxy, which completes first. |
| 3566 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3567 | SpdySessionKey key( |
| 3568 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3569 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3570 | CreateSecureSpdySession(session, key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3571 | |
| 3572 | // Unstall the resolution begun by the transaction. |
| 3573 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3574 | session_deps_.host_resolver->ResolveAllPending(); |
| 3575 | |
| 3576 | EXPECT_FALSE(callback1.have_result()); |
| 3577 | rv = callback1.WaitForResult(); |
| 3578 | EXPECT_EQ(OK, rv); |
| 3579 | |
| 3580 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3581 | ASSERT_TRUE(response != NULL); |
| 3582 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3583 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3584 | |
| 3585 | std::string response_data; |
| 3586 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3587 | EXPECT_EQ(kUploadData, response_data); |
| 3588 | } |
| 3589 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3590 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3591 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3592 | HttpRequestInfo request; |
| 3593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3594 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3595 | request.load_flags = 0; |
| 3596 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3597 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3598 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3599 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3600 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3601 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3602 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3603 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3604 | // The first request will be a bare GET, the second request will be a |
| 3605 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3606 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3607 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3608 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3609 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3610 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3611 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3612 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3613 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3614 | false, |
| 3615 | 3, |
| 3616 | LOWEST, |
| 3617 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3618 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3619 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3620 | }; |
| 3621 | |
| 3622 | // The first response is a 407 proxy authentication challenge, and the second |
| 3623 | // response will be a 200 response since the second request includes a valid |
| 3624 | // Authorization header. |
| 3625 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3626 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3627 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3628 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3629 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3630 | "407 Proxy Authentication Required", |
| 3631 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3632 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3633 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3634 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3635 | scoped_ptr<SpdyFrame> resp_data( |
| 3636 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3637 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3638 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3639 | CreateMockRead(*resp_authentication, 1), |
| 3640 | CreateMockRead(*body_authentication, 2), |
| 3641 | CreateMockRead(*resp_data, 4), |
| 3642 | CreateMockRead(*body_data, 5), |
| 3643 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3644 | }; |
| 3645 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3646 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3647 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3648 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3649 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3650 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3651 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3652 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3654 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3655 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3656 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3659 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3660 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3661 | |
| 3662 | rv = callback1.WaitForResult(); |
| 3663 | EXPECT_EQ(OK, rv); |
| 3664 | |
| 3665 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3666 | |
| 3667 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3668 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3669 | EXPECT_EQ(407, response->headers->response_code()); |
| 3670 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3671 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3673 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3675 | rv = trans->RestartWithAuth( |
| 3676 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3677 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3678 | |
| 3679 | rv = callback2.WaitForResult(); |
| 3680 | EXPECT_EQ(OK, rv); |
| 3681 | |
| 3682 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3683 | |
| 3684 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3685 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3686 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3687 | // The password prompt info should not be set. |
| 3688 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3689 | } |
| 3690 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3691 | // 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] | 3692 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3693 | HttpRequestInfo request; |
| 3694 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3695 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3696 | request.load_flags = 0; |
| 3697 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3698 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3699 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3700 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3701 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3702 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3703 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3704 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3705 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3707 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3708 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3709 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3710 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3711 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3712 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3713 | const char get[] = |
| 3714 | "GET / HTTP/1.1\r\n" |
| 3715 | "Host: www.example.org\r\n" |
| 3716 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3717 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3718 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3719 | scoped_ptr<SpdyFrame> conn_resp( |
| 3720 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3721 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3722 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3723 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3724 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3725 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3726 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3727 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3728 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3729 | |
| 3730 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3731 | CreateMockWrite(*connect, 0), |
| 3732 | CreateMockWrite(*wrapped_get, 2), |
| 3733 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3734 | }; |
| 3735 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3736 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3737 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3738 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3739 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3740 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3741 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3742 | }; |
| 3743 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3744 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3745 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3746 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3747 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3748 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3749 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3751 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3754 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3756 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3757 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3758 | |
| 3759 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3760 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3761 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3762 | LoadTimingInfo load_timing_info; |
| 3763 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3764 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3765 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3766 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3767 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3768 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3769 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3770 | |
| 3771 | std::string response_data; |
| 3772 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3773 | EXPECT_EQ("1234567890", response_data); |
| 3774 | } |
| 3775 | |
| 3776 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3777 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3778 | HttpRequestInfo request; |
| 3779 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3780 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3781 | request.load_flags = 0; |
| 3782 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3783 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3784 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3785 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3786 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3787 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3788 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3789 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3790 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3792 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3793 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3794 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3795 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3796 | // fetch https://www.example.org/ via SPDY |
| 3797 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3798 | scoped_ptr<SpdyFrame> get( |
| 3799 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3800 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3801 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3802 | scoped_ptr<SpdyFrame> conn_resp( |
| 3803 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3804 | scoped_ptr<SpdyFrame> get_resp( |
| 3805 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3806 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3807 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3808 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3809 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3810 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3811 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3812 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3813 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3814 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3815 | |
| 3816 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3817 | CreateMockWrite(*connect, 0), |
| 3818 | CreateMockWrite(*wrapped_get, 2), |
| 3819 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3820 | CreateMockWrite(*window_update_body, 7), |
| 3821 | }; |
| 3822 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3823 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3824 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3825 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3826 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3827 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3828 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3829 | }; |
| 3830 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3831 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3832 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3833 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3834 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3835 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3836 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3838 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3839 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3840 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3842 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3844 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3846 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3847 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3848 | base::MessageLoop::current()->RunUntilIdle(); |
| 3849 | // Now allow the read of the response to complete. |
| 3850 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3851 | rv = callback1.WaitForResult(); |
| 3852 | EXPECT_EQ(OK, rv); |
| 3853 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3854 | LoadTimingInfo load_timing_info; |
| 3855 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3856 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3857 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3858 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3859 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3860 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3861 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3862 | |
| 3863 | std::string response_data; |
| 3864 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3865 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3869 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3870 | HttpRequestInfo request; |
| 3871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3872 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3873 | request.load_flags = 0; |
| 3874 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3875 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3876 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3877 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3878 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3879 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3881 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3882 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3883 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3884 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3885 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3886 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3887 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3888 | scoped_ptr<SpdyFrame> get( |
| 3889 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3890 | |
| 3891 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3892 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3893 | }; |
| 3894 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3895 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3896 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3897 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3898 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3899 | }; |
| 3900 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3901 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3902 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3903 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3904 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3905 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3906 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3908 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3909 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3911 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3912 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3914 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3915 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3916 | |
| 3917 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3918 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3919 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3920 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3921 | } |
| 3922 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3923 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3924 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3925 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3926 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3927 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3928 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3929 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3930 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3931 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 3932 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3933 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3934 | |
| 3935 | HttpRequestInfo request1; |
| 3936 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3937 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3938 | request1.load_flags = 0; |
| 3939 | |
| 3940 | HttpRequestInfo request2; |
| 3941 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3942 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3943 | request2.load_flags = 0; |
| 3944 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3945 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3946 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3947 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3948 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3949 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3950 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3951 | // Fetch https://www.example.org/ via HTTP. |
| 3952 | const char get1[] = |
| 3953 | "GET / HTTP/1.1\r\n" |
| 3954 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3955 | "Connection: keep-alive\r\n\r\n"; |
| 3956 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3957 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3958 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3959 | "Content-Length: 1\r\n\r\n"; |
| 3960 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3961 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3962 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3963 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3964 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3965 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3966 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3967 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3968 | SpdyHeaderBlock connect2_block; |
| 3969 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 3970 | if (GetParam() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3971 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 3972 | } else { |
| 3973 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
| 3974 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
| 3975 | } |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3976 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3977 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3978 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3979 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3980 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3981 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3982 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3983 | // Fetch https://mail.example.org/ via HTTP. |
| 3984 | const char get2[] = |
| 3985 | "GET / HTTP/1.1\r\n" |
| 3986 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3987 | "Connection: keep-alive\r\n\r\n"; |
| 3988 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3989 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3990 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3991 | "Content-Length: 2\r\n\r\n"; |
| 3992 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3993 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3994 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3995 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3996 | |
| 3997 | MockWrite spdy_writes[] = { |
| 3998 | CreateMockWrite(*connect1, 0), |
| 3999 | CreateMockWrite(*wrapped_get1, 2), |
| 4000 | CreateMockWrite(*connect2, 5), |
| 4001 | CreateMockWrite(*wrapped_get2, 7), |
| 4002 | }; |
| 4003 | |
| 4004 | MockRead spdy_reads[] = { |
| 4005 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4006 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4007 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4008 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4009 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4010 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4011 | MockRead(ASYNC, 0, 10), |
| 4012 | }; |
| 4013 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4014 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4015 | arraysize(spdy_writes)); |
| 4016 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4017 | |
| 4018 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4019 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4021 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4023 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4025 | |
| 4026 | TestCompletionCallback callback; |
| 4027 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4028 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4030 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4031 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4032 | |
| 4033 | LoadTimingInfo load_timing_info; |
| 4034 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4035 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4036 | |
| 4037 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4038 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4039 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4040 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4041 | |
| 4042 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4043 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4044 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4045 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4046 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4047 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4049 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4050 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4051 | |
| 4052 | LoadTimingInfo load_timing_info2; |
| 4053 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4054 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4055 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4056 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4057 | |
| 4058 | // The requests should have different IDs, since they each are using their own |
| 4059 | // separate stream. |
| 4060 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4061 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4062 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4063 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4067 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4068 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4069 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4070 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4071 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4072 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4073 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4074 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4075 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4076 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4077 | |
| 4078 | HttpRequestInfo request1; |
| 4079 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4080 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4081 | request1.load_flags = 0; |
| 4082 | |
| 4083 | HttpRequestInfo request2; |
| 4084 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4085 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4086 | request2.load_flags = 0; |
| 4087 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4088 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4089 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4090 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4091 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4092 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4093 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4094 | // Fetch https://www.example.org/ via HTTP. |
| 4095 | const char get1[] = |
| 4096 | "GET / HTTP/1.1\r\n" |
| 4097 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4098 | "Connection: keep-alive\r\n\r\n"; |
| 4099 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4100 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4101 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4102 | "Content-Length: 1\r\n\r\n"; |
| 4103 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4104 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4105 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4106 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4107 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4108 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4109 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4110 | // Fetch https://www.example.org/2 via HTTP. |
| 4111 | const char get2[] = |
| 4112 | "GET /2 HTTP/1.1\r\n" |
| 4113 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4114 | "Connection: keep-alive\r\n\r\n"; |
| 4115 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4116 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4117 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4118 | "Content-Length: 2\r\n\r\n"; |
| 4119 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4120 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4121 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4122 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4123 | |
| 4124 | MockWrite spdy_writes[] = { |
| 4125 | CreateMockWrite(*connect1, 0), |
| 4126 | CreateMockWrite(*wrapped_get1, 2), |
| 4127 | CreateMockWrite(*wrapped_get2, 5), |
| 4128 | }; |
| 4129 | |
| 4130 | MockRead spdy_reads[] = { |
| 4131 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4132 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4133 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4134 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4135 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4136 | MockRead(ASYNC, 0, 8), |
| 4137 | }; |
| 4138 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4139 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4140 | arraysize(spdy_writes)); |
| 4141 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4142 | |
| 4143 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4144 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4146 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4148 | |
| 4149 | TestCompletionCallback callback; |
| 4150 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4151 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4153 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4155 | |
| 4156 | rv = callback.WaitForResult(); |
| 4157 | EXPECT_EQ(OK, rv); |
| 4158 | |
| 4159 | LoadTimingInfo load_timing_info; |
| 4160 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4161 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4162 | |
| 4163 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4164 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4165 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4166 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4167 | |
| 4168 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4169 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4170 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4171 | trans.reset(); |
| 4172 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4173 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4174 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4175 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4176 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4177 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4178 | rv = callback.WaitForResult(); |
| 4179 | EXPECT_EQ(OK, rv); |
| 4180 | |
| 4181 | LoadTimingInfo load_timing_info2; |
| 4182 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4183 | TestLoadTimingReused(load_timing_info2); |
| 4184 | |
| 4185 | // The requests should have the same ID. |
| 4186 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4187 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4188 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4192 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4193 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4194 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4195 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4196 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4197 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4198 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4199 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4200 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4201 | |
| 4202 | HttpRequestInfo request1; |
| 4203 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4204 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4205 | request1.load_flags = 0; |
| 4206 | |
| 4207 | HttpRequestInfo request2; |
| 4208 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4209 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4210 | request2.load_flags = 0; |
| 4211 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4212 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4213 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4214 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4215 | scoped_ptr<SpdyFrame> get1( |
| 4216 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4217 | scoped_ptr<SpdyFrame> get_resp1( |
| 4218 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4219 | scoped_ptr<SpdyFrame> body1( |
| 4220 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4221 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4222 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4223 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4224 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4225 | scoped_ptr<SpdyFrame> get2( |
| 4226 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4227 | scoped_ptr<SpdyFrame> get_resp2( |
| 4228 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4229 | scoped_ptr<SpdyFrame> body2( |
| 4230 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4231 | |
| 4232 | MockWrite spdy_writes[] = { |
| 4233 | CreateMockWrite(*get1, 0), |
| 4234 | CreateMockWrite(*get2, 3), |
| 4235 | }; |
| 4236 | |
| 4237 | MockRead spdy_reads[] = { |
| 4238 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4239 | CreateMockRead(*body1, 2, ASYNC), |
| 4240 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4241 | CreateMockRead(*body2, 5, ASYNC), |
| 4242 | MockRead(ASYNC, 0, 6), |
| 4243 | }; |
| 4244 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4245 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4246 | arraysize(spdy_writes)); |
| 4247 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4248 | |
| 4249 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4250 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4252 | |
| 4253 | TestCompletionCallback callback; |
| 4254 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4255 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4256 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4257 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4258 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4259 | |
| 4260 | LoadTimingInfo load_timing_info; |
| 4261 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4262 | TestLoadTimingNotReused(load_timing_info, |
| 4263 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4264 | |
| 4265 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4266 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4267 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4268 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4269 | |
| 4270 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4271 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4272 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4273 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4274 | // Delete the first request, so the second one can reuse the socket. |
| 4275 | trans.reset(); |
| 4276 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4277 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4279 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4280 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4281 | |
| 4282 | LoadTimingInfo load_timing_info2; |
| 4283 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4284 | TestLoadTimingReused(load_timing_info2); |
| 4285 | |
| 4286 | // The requests should have the same ID. |
| 4287 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4288 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4289 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4290 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4291 | } |
| 4292 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4293 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4294 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4295 | HttpRequestInfo request; |
| 4296 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4297 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4298 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4299 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4300 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4301 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4302 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4303 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4304 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4305 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4306 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4307 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4308 | // Since we have proxy, should use full url |
| 4309 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4310 | MockWrite( |
| 4311 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4312 | "Host: www.example.org\r\n" |
| 4313 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4314 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4315 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4316 | // be issuing -- the final header line contains the credentials. |
| 4317 | MockWrite( |
| 4318 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4319 | "Host: www.example.org\r\n" |
| 4320 | "Proxy-Connection: keep-alive\r\n" |
| 4321 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4322 | }; |
| 4323 | |
| 4324 | // The proxy responds to the GET with a 407, using a persistent |
| 4325 | // connection. |
| 4326 | MockRead data_reads1[] = { |
| 4327 | // No credentials. |
| 4328 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4329 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4330 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4331 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4332 | |
| 4333 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4335 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4337 | }; |
| 4338 | |
| 4339 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4340 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4342 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4345 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4346 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4347 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4348 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4350 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4352 | |
| 4353 | rv = callback1.WaitForResult(); |
| 4354 | EXPECT_EQ(OK, rv); |
| 4355 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4356 | LoadTimingInfo load_timing_info; |
| 4357 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4358 | TestLoadTimingNotReused(load_timing_info, |
| 4359 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4360 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4361 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4362 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4363 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4364 | EXPECT_EQ(407, response->headers->response_code()); |
| 4365 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4366 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4368 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4370 | rv = trans->RestartWithAuth( |
| 4371 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4373 | |
| 4374 | rv = callback2.WaitForResult(); |
| 4375 | EXPECT_EQ(OK, rv); |
| 4376 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4377 | load_timing_info = LoadTimingInfo(); |
| 4378 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4379 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4380 | TestLoadTimingReused(load_timing_info); |
| 4381 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4382 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4383 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4384 | |
| 4385 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4386 | EXPECT_EQ(200, response->headers->response_code()); |
| 4387 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4388 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4389 | |
| 4390 | // The password prompt info should not be set. |
| 4391 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4392 | } |
| 4393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4394 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4395 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4396 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4398 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4399 | request.load_flags = 0; |
| 4400 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4401 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4402 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4403 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4404 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4405 | // Since we have proxy, should try to establish tunnel. |
| 4406 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4407 | MockWrite( |
| 4408 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4409 | "Host: www.example.org\r\n" |
| 4410 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4411 | }; |
| 4412 | |
| 4413 | MockRead data_reads[] = { |
| 4414 | status, |
| 4415 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4416 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4417 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4418 | }; |
| 4419 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4420 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4421 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4424 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4425 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4426 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4427 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4429 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4431 | |
| 4432 | rv = callback.WaitForResult(); |
| 4433 | EXPECT_EQ(expected_status, rv); |
| 4434 | } |
| 4435 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4436 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4437 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4438 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4439 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4440 | } |
| 4441 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4442 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4443 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4444 | } |
| 4445 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4446 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4447 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4448 | } |
| 4449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4450 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4451 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4452 | } |
| 4453 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4454 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4455 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4456 | } |
| 4457 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4458 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4459 | ConnectStatusHelper( |
| 4460 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4461 | } |
| 4462 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4463 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4464 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4465 | } |
| 4466 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4467 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4468 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4469 | } |
| 4470 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4471 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4472 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4473 | } |
| 4474 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4475 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4476 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4477 | } |
| 4478 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4479 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4480 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4481 | } |
| 4482 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4483 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4484 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4485 | } |
| 4486 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4487 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4488 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4489 | } |
| 4490 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4491 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4492 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4493 | } |
| 4494 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4495 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4496 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4497 | } |
| 4498 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4499 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4500 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4501 | } |
| 4502 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4503 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4504 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4505 | } |
| 4506 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4507 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4508 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4509 | } |
| 4510 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4511 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4512 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4513 | } |
| 4514 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4515 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4516 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4517 | } |
| 4518 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4519 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4520 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4521 | } |
| 4522 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4523 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4524 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4525 | } |
| 4526 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4527 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4528 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4529 | } |
| 4530 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4531 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4532 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4533 | } |
| 4534 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4535 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4536 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4537 | } |
| 4538 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4539 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4540 | ConnectStatusHelperWithExpectedStatus( |
| 4541 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4542 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4543 | } |
| 4544 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4545 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4546 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4547 | } |
| 4548 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4549 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4550 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4551 | } |
| 4552 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4553 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4554 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4555 | } |
| 4556 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4557 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4558 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4559 | } |
| 4560 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4561 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4562 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4563 | } |
| 4564 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4565 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4566 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4567 | } |
| 4568 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4569 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4570 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4571 | } |
| 4572 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4573 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4574 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4575 | } |
| 4576 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4577 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4578 | ConnectStatusHelper( |
| 4579 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4580 | } |
| 4581 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4582 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4583 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4584 | } |
| 4585 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4586 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4587 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4588 | } |
| 4589 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4590 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4591 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4592 | } |
| 4593 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4594 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4595 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4596 | } |
| 4597 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4598 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4599 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4600 | } |
| 4601 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4602 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4603 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4604 | } |
| 4605 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4606 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4607 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4608 | } |
| 4609 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4610 | // Test the flow when both the proxy server AND origin server require |
| 4611 | // authentication. Again, this uses basic auth for both since that is |
| 4612 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4613 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4614 | HttpRequestInfo request; |
| 4615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4616 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4617 | request.load_flags = 0; |
| 4618 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4619 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4620 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4621 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4622 | |
| 4623 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4624 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4625 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4626 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4627 | MockWrite( |
| 4628 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4629 | "Host: www.example.org\r\n" |
| 4630 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4631 | }; |
| 4632 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4633 | MockRead data_reads1[] = { |
| 4634 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4635 | // Give a couple authenticate options (only the middle one is actually |
| 4636 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4637 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4638 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4639 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4640 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4641 | // Large content-length -- won't matter, as connection will be reset. |
| 4642 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4643 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4644 | }; |
| 4645 | |
| 4646 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4647 | // request we should be issuing -- the final header line contains the |
| 4648 | // proxy's credentials. |
| 4649 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4650 | MockWrite( |
| 4651 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4652 | "Host: www.example.org\r\n" |
| 4653 | "Proxy-Connection: keep-alive\r\n" |
| 4654 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4655 | }; |
| 4656 | |
| 4657 | // Now the proxy server lets the request pass through to origin server. |
| 4658 | // The origin server responds with a 401. |
| 4659 | MockRead data_reads2[] = { |
| 4660 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4661 | // Note: We are using the same realm-name as the proxy server. This is |
| 4662 | // completely valid, as realms are unique across hosts. |
| 4663 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4665 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4666 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4667 | }; |
| 4668 | |
| 4669 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4670 | // the credentials for both the proxy and origin server. |
| 4671 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4672 | MockWrite( |
| 4673 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4674 | "Host: www.example.org\r\n" |
| 4675 | "Proxy-Connection: keep-alive\r\n" |
| 4676 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4677 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | // Lastly we get the desired content. |
| 4681 | MockRead data_reads3[] = { |
| 4682 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4684 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4686 | }; |
| 4687 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4688 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4689 | data_writes1, arraysize(data_writes1)); |
| 4690 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4691 | data_writes2, arraysize(data_writes2)); |
| 4692 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4693 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4695 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4696 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4697 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4698 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4700 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4701 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4702 | |
| 4703 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4704 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4705 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4706 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4707 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4708 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4710 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4712 | rv = trans->RestartWithAuth( |
| 4713 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4714 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4715 | |
| 4716 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4717 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4718 | |
| 4719 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4720 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4721 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4723 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4725 | rv = trans->RestartWithAuth( |
| 4726 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4727 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4728 | |
| 4729 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4730 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4731 | |
| 4732 | response = trans->GetResponseInfo(); |
| 4733 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4734 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4735 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4736 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4737 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4738 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4739 | // authorization headers. |
| 4740 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4741 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4742 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4743 | // bytes in the debugger. |
| 4744 | |
| 4745 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4746 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4747 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4748 | request.method = "GET"; |
| 4749 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4750 | |
| 4751 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4752 | // to other auth schemes. |
| 4753 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4754 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4755 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4756 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4757 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4758 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4759 | MockWrite data_writes1[] = { |
| 4760 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4761 | "Host: 172.22.68.17\r\n" |
| 4762 | "Connection: keep-alive\r\n\r\n"), |
| 4763 | }; |
| 4764 | |
| 4765 | MockRead data_reads1[] = { |
| 4766 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4767 | // Negotiate and NTLM are often requested together. However, we only want |
| 4768 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4769 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4770 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4771 | MockRead("Connection: close\r\n"), |
| 4772 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4773 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4774 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4775 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4776 | }; |
| 4777 | |
| 4778 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4779 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4780 | // request we should be issuing -- the final header line contains a Type |
| 4781 | // 1 message. |
| 4782 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4783 | "Host: 172.22.68.17\r\n" |
| 4784 | "Connection: keep-alive\r\n" |
| 4785 | "Authorization: NTLM " |
| 4786 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4787 | |
| 4788 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4789 | // (the credentials for the origin server). The second request continues |
| 4790 | // on the same connection. |
| 4791 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4792 | "Host: 172.22.68.17\r\n" |
| 4793 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4794 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4795 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4796 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4797 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4798 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4799 | }; |
| 4800 | |
| 4801 | MockRead data_reads2[] = { |
| 4802 | // The origin server responds with a Type 2 message. |
| 4803 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4804 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4805 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4806 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4807 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4808 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4809 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4810 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4811 | "BtAAAAAAA=\r\n"), |
| 4812 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4813 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4814 | MockRead("You are not authorized to view this page\r\n"), |
| 4815 | |
| 4816 | // Lastly we get the desired content. |
| 4817 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4818 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4819 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4820 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4821 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4822 | }; |
| 4823 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4824 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4825 | data_writes1, arraysize(data_writes1)); |
| 4826 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4827 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4828 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4829 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4831 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4832 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4833 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4836 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4838 | |
| 4839 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4840 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4841 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4842 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4843 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4844 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4845 | ASSERT_FALSE(response == NULL); |
| 4846 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4848 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4849 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4850 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4851 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4853 | |
| 4854 | rv = callback2.WaitForResult(); |
| 4855 | EXPECT_EQ(OK, rv); |
| 4856 | |
| 4857 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4858 | |
| 4859 | response = trans->GetResponseInfo(); |
| 4860 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4861 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4863 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4865 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4866 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4867 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4868 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4869 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4870 | |
| 4871 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4872 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4873 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4874 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4875 | } |
| 4876 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4877 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4878 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4879 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4880 | request.method = "GET"; |
| 4881 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4882 | request.load_flags = 0; |
| 4883 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4884 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4885 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 4886 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4887 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4888 | MockWrite data_writes1[] = { |
| 4889 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4890 | "Host: 172.22.68.17\r\n" |
| 4891 | "Connection: keep-alive\r\n\r\n"), |
| 4892 | }; |
| 4893 | |
| 4894 | MockRead data_reads1[] = { |
| 4895 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4896 | // Negotiate and NTLM are often requested together. However, we only want |
| 4897 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4898 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4899 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4900 | MockRead("Connection: close\r\n"), |
| 4901 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4902 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4903 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4904 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4905 | }; |
| 4906 | |
| 4907 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4908 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4909 | // request we should be issuing -- the final header line contains a Type |
| 4910 | // 1 message. |
| 4911 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4912 | "Host: 172.22.68.17\r\n" |
| 4913 | "Connection: keep-alive\r\n" |
| 4914 | "Authorization: NTLM " |
| 4915 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4916 | |
| 4917 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4918 | // (the credentials for the origin server). The second request continues |
| 4919 | // on the same connection. |
| 4920 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4921 | "Host: 172.22.68.17\r\n" |
| 4922 | "Connection: keep-alive\r\n" |
| 4923 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4924 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4925 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4926 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4927 | "4Ww7b7E=\r\n\r\n"), |
| 4928 | }; |
| 4929 | |
| 4930 | MockRead data_reads2[] = { |
| 4931 | // The origin server responds with a Type 2 message. |
| 4932 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4933 | MockRead("WWW-Authenticate: NTLM " |
| 4934 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4935 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4936 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4937 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4938 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4939 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4940 | "BtAAAAAAA=\r\n"), |
| 4941 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4942 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4943 | MockRead("You are not authorized to view this page\r\n"), |
| 4944 | |
| 4945 | // Wrong password. |
| 4946 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4947 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4948 | MockRead("Connection: close\r\n"), |
| 4949 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4950 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4951 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4952 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4953 | }; |
| 4954 | |
| 4955 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4956 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4957 | // request we should be issuing -- the final header line contains a Type |
| 4958 | // 1 message. |
| 4959 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4960 | "Host: 172.22.68.17\r\n" |
| 4961 | "Connection: keep-alive\r\n" |
| 4962 | "Authorization: NTLM " |
| 4963 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4964 | |
| 4965 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4966 | // (the credentials for the origin server). The second request continues |
| 4967 | // on the same connection. |
| 4968 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4969 | "Host: 172.22.68.17\r\n" |
| 4970 | "Connection: keep-alive\r\n" |
| 4971 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4972 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4973 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4974 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4975 | "+4MUm7c=\r\n\r\n"), |
| 4976 | }; |
| 4977 | |
| 4978 | MockRead data_reads3[] = { |
| 4979 | // The origin server responds with a Type 2 message. |
| 4980 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4981 | MockRead("WWW-Authenticate: NTLM " |
| 4982 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4983 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4984 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4985 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4986 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4987 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4988 | "BtAAAAAAA=\r\n"), |
| 4989 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4990 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4991 | MockRead("You are not authorized to view this page\r\n"), |
| 4992 | |
| 4993 | // Lastly we get the desired content. |
| 4994 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4995 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4996 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4997 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4999 | }; |
| 5000 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5002 | data_writes1, arraysize(data_writes1)); |
| 5003 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5004 | data_writes2, arraysize(data_writes2)); |
| 5005 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5006 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5007 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5008 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5009 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5011 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5012 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5013 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5014 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5016 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5017 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5018 | |
| 5019 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5020 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5021 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5022 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5023 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5024 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5025 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5026 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5028 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5029 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5030 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5031 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5032 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5034 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5035 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5036 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5037 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5038 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5039 | TestCompletionCallback callback3; |
| 5040 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5042 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5043 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5044 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5045 | |
| 5046 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5047 | ASSERT_FALSE(response == NULL); |
| 5048 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5050 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5051 | |
| 5052 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5053 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5054 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5055 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5056 | |
| 5057 | rv = callback4.WaitForResult(); |
| 5058 | EXPECT_EQ(OK, rv); |
| 5059 | |
| 5060 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5062 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5063 | |
| 5064 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5065 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5067 | |
| 5068 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5069 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5070 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5071 | response = trans->GetResponseInfo(); |
| 5072 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5073 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5074 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5075 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5076 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5077 | // Test reading a server response which has only headers, and no body. |
| 5078 | // After some maximum number of bytes is consumed, the transaction should |
| 5079 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5080 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5081 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5083 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5084 | request.load_flags = 0; |
| 5085 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5086 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5087 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5088 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5089 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5090 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5091 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5092 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5093 | |
| 5094 | MockRead data_reads[] = { |
| 5095 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5096 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5097 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5098 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5099 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5100 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5101 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5103 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5105 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5106 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5107 | |
| 5108 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5109 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5110 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5111 | |
| 5112 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5113 | // establish tunnel. |
| 5114 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5115 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5116 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5117 | HttpRequestInfo request; |
| 5118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5119 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5120 | request.load_flags = 0; |
| 5121 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5122 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5123 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5124 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5125 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5126 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5127 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5128 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5129 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5130 | // Since we have proxy, should try to establish tunnel. |
| 5131 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5132 | MockWrite( |
| 5133 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5134 | "Host: www.example.org\r\n" |
| 5135 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5136 | }; |
| 5137 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5138 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5139 | // connection. Usually a proxy would return 501 (not implemented), |
| 5140 | // or 200 (tunnel established). |
| 5141 | MockRead data_reads1[] = { |
| 5142 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5143 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5144 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5145 | }; |
| 5146 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5147 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5148 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5151 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5153 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5155 | |
| 5156 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5157 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5158 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5159 | // Empty the current queue. This is necessary because idle sockets are |
| 5160 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5161 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5162 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5163 | // We now check to make sure the TCPClientSocket was not added back to |
| 5164 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5165 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5166 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5167 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5168 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5169 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5170 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5171 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5172 | // 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] | 5173 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5174 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5176 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5177 | request.load_flags = 0; |
| 5178 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5179 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5180 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5181 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5182 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5183 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5184 | MockRead data_reads[] = { |
| 5185 | // A part of the response body is received with the response headers. |
| 5186 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5187 | // The rest of the response body is received in two parts. |
| 5188 | MockRead("lo"), |
| 5189 | MockRead(" world"), |
| 5190 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5191 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5192 | }; |
| 5193 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5194 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5197 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5199 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5201 | |
| 5202 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5203 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5204 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5205 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5206 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5207 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5208 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5209 | std::string status_line = response->headers->GetStatusLine(); |
| 5210 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5211 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5212 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5213 | |
| 5214 | std::string response_data; |
| 5215 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5216 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5217 | EXPECT_EQ("hello world", response_data); |
| 5218 | |
| 5219 | // Empty the current queue. This is necessary because idle sockets are |
| 5220 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5221 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5222 | |
| 5223 | // 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] | 5224 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5225 | } |
| 5226 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5227 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5228 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5229 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5230 | HttpRequestInfo request; |
| 5231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5232 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5233 | request.load_flags = 0; |
| 5234 | |
| 5235 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5236 | MockWrite( |
| 5237 | "GET / HTTP/1.1\r\n" |
| 5238 | "Host: www.example.org\r\n" |
| 5239 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5240 | }; |
| 5241 | |
| 5242 | MockRead data_reads[] = { |
| 5243 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5244 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5245 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5247 | }; |
| 5248 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5249 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5251 | |
| 5252 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5253 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5254 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5256 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5257 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5258 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5259 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5262 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5263 | |
| 5264 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5265 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5266 | |
| 5267 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5268 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5269 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5270 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5271 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5272 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5273 | |
| 5274 | std::string response_data; |
| 5275 | rv = ReadTransaction(trans.get(), &response_data); |
| 5276 | EXPECT_EQ(OK, rv); |
| 5277 | EXPECT_EQ("hello world", response_data); |
| 5278 | |
| 5279 | // Empty the current queue. This is necessary because idle sockets are |
| 5280 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5281 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5282 | |
| 5283 | // 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] | 5284 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5288 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5289 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5290 | HttpRequestInfo request; |
| 5291 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5292 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5293 | request.load_flags = 0; |
| 5294 | |
| 5295 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5296 | MockWrite( |
| 5297 | "GET / HTTP/1.1\r\n" |
| 5298 | "Host: www.example.org\r\n" |
| 5299 | "Connection: keep-alive\r\n\r\n"), |
| 5300 | MockWrite( |
| 5301 | "GET / HTTP/1.1\r\n" |
| 5302 | "Host: www.example.org\r\n" |
| 5303 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5304 | }; |
| 5305 | |
| 5306 | MockRead data_reads[] = { |
| 5307 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5308 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5309 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5310 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5311 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5312 | }; |
| 5313 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5314 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5315 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5318 | |
| 5319 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5320 | data_writes, arraysize(data_writes)); |
| 5321 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5322 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5323 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5324 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5326 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5327 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5328 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5329 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5330 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5332 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5333 | |
| 5334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5335 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5336 | |
| 5337 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5338 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5339 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5340 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5341 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5342 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5343 | |
| 5344 | std::string response_data; |
| 5345 | rv = ReadTransaction(trans.get(), &response_data); |
| 5346 | EXPECT_EQ(OK, rv); |
| 5347 | EXPECT_EQ("hello world", response_data); |
| 5348 | |
| 5349 | // Empty the current queue. This is necessary because idle sockets are |
| 5350 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5351 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5352 | |
| 5353 | // 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] | 5354 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5355 | |
| 5356 | // Now start the second transaction, which should reuse the previous socket. |
| 5357 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5358 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5360 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5361 | |
| 5362 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5363 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5364 | |
| 5365 | response = trans->GetResponseInfo(); |
| 5366 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5367 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5368 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5369 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5370 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5371 | |
| 5372 | rv = ReadTransaction(trans.get(), &response_data); |
| 5373 | EXPECT_EQ(OK, rv); |
| 5374 | EXPECT_EQ("hello world", response_data); |
| 5375 | |
| 5376 | // Empty the current queue. This is necessary because idle sockets are |
| 5377 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5378 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5379 | |
| 5380 | // 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] | 5381 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5382 | } |
| 5383 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5384 | // Make sure that we recycle a socket after a zero-length response. |
| 5385 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5386 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5387 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5389 | request.url = GURL( |
| 5390 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5391 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5392 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5393 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5394 | request.load_flags = 0; |
| 5395 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5396 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5397 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5398 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5400 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5401 | MockRead data_reads[] = { |
| 5402 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5403 | "Content-Length: 0\r\n" |
| 5404 | "Content-Type: text/html\r\n\r\n"), |
| 5405 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5406 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5407 | }; |
| 5408 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5409 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5411 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5412 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5414 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5416 | |
| 5417 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5418 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5419 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5420 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5421 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5422 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5423 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5424 | std::string status_line = response->headers->GetStatusLine(); |
| 5425 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5426 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5427 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5428 | |
| 5429 | std::string response_data; |
| 5430 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5431 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5432 | EXPECT_EQ("", response_data); |
| 5433 | |
| 5434 | // Empty the current queue. This is necessary because idle sockets are |
| 5435 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5436 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5437 | |
| 5438 | // 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] | 5439 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5440 | } |
| 5441 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5442 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5443 | ScopedVector<UploadElementReader> element_readers; |
| 5444 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5445 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5446 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5447 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5448 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5449 | // after use. |
| 5450 | request[0].method = "GET"; |
| 5451 | request[0].url = GURL("http://www.google.com/"); |
| 5452 | request[0].load_flags = 0; |
| 5453 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5454 | // transaction 1. The first attempts fails when writing the POST data. |
| 5455 | // This causes the transaction to retry with a new socket. The second |
| 5456 | // attempt succeeds. |
| 5457 | request[1].method = "POST"; |
| 5458 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5459 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5460 | request[1].load_flags = 0; |
| 5461 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5462 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5463 | |
| 5464 | // The first socket is used for transaction 1 and the first attempt of |
| 5465 | // transaction 2. |
| 5466 | |
| 5467 | // The response of transaction 1. |
| 5468 | MockRead data_reads1[] = { |
| 5469 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5470 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5471 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5472 | }; |
| 5473 | // The mock write results of transaction 1 and the first attempt of |
| 5474 | // transaction 2. |
| 5475 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5476 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5477 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5478 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5479 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5480 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5481 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5482 | |
| 5483 | // The second socket is used for the second attempt of transaction 2. |
| 5484 | |
| 5485 | // The response of transaction 2. |
| 5486 | MockRead data_reads2[] = { |
| 5487 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5488 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5489 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5490 | }; |
| 5491 | // The mock write results of the second attempt of transaction 2. |
| 5492 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5493 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5494 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5495 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5496 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5497 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5498 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5499 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5500 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5501 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5502 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5503 | "hello world", "welcome" |
| 5504 | }; |
| 5505 | |
| 5506 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5508 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5510 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5512 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5513 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5514 | |
| 5515 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5516 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5517 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5518 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5519 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5520 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5521 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5522 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5523 | |
| 5524 | std::string response_data; |
| 5525 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5526 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5527 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5528 | } |
| 5529 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5530 | |
| 5531 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5532 | // 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] | 5533 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5534 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5535 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5536 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5537 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5538 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5539 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5540 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5541 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5543 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5544 | // The password contains an escaped character -- for this test to pass it |
| 5545 | // will need to be unescaped by HttpNetworkTransaction. |
| 5546 | EXPECT_EQ("b%40r", request.url.password()); |
| 5547 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5548 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5549 | MockWrite( |
| 5550 | "GET / HTTP/1.1\r\n" |
| 5551 | "Host: www.example.org\r\n" |
| 5552 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5553 | }; |
| 5554 | |
| 5555 | MockRead data_reads1[] = { |
| 5556 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5557 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5558 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5559 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5560 | }; |
| 5561 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5562 | // After the challenge above, the transaction will be restarted using the |
| 5563 | // identity from the url (foo, b@r) to answer the challenge. |
| 5564 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5565 | MockWrite( |
| 5566 | "GET / HTTP/1.1\r\n" |
| 5567 | "Host: www.example.org\r\n" |
| 5568 | "Connection: keep-alive\r\n" |
| 5569 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5570 | }; |
| 5571 | |
| 5572 | MockRead data_reads2[] = { |
| 5573 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5574 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5575 | MockRead(SYNCHRONOUS, OK), |
| 5576 | }; |
| 5577 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5578 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5579 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5580 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5581 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5582 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5583 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5585 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5586 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5588 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5589 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5590 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5591 | |
| 5592 | TestCompletionCallback callback2; |
| 5593 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5594 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5595 | rv = callback2.WaitForResult(); |
| 5596 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5597 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5598 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5599 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5600 | ASSERT_TRUE(response != NULL); |
| 5601 | |
| 5602 | // There is no challenge info, since the identity in URL worked. |
| 5603 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5604 | |
| 5605 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5606 | |
| 5607 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5608 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5612 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5613 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5614 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5615 | HttpRequestInfo request; |
| 5616 | request.method = "GET"; |
| 5617 | // Note: the URL has a username:password in it. The password "baz" is |
| 5618 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5619 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5620 | |
| 5621 | request.load_flags = LOAD_NORMAL; |
| 5622 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5623 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5624 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5625 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5626 | |
| 5627 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5628 | MockWrite( |
| 5629 | "GET / HTTP/1.1\r\n" |
| 5630 | "Host: www.example.org\r\n" |
| 5631 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5632 | }; |
| 5633 | |
| 5634 | MockRead data_reads1[] = { |
| 5635 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5636 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5637 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5638 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5639 | }; |
| 5640 | |
| 5641 | // After the challenge above, the transaction will be restarted using the |
| 5642 | // identity from the url (foo, baz) to answer the challenge. |
| 5643 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5644 | MockWrite( |
| 5645 | "GET / HTTP/1.1\r\n" |
| 5646 | "Host: www.example.org\r\n" |
| 5647 | "Connection: keep-alive\r\n" |
| 5648 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5649 | }; |
| 5650 | |
| 5651 | MockRead data_reads2[] = { |
| 5652 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5653 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5654 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5655 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5656 | }; |
| 5657 | |
| 5658 | // After the challenge above, the transaction will be restarted using the |
| 5659 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5660 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5661 | MockWrite( |
| 5662 | "GET / HTTP/1.1\r\n" |
| 5663 | "Host: www.example.org\r\n" |
| 5664 | "Connection: keep-alive\r\n" |
| 5665 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5666 | }; |
| 5667 | |
| 5668 | MockRead data_reads3[] = { |
| 5669 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5670 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5671 | MockRead(SYNCHRONOUS, OK), |
| 5672 | }; |
| 5673 | |
| 5674 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5675 | data_writes1, arraysize(data_writes1)); |
| 5676 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5677 | data_writes2, arraysize(data_writes2)); |
| 5678 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5679 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5680 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5681 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5682 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5683 | |
| 5684 | TestCompletionCallback callback1; |
| 5685 | |
| 5686 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5688 | |
| 5689 | rv = callback1.WaitForResult(); |
| 5690 | EXPECT_EQ(OK, rv); |
| 5691 | |
| 5692 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5693 | TestCompletionCallback callback2; |
| 5694 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5696 | rv = callback2.WaitForResult(); |
| 5697 | EXPECT_EQ(OK, rv); |
| 5698 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5699 | |
| 5700 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5701 | ASSERT_TRUE(response != NULL); |
| 5702 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5703 | |
| 5704 | TestCompletionCallback callback3; |
| 5705 | rv = trans->RestartWithAuth( |
| 5706 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5707 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5708 | rv = callback3.WaitForResult(); |
| 5709 | EXPECT_EQ(OK, rv); |
| 5710 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5711 | |
| 5712 | response = trans->GetResponseInfo(); |
| 5713 | ASSERT_TRUE(response != NULL); |
| 5714 | |
| 5715 | // There is no challenge info, since the identity worked. |
| 5716 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5717 | |
| 5718 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5719 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5720 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5721 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5722 | } |
| 5723 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5724 | |
| 5725 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5726 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5727 | // from the URL should never be used. |
| 5728 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5729 | HttpRequestInfo request; |
| 5730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5731 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5732 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5733 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5734 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5735 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5736 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5737 | |
| 5738 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5739 | MockWrite( |
| 5740 | "GET / HTTP/1.1\r\n" |
| 5741 | "Host: www.example.org\r\n" |
| 5742 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5743 | }; |
| 5744 | |
| 5745 | MockRead data_reads1[] = { |
| 5746 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5747 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5748 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5749 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5750 | }; |
| 5751 | |
| 5752 | // After the challenge above, the transaction will be restarted using the |
| 5753 | // identity supplied by the user, not the one in the URL, to answer the |
| 5754 | // challenge. |
| 5755 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5756 | MockWrite( |
| 5757 | "GET / HTTP/1.1\r\n" |
| 5758 | "Host: www.example.org\r\n" |
| 5759 | "Connection: keep-alive\r\n" |
| 5760 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5761 | }; |
| 5762 | |
| 5763 | MockRead data_reads3[] = { |
| 5764 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5765 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5766 | MockRead(SYNCHRONOUS, OK), |
| 5767 | }; |
| 5768 | |
| 5769 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5770 | data_writes1, arraysize(data_writes1)); |
| 5771 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5772 | data_writes3, arraysize(data_writes3)); |
| 5773 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5774 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5775 | |
| 5776 | TestCompletionCallback callback1; |
| 5777 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5779 | rv = callback1.WaitForResult(); |
| 5780 | EXPECT_EQ(OK, rv); |
| 5781 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5782 | |
| 5783 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5784 | ASSERT_TRUE(response != NULL); |
| 5785 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5786 | |
| 5787 | TestCompletionCallback callback3; |
| 5788 | rv = trans->RestartWithAuth( |
| 5789 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5790 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5791 | rv = callback3.WaitForResult(); |
| 5792 | EXPECT_EQ(OK, rv); |
| 5793 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5794 | |
| 5795 | response = trans->GetResponseInfo(); |
| 5796 | ASSERT_TRUE(response != NULL); |
| 5797 | |
| 5798 | // There is no challenge info, since the identity worked. |
| 5799 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5800 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5801 | |
| 5802 | // Empty the current queue. |
| 5803 | base::MessageLoop::current()->RunUntilIdle(); |
| 5804 | } |
| 5805 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5806 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5807 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 5808 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5809 | |
| 5810 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5811 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5812 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5813 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5814 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5815 | request.load_flags = 0; |
| 5816 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5817 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5819 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5820 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5821 | MockWrite( |
| 5822 | "GET /x/y/z HTTP/1.1\r\n" |
| 5823 | "Host: www.example.org\r\n" |
| 5824 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5825 | }; |
| 5826 | |
| 5827 | MockRead data_reads1[] = { |
| 5828 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5829 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5830 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5831 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5832 | }; |
| 5833 | |
| 5834 | // Resend with authorization (username=foo, password=bar) |
| 5835 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5836 | MockWrite( |
| 5837 | "GET /x/y/z HTTP/1.1\r\n" |
| 5838 | "Host: www.example.org\r\n" |
| 5839 | "Connection: keep-alive\r\n" |
| 5840 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5841 | }; |
| 5842 | |
| 5843 | // Sever accepts the authorization. |
| 5844 | MockRead data_reads2[] = { |
| 5845 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5846 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5847 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5848 | }; |
| 5849 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5850 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5851 | data_writes1, arraysize(data_writes1)); |
| 5852 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5853 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5855 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5857 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5859 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5860 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5861 | |
| 5862 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5863 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5864 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5865 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5866 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5867 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5869 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5871 | rv = trans->RestartWithAuth( |
| 5872 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5874 | |
| 5875 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5876 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5877 | |
| 5878 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5879 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5880 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5881 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5882 | } |
| 5883 | |
| 5884 | // ------------------------------------------------------------------------ |
| 5885 | |
| 5886 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5887 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5888 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5889 | request.method = "GET"; |
| 5890 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5891 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5892 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5893 | request.load_flags = 0; |
| 5894 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5895 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5897 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5898 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5899 | MockWrite( |
| 5900 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5901 | "Host: www.example.org\r\n" |
| 5902 | "Connection: keep-alive\r\n" |
| 5903 | // Send preemptive authorization for MyRealm1 |
| 5904 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5905 | }; |
| 5906 | |
| 5907 | // The server didn't like the preemptive authorization, and |
| 5908 | // challenges us for a different realm (MyRealm2). |
| 5909 | MockRead data_reads1[] = { |
| 5910 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5911 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5912 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5913 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5914 | }; |
| 5915 | |
| 5916 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5917 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5918 | MockWrite( |
| 5919 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5920 | "Host: www.example.org\r\n" |
| 5921 | "Connection: keep-alive\r\n" |
| 5922 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5923 | }; |
| 5924 | |
| 5925 | // Sever accepts the authorization. |
| 5926 | MockRead data_reads2[] = { |
| 5927 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5928 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5930 | }; |
| 5931 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5932 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5933 | data_writes1, arraysize(data_writes1)); |
| 5934 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5935 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5936 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5937 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5939 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5941 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5943 | |
| 5944 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5945 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5946 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5947 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5948 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5949 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5950 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5951 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5952 | response->auth_challenge->challenger.ToString()); |
| 5953 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5954 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5956 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5958 | rv = trans->RestartWithAuth( |
| 5959 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5961 | |
| 5962 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5963 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5964 | |
| 5965 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5966 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5967 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5968 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5969 | } |
| 5970 | |
| 5971 | // ------------------------------------------------------------------------ |
| 5972 | |
| 5973 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5974 | // succeed with preemptive authorization. |
| 5975 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5976 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5978 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5979 | request.load_flags = 0; |
| 5980 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5981 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5982 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5983 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5984 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5985 | MockWrite( |
| 5986 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 5987 | "Host: www.example.org\r\n" |
| 5988 | "Connection: keep-alive\r\n" |
| 5989 | // The authorization for MyRealm1 gets sent preemptively |
| 5990 | // (since the url is in the same protection space) |
| 5991 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5992 | }; |
| 5993 | |
| 5994 | // Sever accepts the preemptive authorization |
| 5995 | MockRead data_reads1[] = { |
| 5996 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5997 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5999 | }; |
| 6000 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6002 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6005 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6007 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6008 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6009 | |
| 6010 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6011 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6012 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6013 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6014 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6015 | |
| 6016 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6017 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6018 | } |
| 6019 | |
| 6020 | // ------------------------------------------------------------------------ |
| 6021 | |
| 6022 | // Transaction 4: request another URL in MyRealm (however the |
| 6023 | // url is not known to belong to the protection space, so no pre-auth). |
| 6024 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6025 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6027 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6028 | request.load_flags = 0; |
| 6029 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6030 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6031 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6032 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6033 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6034 | MockWrite( |
| 6035 | "GET /x/1 HTTP/1.1\r\n" |
| 6036 | "Host: www.example.org\r\n" |
| 6037 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6038 | }; |
| 6039 | |
| 6040 | MockRead data_reads1[] = { |
| 6041 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6042 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6043 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6044 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6045 | }; |
| 6046 | |
| 6047 | // Resend with authorization from MyRealm's cache. |
| 6048 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6049 | MockWrite( |
| 6050 | "GET /x/1 HTTP/1.1\r\n" |
| 6051 | "Host: www.example.org\r\n" |
| 6052 | "Connection: keep-alive\r\n" |
| 6053 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6054 | }; |
| 6055 | |
| 6056 | // Sever accepts the authorization. |
| 6057 | MockRead data_reads2[] = { |
| 6058 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6059 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6061 | }; |
| 6062 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6063 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6064 | data_writes1, arraysize(data_writes1)); |
| 6065 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6066 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6067 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6068 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6070 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6072 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6073 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6074 | |
| 6075 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6076 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6077 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6078 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6079 | TestCompletionCallback callback2; |
| 6080 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6082 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6083 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6084 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6085 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6086 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6087 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6088 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6089 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6090 | } |
| 6091 | |
| 6092 | // ------------------------------------------------------------------------ |
| 6093 | |
| 6094 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6095 | // cached identity. Should invalidate and re-prompt. |
| 6096 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6097 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6098 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6099 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6100 | request.load_flags = 0; |
| 6101 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6102 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6103 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 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 /p/q/t 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: 10000\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 | |
| 6119 | // Resend with authorization from cache for MyRealm. |
| 6120 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6121 | MockWrite( |
| 6122 | "GET /p/q/t HTTP/1.1\r\n" |
| 6123 | "Host: www.example.org\r\n" |
| 6124 | "Connection: keep-alive\r\n" |
| 6125 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6126 | }; |
| 6127 | |
| 6128 | // Sever rejects the authorization. |
| 6129 | MockRead data_reads2[] = { |
| 6130 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6131 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6132 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6133 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6134 | }; |
| 6135 | |
| 6136 | // At this point we should prompt for new credentials for MyRealm. |
| 6137 | // Restart with username=foo3, password=foo4. |
| 6138 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6139 | MockWrite( |
| 6140 | "GET /p/q/t HTTP/1.1\r\n" |
| 6141 | "Host: www.example.org\r\n" |
| 6142 | "Connection: keep-alive\r\n" |
| 6143 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6144 | }; |
| 6145 | |
| 6146 | // Sever accepts the authorization. |
| 6147 | MockRead data_reads3[] = { |
| 6148 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6149 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6150 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6151 | }; |
| 6152 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6153 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6154 | data_writes1, arraysize(data_writes1)); |
| 6155 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6156 | data_writes2, arraysize(data_writes2)); |
| 6157 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6158 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6161 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6163 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6165 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6167 | |
| 6168 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6169 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6170 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6171 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6172 | TestCompletionCallback callback2; |
| 6173 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6175 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6176 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6177 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6178 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6179 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6180 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6181 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6182 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6183 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6184 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6185 | rv = trans->RestartWithAuth( |
| 6186 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6187 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6188 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6189 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6190 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6191 | |
| 6192 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6193 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6194 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6195 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6196 | } |
| 6197 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6198 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6199 | // Tests that nonce count increments when multiple auth attempts |
| 6200 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6201 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6202 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6203 | new HttpAuthHandlerDigest::Factory(); |
| 6204 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6205 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6206 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6207 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6208 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6209 | |
| 6210 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6211 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6212 | HttpRequestInfo request; |
| 6213 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6214 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6215 | request.load_flags = 0; |
| 6216 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6217 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6218 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6219 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6220 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6221 | MockWrite( |
| 6222 | "GET /x/y/z HTTP/1.1\r\n" |
| 6223 | "Host: www.example.org\r\n" |
| 6224 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6225 | }; |
| 6226 | |
| 6227 | MockRead data_reads1[] = { |
| 6228 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6229 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6230 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6231 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6232 | }; |
| 6233 | |
| 6234 | // Resend with authorization (username=foo, password=bar) |
| 6235 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6236 | MockWrite( |
| 6237 | "GET /x/y/z HTTP/1.1\r\n" |
| 6238 | "Host: www.example.org\r\n" |
| 6239 | "Connection: keep-alive\r\n" |
| 6240 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6241 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6242 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6243 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6244 | }; |
| 6245 | |
| 6246 | // Sever accepts the authorization. |
| 6247 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6248 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6249 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6250 | }; |
| 6251 | |
| 6252 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6253 | data_writes1, arraysize(data_writes1)); |
| 6254 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6255 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6256 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6257 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6259 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6261 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6263 | |
| 6264 | rv = callback1.WaitForResult(); |
| 6265 | EXPECT_EQ(OK, rv); |
| 6266 | |
| 6267 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6268 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6269 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6271 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6273 | rv = trans->RestartWithAuth( |
| 6274 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6276 | |
| 6277 | rv = callback2.WaitForResult(); |
| 6278 | EXPECT_EQ(OK, rv); |
| 6279 | |
| 6280 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6281 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6282 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6283 | } |
| 6284 | |
| 6285 | // ------------------------------------------------------------------------ |
| 6286 | |
| 6287 | // Transaction 2: Request another resource in digestive's protection space. |
| 6288 | // This will preemptively add an Authorization header which should have an |
| 6289 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6290 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6291 | HttpRequestInfo request; |
| 6292 | request.method = "GET"; |
| 6293 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6294 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6295 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6296 | request.load_flags = 0; |
| 6297 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6298 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6300 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6301 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6302 | MockWrite( |
| 6303 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6304 | "Host: www.example.org\r\n" |
| 6305 | "Connection: keep-alive\r\n" |
| 6306 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6307 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6308 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6309 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6310 | }; |
| 6311 | |
| 6312 | // Sever accepts the authorization. |
| 6313 | MockRead data_reads1[] = { |
| 6314 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6315 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6316 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6317 | }; |
| 6318 | |
| 6319 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6320 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6321 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6323 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6324 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6325 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6327 | |
| 6328 | rv = callback1.WaitForResult(); |
| 6329 | EXPECT_EQ(OK, rv); |
| 6330 | |
| 6331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6332 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6333 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6334 | } |
| 6335 | } |
| 6336 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6337 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6338 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6339 | // Create a transaction (the dependencies aren't important). |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6340 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6341 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6342 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6343 | |
| 6344 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6345 | trans->read_buf_ = new IOBuffer(15); |
| 6346 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6347 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6348 | |
| 6349 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6350 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6351 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6352 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6353 | response->response_time = base::Time::Now(); |
| 6354 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6355 | |
| 6356 | { // Setup state for response_.vary_data |
| 6357 | HttpRequestInfo request; |
| 6358 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6359 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6360 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6361 | request.extra_headers.SetHeader("Foo", "1"); |
| 6362 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6363 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | // Cause the above state to be reset. |
| 6367 | trans->ResetStateForRestart(); |
| 6368 | |
| 6369 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6370 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6371 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6372 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6373 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6374 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6375 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6376 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6377 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6378 | } |
| 6379 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6380 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6381 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6382 | HttpRequestInfo request; |
| 6383 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6384 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6385 | request.load_flags = 0; |
| 6386 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6388 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6389 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6390 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6391 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6392 | MockWrite( |
| 6393 | "GET / HTTP/1.1\r\n" |
| 6394 | "Host: www.example.org\r\n" |
| 6395 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6396 | }; |
| 6397 | |
| 6398 | MockRead data_reads[] = { |
| 6399 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6401 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6402 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6403 | }; |
| 6404 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6405 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6406 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6407 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6408 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6409 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6410 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6411 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6412 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6413 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6416 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6418 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6419 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6420 | |
| 6421 | rv = callback.WaitForResult(); |
| 6422 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6424 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6426 | |
| 6427 | rv = callback.WaitForResult(); |
| 6428 | EXPECT_EQ(OK, rv); |
| 6429 | |
| 6430 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6431 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6432 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6433 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6434 | } |
| 6435 | |
| 6436 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6437 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6438 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6439 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6440 | |
| 6441 | HttpRequestInfo request; |
| 6442 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6443 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6444 | request.load_flags = 0; |
| 6445 | |
| 6446 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6447 | MockWrite( |
| 6448 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6449 | "Host: www.example.org\r\n" |
| 6450 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6451 | }; |
| 6452 | |
| 6453 | MockRead proxy_reads[] = { |
| 6454 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6455 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6456 | }; |
| 6457 | |
| 6458 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6459 | MockWrite( |
| 6460 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6461 | "Host: www.example.org\r\n" |
| 6462 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6463 | MockWrite( |
| 6464 | "GET / HTTP/1.1\r\n" |
| 6465 | "Host: www.example.org\r\n" |
| 6466 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6467 | }; |
| 6468 | |
| 6469 | MockRead data_reads[] = { |
| 6470 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6471 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6472 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6473 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6474 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6475 | }; |
| 6476 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6477 | StaticSocketDataProvider ssl_bad_certificate( |
| 6478 | proxy_reads, arraysize(proxy_reads), |
| 6479 | proxy_writes, arraysize(proxy_writes)); |
| 6480 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6481 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6482 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6483 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6484 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6485 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6490 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6491 | |
| 6492 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6493 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6494 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6495 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6496 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6497 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6499 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6501 | |
| 6502 | rv = callback.WaitForResult(); |
| 6503 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6505 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6507 | |
| 6508 | rv = callback.WaitForResult(); |
| 6509 | EXPECT_EQ(OK, rv); |
| 6510 | |
| 6511 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6512 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6513 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6514 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6515 | } |
| 6516 | } |
| 6517 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6518 | |
| 6519 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6520 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6521 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6522 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6523 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6524 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6525 | |
| 6526 | HttpRequestInfo request; |
| 6527 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6528 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6529 | request.load_flags = 0; |
| 6530 | |
| 6531 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6532 | MockWrite( |
| 6533 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6534 | "Host: www.example.org\r\n" |
| 6535 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6536 | MockWrite( |
| 6537 | "GET / HTTP/1.1\r\n" |
| 6538 | "Host: www.example.org\r\n" |
| 6539 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6540 | }; |
| 6541 | |
| 6542 | MockRead data_reads[] = { |
| 6543 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6544 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6545 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6546 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6547 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6548 | }; |
| 6549 | |
| 6550 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6551 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6552 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6553 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6554 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6559 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6560 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6561 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6562 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6563 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6565 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6566 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6567 | |
| 6568 | rv = callback.WaitForResult(); |
| 6569 | EXPECT_EQ(OK, rv); |
| 6570 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6571 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6572 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6573 | |
| 6574 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6575 | EXPECT_EQ(200, response->headers->response_code()); |
| 6576 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6577 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6578 | |
| 6579 | LoadTimingInfo load_timing_info; |
| 6580 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6581 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6582 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6583 | } |
| 6584 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6585 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6586 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6587 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6588 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6589 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6590 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6591 | |
| 6592 | HttpRequestInfo request; |
| 6593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6594 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6595 | request.load_flags = 0; |
| 6596 | |
| 6597 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6598 | MockWrite( |
| 6599 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6600 | "Host: www.example.org\r\n" |
| 6601 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6602 | }; |
| 6603 | |
| 6604 | MockRead data_reads[] = { |
| 6605 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6606 | MockRead("Location: http://login.example.com/\r\n"), |
| 6607 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6608 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6609 | }; |
| 6610 | |
| 6611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6612 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6613 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6614 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6618 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6619 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6620 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6621 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6622 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6624 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6626 | |
| 6627 | rv = callback.WaitForResult(); |
| 6628 | EXPECT_EQ(OK, rv); |
| 6629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6630 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6631 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6632 | |
| 6633 | EXPECT_EQ(302, response->headers->response_code()); |
| 6634 | std::string url; |
| 6635 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6636 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6637 | |
| 6638 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6639 | // timing for the proxy connection instead of the connection to the host, |
| 6640 | // and no send / receive times. |
| 6641 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6642 | LoadTimingInfo load_timing_info; |
| 6643 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6644 | |
| 6645 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6646 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6647 | |
| 6648 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6649 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6650 | load_timing_info.proxy_resolve_end); |
| 6651 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6652 | load_timing_info.connect_timing.connect_start); |
| 6653 | ExpectConnectTimingHasTimes( |
| 6654 | load_timing_info.connect_timing, |
| 6655 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6656 | |
| 6657 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6658 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6659 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6660 | } |
| 6661 | |
| 6662 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6663 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6664 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6665 | ProxyService::CreateFixed("https://proxy:70")); |
| 6666 | |
| 6667 | HttpRequestInfo request; |
| 6668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6669 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6670 | request.load_flags = 0; |
| 6671 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6672 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6673 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6674 | scoped_ptr<SpdyFrame> goaway( |
| 6675 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6676 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6677 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6678 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6679 | }; |
| 6680 | |
| 6681 | static const char* const kExtraHeaders[] = { |
| 6682 | "location", |
| 6683 | "http://login.example.com/", |
| 6684 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6685 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6686 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6687 | arraysize(kExtraHeaders)/2, 1)); |
| 6688 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6689 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6690 | }; |
| 6691 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6692 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6693 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6694 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6695 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6696 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6700 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6701 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6702 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6703 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6704 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6706 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6707 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6708 | |
| 6709 | rv = callback.WaitForResult(); |
| 6710 | EXPECT_EQ(OK, rv); |
| 6711 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6712 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6713 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6714 | |
| 6715 | EXPECT_EQ(302, response->headers->response_code()); |
| 6716 | std::string url; |
| 6717 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6718 | EXPECT_EQ("http://login.example.com/", url); |
| 6719 | } |
| 6720 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6721 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6722 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6723 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6724 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6725 | ProxyService::CreateFixed("https://proxy:70")); |
| 6726 | |
| 6727 | HttpRequestInfo request; |
| 6728 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6729 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6730 | request.load_flags = 0; |
| 6731 | |
| 6732 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6733 | MockWrite( |
| 6734 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6735 | "Host: www.example.org\r\n" |
| 6736 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6737 | }; |
| 6738 | |
| 6739 | MockRead data_reads[] = { |
| 6740 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6741 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6742 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6743 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6744 | }; |
| 6745 | |
| 6746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6747 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6748 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6749 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6753 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6754 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6755 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6756 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6757 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6758 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6759 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6761 | |
| 6762 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6763 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6764 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6765 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6766 | } |
| 6767 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6768 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6769 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6770 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6771 | session_deps_.proxy_service.reset( |
| 6772 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6773 | |
| 6774 | HttpRequestInfo request; |
| 6775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6776 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6777 | request.load_flags = 0; |
| 6778 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6779 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6780 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6781 | scoped_ptr<SpdyFrame> rst( |
| 6782 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6783 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6784 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6785 | }; |
| 6786 | |
| 6787 | static const char* const kExtraHeaders[] = { |
| 6788 | "location", |
| 6789 | "http://login.example.com/", |
| 6790 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6791 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6792 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6793 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6794 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6795 | spdy_util_.ConstructSpdyBodyFrame( |
| 6796 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6797 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6798 | CreateMockRead(*resp.get(), 1), |
| 6799 | CreateMockRead(*body.get(), 2), |
| 6800 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6801 | }; |
| 6802 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6803 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6804 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6805 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6806 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6812 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6813 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6814 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6815 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6817 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6819 | |
| 6820 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6821 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6822 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6823 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6824 | } |
| 6825 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6826 | // Test the request-challenge-retry sequence for basic auth, through |
| 6827 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6828 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6829 | HttpRequestInfo request; |
| 6830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6831 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6832 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6833 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6834 | |
| 6835 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6836 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6837 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6838 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6839 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6840 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6841 | |
| 6842 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6843 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6844 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6845 | scoped_ptr<SpdyFrame> rst( |
| 6846 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6847 | |
| 6848 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6849 | // be issuing -- the final header line contains the credentials. |
| 6850 | const char* const kAuthCredentials[] = { |
| 6851 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6852 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6853 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6854 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6855 | HostPortPair("www.example.org", 443))); |
| 6856 | // fetch https://www.example.org/ via HTTP |
| 6857 | const char get[] = |
| 6858 | "GET / HTTP/1.1\r\n" |
| 6859 | "Host: www.example.org\r\n" |
| 6860 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6861 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6862 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6863 | |
| 6864 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6865 | CreateMockWrite(*req, 0, ASYNC), |
| 6866 | CreateMockWrite(*rst, 2, ASYNC), |
| 6867 | CreateMockWrite(*connect2, 3), |
| 6868 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6869 | }; |
| 6870 | |
| 6871 | // The proxy responds to the connect with a 407, using a persistent |
| 6872 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6873 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6874 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6875 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6876 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6877 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6878 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6879 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6880 | scoped_ptr<SpdyFrame> conn_resp( |
| 6881 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6882 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6883 | "Content-Length: 5\r\n\r\n"; |
| 6884 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6885 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6886 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6887 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6888 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6889 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6890 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6891 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6892 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6893 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6894 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6895 | }; |
| 6896 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6897 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6898 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6899 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6900 | // Negotiate SPDY to the proxy |
| 6901 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6902 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6904 | // Vanilla SSL to the server |
| 6905 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6906 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6907 | |
| 6908 | TestCompletionCallback callback1; |
| 6909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6910 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6912 | |
| 6913 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6914 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6915 | |
| 6916 | rv = callback1.WaitForResult(); |
| 6917 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6918 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6919 | log.GetEntries(&entries); |
| 6920 | size_t pos = ExpectLogContainsSomewhere( |
| 6921 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6922 | NetLog::PHASE_NONE); |
| 6923 | ExpectLogContainsSomewhere( |
| 6924 | entries, pos, |
| 6925 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6926 | NetLog::PHASE_NONE); |
| 6927 | |
| 6928 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6929 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6930 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6931 | EXPECT_EQ(407, response->headers->response_code()); |
| 6932 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6933 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6934 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6935 | |
| 6936 | TestCompletionCallback callback2; |
| 6937 | |
| 6938 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6939 | callback2.callback()); |
| 6940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6941 | |
| 6942 | rv = callback2.WaitForResult(); |
| 6943 | EXPECT_EQ(OK, rv); |
| 6944 | |
| 6945 | response = trans->GetResponseInfo(); |
| 6946 | ASSERT_TRUE(response != NULL); |
| 6947 | |
| 6948 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6949 | EXPECT_EQ(200, response->headers->response_code()); |
| 6950 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6951 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6952 | |
| 6953 | // The password prompt info should not be set. |
| 6954 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6955 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6956 | LoadTimingInfo load_timing_info; |
| 6957 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6958 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6959 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6960 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6961 | trans.reset(); |
| 6962 | session->CloseAllConnections(); |
| 6963 | } |
| 6964 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6965 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6966 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6967 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6968 | HttpRequestInfo request; |
| 6969 | HttpRequestInfo push_request; |
| 6970 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6972 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6973 | push_request.method = "GET"; |
| 6974 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6975 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6976 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6977 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6978 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6979 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6980 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6981 | |
| 6982 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6983 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6984 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 6985 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6986 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6987 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6988 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6989 | |
| 6990 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6991 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6992 | }; |
| 6993 | |
| 6994 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6995 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6996 | |
| 6997 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6998 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6999 | |
| 7000 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7001 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7002 | 0, |
| 7003 | 2, |
| 7004 | 1, |
| 7005 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7006 | const char kPushedData[] = "pushed"; |
| 7007 | scoped_ptr<SpdyFrame> stream2_body( |
| 7008 | spdy_util_.ConstructSpdyBodyFrame( |
| 7009 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7010 | |
| 7011 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7012 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7013 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7014 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7015 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7016 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7017 | }; |
| 7018 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7019 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7020 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7021 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7022 | // Negotiate SPDY to the proxy |
| 7023 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7024 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7026 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7027 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7028 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7029 | TestCompletionCallback callback; |
| 7030 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7032 | |
| 7033 | rv = callback.WaitForResult(); |
| 7034 | EXPECT_EQ(OK, rv); |
| 7035 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7036 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7037 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7039 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7041 | |
| 7042 | rv = callback.WaitForResult(); |
| 7043 | EXPECT_EQ(OK, rv); |
| 7044 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7045 | |
| 7046 | ASSERT_TRUE(response != NULL); |
| 7047 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7048 | |
| 7049 | EXPECT_EQ(200, response->headers->response_code()); |
| 7050 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7051 | |
| 7052 | std::string response_data; |
| 7053 | rv = ReadTransaction(trans.get(), &response_data); |
| 7054 | EXPECT_EQ(OK, rv); |
| 7055 | EXPECT_EQ("hello!", response_data); |
| 7056 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7057 | LoadTimingInfo load_timing_info; |
| 7058 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7059 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7060 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7061 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7062 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7063 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7064 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7065 | |
| 7066 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7067 | EXPECT_EQ(OK, rv); |
| 7068 | EXPECT_EQ("pushed", response_data); |
| 7069 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7070 | LoadTimingInfo push_load_timing_info; |
| 7071 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7072 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7073 | // The transactions should share a socket ID, despite being for different |
| 7074 | // origins. |
| 7075 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7076 | push_load_timing_info.socket_log_id); |
| 7077 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7078 | trans.reset(); |
| 7079 | push_trans.reset(); |
| 7080 | session->CloseAllConnections(); |
| 7081 | } |
| 7082 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7083 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7084 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7085 | HttpRequestInfo request; |
| 7086 | |
| 7087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7088 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7089 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7090 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7091 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7092 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7093 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7094 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7095 | |
| 7096 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7097 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7098 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7099 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7100 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7101 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7102 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7103 | |
| 7104 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7105 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7106 | |
| 7107 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7108 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7109 | }; |
| 7110 | |
| 7111 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7112 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7113 | |
| 7114 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7115 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7116 | |
| 7117 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7118 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7119 | 0, |
| 7120 | 2, |
| 7121 | 1, |
| 7122 | "https://www.another-origin.com/foo.dat")); |
| 7123 | |
| 7124 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7125 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7126 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7127 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7128 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7129 | }; |
| 7130 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7131 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7132 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7133 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7134 | // Negotiate SPDY to the proxy |
| 7135 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7136 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7138 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7139 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7141 | TestCompletionCallback callback; |
| 7142 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7144 | |
| 7145 | rv = callback.WaitForResult(); |
| 7146 | EXPECT_EQ(OK, rv); |
| 7147 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7148 | |
| 7149 | ASSERT_TRUE(response != NULL); |
| 7150 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7151 | |
| 7152 | EXPECT_EQ(200, response->headers->response_code()); |
| 7153 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7154 | |
| 7155 | std::string response_data; |
| 7156 | rv = ReadTransaction(trans.get(), &response_data); |
| 7157 | EXPECT_EQ(OK, rv); |
| 7158 | EXPECT_EQ("hello!", response_data); |
| 7159 | |
| 7160 | trans.reset(); |
| 7161 | session->CloseAllConnections(); |
| 7162 | } |
| 7163 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7164 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7165 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7166 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7167 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7168 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7169 | |
| 7170 | HttpRequestInfo request; |
| 7171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7172 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7173 | request.load_flags = 0; |
| 7174 | |
| 7175 | // Attempt to fetch the URL from a server with a bad cert |
| 7176 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7177 | MockWrite( |
| 7178 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7179 | "Host: www.example.org\r\n" |
| 7180 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7181 | }; |
| 7182 | |
| 7183 | MockRead bad_cert_reads[] = { |
| 7184 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7185 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7186 | }; |
| 7187 | |
| 7188 | // Attempt to fetch the URL with a good cert |
| 7189 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7190 | MockWrite( |
| 7191 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7192 | "Host: www.example.org\r\n" |
| 7193 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7194 | MockWrite( |
| 7195 | "GET / HTTP/1.1\r\n" |
| 7196 | "Host: www.example.org\r\n" |
| 7197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7198 | }; |
| 7199 | |
| 7200 | MockRead good_cert_reads[] = { |
| 7201 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7203 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7204 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7206 | }; |
| 7207 | |
| 7208 | StaticSocketDataProvider ssl_bad_certificate( |
| 7209 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7210 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7211 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7212 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7213 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7214 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7215 | |
| 7216 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7218 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7220 | |
| 7221 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7223 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7226 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7227 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7229 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7232 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7233 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7234 | |
| 7235 | rv = callback.WaitForResult(); |
| 7236 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7238 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7239 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7240 | |
| 7241 | rv = callback.WaitForResult(); |
| 7242 | EXPECT_EQ(OK, rv); |
| 7243 | |
| 7244 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7245 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7246 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7247 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7248 | } |
| 7249 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7250 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7251 | HttpRequestInfo request; |
| 7252 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7253 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7254 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7255 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7256 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7257 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7258 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7260 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7261 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7262 | MockWrite( |
| 7263 | "GET / HTTP/1.1\r\n" |
| 7264 | "Host: www.example.org\r\n" |
| 7265 | "Connection: keep-alive\r\n" |
| 7266 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7267 | }; |
| 7268 | |
| 7269 | // Lastly, the server responds with the actual content. |
| 7270 | MockRead data_reads[] = { |
| 7271 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7273 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7274 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7275 | }; |
| 7276 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7278 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7281 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7283 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7284 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7285 | |
| 7286 | rv = callback.WaitForResult(); |
| 7287 | EXPECT_EQ(OK, rv); |
| 7288 | } |
| 7289 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7290 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7291 | HttpRequestInfo request; |
| 7292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7293 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7294 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7295 | "Chromium Ultra Awesome X Edition"); |
| 7296 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7297 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7298 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7299 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7300 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7301 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7302 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7303 | MockWrite( |
| 7304 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7305 | "Host: www.example.org\r\n" |
| 7306 | "Proxy-Connection: keep-alive\r\n" |
| 7307 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7308 | }; |
| 7309 | MockRead data_reads[] = { |
| 7310 | // Return an error, so the transaction stops here (this test isn't |
| 7311 | // interested in the rest). |
| 7312 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7313 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7314 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7315 | }; |
| 7316 | |
| 7317 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7318 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7321 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7323 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7324 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7325 | |
| 7326 | rv = callback.WaitForResult(); |
| 7327 | EXPECT_EQ(OK, rv); |
| 7328 | } |
| 7329 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7330 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7331 | HttpRequestInfo request; |
| 7332 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7333 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7334 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7335 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7336 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7337 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7338 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7339 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7340 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7341 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7342 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7343 | MockWrite( |
| 7344 | "GET / HTTP/1.1\r\n" |
| 7345 | "Host: www.example.org\r\n" |
| 7346 | "Connection: keep-alive\r\n" |
| 7347 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7348 | }; |
| 7349 | |
| 7350 | // Lastly, the server responds with the actual content. |
| 7351 | MockRead data_reads[] = { |
| 7352 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7354 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7355 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7356 | }; |
| 7357 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7358 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7359 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7362 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7364 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7365 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7366 | |
| 7367 | rv = callback.WaitForResult(); |
| 7368 | EXPECT_EQ(OK, rv); |
| 7369 | } |
| 7370 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7371 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7372 | HttpRequestInfo request; |
| 7373 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7374 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7375 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7376 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7377 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7379 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7380 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7381 | MockWrite( |
| 7382 | "POST / HTTP/1.1\r\n" |
| 7383 | "Host: www.example.org\r\n" |
| 7384 | "Connection: keep-alive\r\n" |
| 7385 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7386 | }; |
| 7387 | |
| 7388 | // Lastly, the server responds with the actual content. |
| 7389 | MockRead data_reads[] = { |
| 7390 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7392 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7394 | }; |
| 7395 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7396 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7397 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7400 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7404 | |
| 7405 | rv = callback.WaitForResult(); |
| 7406 | EXPECT_EQ(OK, rv); |
| 7407 | } |
| 7408 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7409 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7410 | HttpRequestInfo request; |
| 7411 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7412 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7413 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7414 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7415 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7416 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7417 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7418 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7419 | MockWrite( |
| 7420 | "PUT / HTTP/1.1\r\n" |
| 7421 | "Host: www.example.org\r\n" |
| 7422 | "Connection: keep-alive\r\n" |
| 7423 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7424 | }; |
| 7425 | |
| 7426 | // Lastly, the server responds with the actual content. |
| 7427 | MockRead data_reads[] = { |
| 7428 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7429 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7430 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7432 | }; |
| 7433 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7434 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7435 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7436 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7438 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7440 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7442 | |
| 7443 | rv = callback.WaitForResult(); |
| 7444 | EXPECT_EQ(OK, rv); |
| 7445 | } |
| 7446 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7447 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7448 | HttpRequestInfo request; |
| 7449 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7450 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7451 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7452 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7453 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7454 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7455 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7456 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 7457 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7458 | "Host: www.example.org\r\n" |
| 7459 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7460 | }; |
| 7461 | |
| 7462 | // Lastly, the server responds with the actual content. |
| 7463 | MockRead data_reads[] = { |
| 7464 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7465 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7466 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7467 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7468 | }; |
| 7469 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7470 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7471 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7472 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7474 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7476 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7477 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7478 | |
| 7479 | rv = callback.WaitForResult(); |
| 7480 | EXPECT_EQ(OK, rv); |
| 7481 | } |
| 7482 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7483 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7484 | HttpRequestInfo request; |
| 7485 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7486 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7487 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7488 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7489 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7490 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7491 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7492 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7493 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7494 | MockWrite( |
| 7495 | "GET / HTTP/1.1\r\n" |
| 7496 | "Host: www.example.org\r\n" |
| 7497 | "Connection: keep-alive\r\n" |
| 7498 | "Pragma: no-cache\r\n" |
| 7499 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7500 | }; |
| 7501 | |
| 7502 | // Lastly, the server responds with the actual content. |
| 7503 | MockRead data_reads[] = { |
| 7504 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7505 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7506 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7508 | }; |
| 7509 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7511 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7514 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7516 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7517 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7518 | |
| 7519 | rv = callback.WaitForResult(); |
| 7520 | EXPECT_EQ(OK, rv); |
| 7521 | } |
| 7522 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7523 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7524 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7525 | HttpRequestInfo request; |
| 7526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7527 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7528 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7529 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7530 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7531 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7532 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7533 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7534 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7535 | MockWrite( |
| 7536 | "GET / HTTP/1.1\r\n" |
| 7537 | "Host: www.example.org\r\n" |
| 7538 | "Connection: keep-alive\r\n" |
| 7539 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7540 | }; |
| 7541 | |
| 7542 | // Lastly, the server responds with the actual content. |
| 7543 | MockRead data_reads[] = { |
| 7544 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7545 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7546 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7547 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7548 | }; |
| 7549 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7550 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7551 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7554 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7556 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7557 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7558 | |
| 7559 | rv = callback.WaitForResult(); |
| 7560 | EXPECT_EQ(OK, rv); |
| 7561 | } |
| 7562 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7563 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7564 | HttpRequestInfo request; |
| 7565 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7566 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7567 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7568 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7569 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7570 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7571 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7572 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7573 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7574 | MockWrite( |
| 7575 | "GET / HTTP/1.1\r\n" |
| 7576 | "Host: www.example.org\r\n" |
| 7577 | "Connection: keep-alive\r\n" |
| 7578 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7579 | }; |
| 7580 | |
| 7581 | // Lastly, the server responds with the actual content. |
| 7582 | MockRead data_reads[] = { |
| 7583 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7584 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7585 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7586 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7587 | }; |
| 7588 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7589 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7590 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7593 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7595 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7596 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7597 | |
| 7598 | rv = callback.WaitForResult(); |
| 7599 | EXPECT_EQ(OK, rv); |
| 7600 | } |
| 7601 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7602 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7603 | HttpRequestInfo request; |
| 7604 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7605 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7606 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7607 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7608 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7609 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7610 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7611 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7612 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7613 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7614 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7615 | MockWrite( |
| 7616 | "GET / HTTP/1.1\r\n" |
| 7617 | "Host: www.example.org\r\n" |
| 7618 | "Connection: keep-alive\r\n" |
| 7619 | "referer: www.foo.com\r\n" |
| 7620 | "hEllo: Kitty\r\n" |
| 7621 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7622 | }; |
| 7623 | |
| 7624 | // Lastly, the server responds with the actual content. |
| 7625 | MockRead data_reads[] = { |
| 7626 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7628 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7630 | }; |
| 7631 | |
| 7632 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7633 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7635 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7636 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7638 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7640 | |
| 7641 | rv = callback.WaitForResult(); |
| 7642 | EXPECT_EQ(OK, rv); |
| 7643 | } |
| 7644 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7645 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7646 | HttpRequestInfo request; |
| 7647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7648 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7649 | request.load_flags = 0; |
| 7650 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7651 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7652 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7653 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7654 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7655 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7656 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7657 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7659 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7660 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7661 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7662 | |
| 7663 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7664 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7665 | MockWrite( |
| 7666 | "GET / HTTP/1.1\r\n" |
| 7667 | "Host: www.example.org\r\n" |
| 7668 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7669 | |
| 7670 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7671 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7672 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7673 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7674 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7675 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7676 | }; |
| 7677 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7678 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7679 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7680 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7681 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7682 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7684 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7686 | |
| 7687 | rv = callback.WaitForResult(); |
| 7688 | EXPECT_EQ(OK, rv); |
| 7689 | |
| 7690 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7691 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7692 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7693 | LoadTimingInfo load_timing_info; |
| 7694 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7695 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7696 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7697 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7698 | std::string response_text; |
| 7699 | rv = ReadTransaction(trans.get(), &response_text); |
| 7700 | EXPECT_EQ(OK, rv); |
| 7701 | EXPECT_EQ("Payload", response_text); |
| 7702 | } |
| 7703 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7704 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7705 | HttpRequestInfo request; |
| 7706 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7707 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7708 | request.load_flags = 0; |
| 7709 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7710 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7711 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7712 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7713 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7714 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7715 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7716 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7718 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7719 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7720 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7721 | |
| 7722 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7723 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7724 | arraysize(write_buffer)), |
| 7725 | MockWrite( |
| 7726 | "GET / HTTP/1.1\r\n" |
| 7727 | "Host: www.example.org\r\n" |
| 7728 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7729 | |
| 7730 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7731 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7732 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7734 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7735 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7736 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7737 | }; |
| 7738 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7740 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7742 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7743 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7746 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7748 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7749 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7750 | |
| 7751 | rv = callback.WaitForResult(); |
| 7752 | EXPECT_EQ(OK, rv); |
| 7753 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7754 | LoadTimingInfo load_timing_info; |
| 7755 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7756 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7757 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7758 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7759 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7760 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7761 | |
| 7762 | std::string response_text; |
| 7763 | rv = ReadTransaction(trans.get(), &response_text); |
| 7764 | EXPECT_EQ(OK, rv); |
| 7765 | EXPECT_EQ("Payload", response_text); |
| 7766 | } |
| 7767 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7768 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7769 | HttpRequestInfo request; |
| 7770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7771 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7772 | request.load_flags = 0; |
| 7773 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7774 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7775 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7776 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7777 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7778 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7779 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7780 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7782 | |
| 7783 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7784 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7785 | |
| 7786 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7787 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7788 | MockWrite( |
| 7789 | "GET / HTTP/1.1\r\n" |
| 7790 | "Host: www.example.org\r\n" |
| 7791 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7792 | |
| 7793 | MockRead data_reads[] = { |
| 7794 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7795 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7796 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7797 | MockRead("Payload"), |
| 7798 | MockRead(SYNCHRONOUS, OK) |
| 7799 | }; |
| 7800 | |
| 7801 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7802 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7804 | |
| 7805 | TestCompletionCallback callback; |
| 7806 | |
| 7807 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7809 | |
| 7810 | rv = callback.WaitForResult(); |
| 7811 | EXPECT_EQ(OK, rv); |
| 7812 | |
| 7813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7814 | ASSERT_TRUE(response != NULL); |
| 7815 | |
| 7816 | LoadTimingInfo load_timing_info; |
| 7817 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7818 | TestLoadTimingNotReused(load_timing_info, |
| 7819 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7820 | |
| 7821 | std::string response_text; |
| 7822 | rv = ReadTransaction(trans.get(), &response_text); |
| 7823 | EXPECT_EQ(OK, rv); |
| 7824 | EXPECT_EQ("Payload", response_text); |
| 7825 | } |
| 7826 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7827 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7828 | HttpRequestInfo request; |
| 7829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7830 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7831 | request.load_flags = 0; |
| 7832 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7833 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7834 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7835 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7836 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7837 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7838 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7839 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7841 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7842 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7843 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7844 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7845 | 0x05, // Version |
| 7846 | 0x01, // Command (CONNECT) |
| 7847 | 0x00, // Reserved. |
| 7848 | 0x03, // Address type (DOMAINNAME). |
| 7849 | 0x0F, // Length of domain (15) |
| 7850 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7851 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7852 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7853 | const char kSOCKS5OkResponse[] = |
| 7854 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7855 | |
| 7856 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7857 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7858 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7859 | MockWrite( |
| 7860 | "GET / HTTP/1.1\r\n" |
| 7861 | "Host: www.example.org\r\n" |
| 7862 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7863 | |
| 7864 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7865 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7866 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7867 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7868 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7869 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7870 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7871 | }; |
| 7872 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7873 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7874 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7877 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7879 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7880 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7881 | |
| 7882 | rv = callback.WaitForResult(); |
| 7883 | EXPECT_EQ(OK, rv); |
| 7884 | |
| 7885 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7886 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7887 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7888 | LoadTimingInfo load_timing_info; |
| 7889 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7890 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7891 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7892 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7893 | std::string response_text; |
| 7894 | rv = ReadTransaction(trans.get(), &response_text); |
| 7895 | EXPECT_EQ(OK, rv); |
| 7896 | EXPECT_EQ("Payload", response_text); |
| 7897 | } |
| 7898 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7899 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7900 | HttpRequestInfo request; |
| 7901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7902 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7903 | request.load_flags = 0; |
| 7904 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7905 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7906 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7907 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7908 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7909 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7910 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7911 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7912 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7913 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7914 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7915 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7916 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7917 | 0x05, // Version |
| 7918 | 0x01, // Command (CONNECT) |
| 7919 | 0x00, // Reserved. |
| 7920 | 0x03, // Address type (DOMAINNAME). |
| 7921 | 0x0F, // Length of domain (15) |
| 7922 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7923 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7924 | }; |
| 7925 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7926 | const char kSOCKS5OkResponse[] = |
| 7927 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7928 | |
| 7929 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7930 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7931 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7932 | arraysize(kSOCKS5OkRequest)), |
| 7933 | MockWrite( |
| 7934 | "GET / HTTP/1.1\r\n" |
| 7935 | "Host: www.example.org\r\n" |
| 7936 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7937 | |
| 7938 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7939 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7940 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7941 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7942 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7943 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7944 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7945 | }; |
| 7946 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7947 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7948 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7949 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7950 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7951 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7952 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7954 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7956 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7958 | |
| 7959 | rv = callback.WaitForResult(); |
| 7960 | EXPECT_EQ(OK, rv); |
| 7961 | |
| 7962 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7963 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7964 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7965 | LoadTimingInfo load_timing_info; |
| 7966 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7967 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7968 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7969 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7970 | std::string response_text; |
| 7971 | rv = ReadTransaction(trans.get(), &response_text); |
| 7972 | EXPECT_EQ(OK, rv); |
| 7973 | EXPECT_EQ("Payload", response_text); |
| 7974 | } |
| 7975 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7976 | namespace { |
| 7977 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7978 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7979 | |
| 7980 | struct GroupNameTest { |
| 7981 | std::string proxy_server; |
| 7982 | std::string url; |
| 7983 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7984 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7985 | }; |
| 7986 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7987 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7988 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7989 | SpdySessionDependencies* session_deps_) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 7990 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7991 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7992 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7993 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7994 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7995 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7996 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7997 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7998 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 7999 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8000 | |
| 8001 | return session; |
| 8002 | } |
| 8003 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8004 | int GroupNameTransactionHelper( |
| 8005 | const std::string& url, |
| 8006 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8007 | HttpRequestInfo request; |
| 8008 | request.method = "GET"; |
| 8009 | request.url = GURL(url); |
| 8010 | request.load_flags = 0; |
| 8011 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8012 | scoped_ptr<HttpTransaction> trans( |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8013 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8015 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8016 | |
| 8017 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8018 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8019 | } |
| 8020 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8021 | } // namespace |
| 8022 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8023 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8024 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8025 | { |
| 8026 | "", // unused |
| 8027 | "http://www.example.org/direct", |
| 8028 | "www.example.org:80", |
| 8029 | false, |
| 8030 | }, |
| 8031 | { |
| 8032 | "", // unused |
| 8033 | "http://[2001:1418:13:1::25]/direct", |
| 8034 | "[2001:1418:13:1::25]:80", |
| 8035 | false, |
| 8036 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8037 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8038 | // SSL Tests |
| 8039 | { |
| 8040 | "", // unused |
| 8041 | "https://www.example.org/direct_ssl", |
| 8042 | "ssl/www.example.org:443", |
| 8043 | true, |
| 8044 | }, |
| 8045 | { |
| 8046 | "", // unused |
| 8047 | "https://[2001:1418:13:1::25]/direct", |
| 8048 | "ssl/[2001:1418:13:1::25]:443", |
| 8049 | true, |
| 8050 | }, |
| 8051 | { |
| 8052 | "", // unused |
| 8053 | "http://host.with.alternate/direct", |
| 8054 | "ssl/host.with.alternate:443", |
| 8055 | true, |
| 8056 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8057 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8058 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8059 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8060 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8061 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8062 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8063 | ProxyService::CreateFixed(tests[i].proxy_server)); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8064 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8065 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8066 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8067 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8068 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8069 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8070 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8071 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8072 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8073 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8074 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8075 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8076 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8077 | |
| 8078 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8079 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8080 | if (tests[i].ssl) |
| 8081 | EXPECT_EQ(tests[i].expected_group_name, |
| 8082 | ssl_conn_pool->last_group_name_received()); |
| 8083 | else |
| 8084 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8085 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8086 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8087 | } |
| 8088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8089 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8090 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8091 | { |
| 8092 | "http_proxy", |
| 8093 | "http://www.example.org/http_proxy_normal", |
| 8094 | "www.example.org:80", |
| 8095 | false, |
| 8096 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8097 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8098 | // SSL Tests |
| 8099 | { |
| 8100 | "http_proxy", |
| 8101 | "https://www.example.org/http_connect_ssl", |
| 8102 | "ssl/www.example.org:443", |
| 8103 | true, |
| 8104 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8105 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8106 | { |
| 8107 | "http_proxy", |
| 8108 | "http://host.with.alternate/direct", |
| 8109 | "ssl/host.with.alternate:443", |
| 8110 | true, |
| 8111 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8112 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8113 | { |
| 8114 | "http_proxy", |
| 8115 | "ftp://ftp.google.com/http_proxy_normal", |
| 8116 | "ftp/ftp.google.com:21", |
| 8117 | false, |
| 8118 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8119 | }; |
| 8120 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8121 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8122 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8123 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8124 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8125 | ProxyService::CreateFixed(tests[i].proxy_server)); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8126 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8127 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8128 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8129 | HttpNetworkSessionPeer peer(session); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8130 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8131 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8132 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8133 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8134 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8135 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8136 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8137 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8138 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8139 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8140 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8141 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8142 | |
| 8143 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8144 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8145 | if (tests[i].ssl) |
| 8146 | EXPECT_EQ(tests[i].expected_group_name, |
| 8147 | ssl_conn_pool->last_group_name_received()); |
| 8148 | else |
| 8149 | EXPECT_EQ(tests[i].expected_group_name, |
| 8150 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8151 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8152 | } |
| 8153 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8154 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8155 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8156 | { |
| 8157 | "socks4://socks_proxy:1080", |
| 8158 | "http://www.example.org/socks4_direct", |
| 8159 | "socks4/www.example.org:80", |
| 8160 | false, |
| 8161 | }, |
| 8162 | { |
| 8163 | "socks5://socks_proxy:1080", |
| 8164 | "http://www.example.org/socks5_direct", |
| 8165 | "socks5/www.example.org:80", |
| 8166 | false, |
| 8167 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8168 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8169 | // SSL Tests |
| 8170 | { |
| 8171 | "socks4://socks_proxy:1080", |
| 8172 | "https://www.example.org/socks4_ssl", |
| 8173 | "socks4/ssl/www.example.org:443", |
| 8174 | true, |
| 8175 | }, |
| 8176 | { |
| 8177 | "socks5://socks_proxy:1080", |
| 8178 | "https://www.example.org/socks5_ssl", |
| 8179 | "socks5/ssl/www.example.org:443", |
| 8180 | true, |
| 8181 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8182 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8183 | { |
| 8184 | "socks4://socks_proxy:1080", |
| 8185 | "http://host.with.alternate/direct", |
| 8186 | "socks4/ssl/host.with.alternate:443", |
| 8187 | true, |
| 8188 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8189 | }; |
| 8190 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8191 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8192 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8193 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8194 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8195 | ProxyService::CreateFixed(tests[i].proxy_server)); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8196 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8197 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8198 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8199 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8200 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8201 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8202 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8203 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8204 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8205 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8206 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8207 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8208 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8209 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8210 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8211 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8212 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8213 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8214 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8215 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8216 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8217 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8218 | if (tests[i].ssl) |
| 8219 | EXPECT_EQ(tests[i].expected_group_name, |
| 8220 | ssl_conn_pool->last_group_name_received()); |
| 8221 | else |
| 8222 | EXPECT_EQ(tests[i].expected_group_name, |
| 8223 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8224 | } |
| 8225 | } |
| 8226 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8227 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8228 | HttpRequestInfo request; |
| 8229 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8230 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8231 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8232 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8233 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8234 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8235 | // This simulates failure resolving all hostnames; that means we will fail |
| 8236 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8237 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8238 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8239 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8240 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8243 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8245 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8246 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8247 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8248 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8249 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8250 | } |
| 8251 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8252 | // Base test to make sure that when the load flags for a request specify to |
| 8253 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8254 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8255 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8256 | // Issue a request, asking to bypass the cache(s). |
| 8257 | HttpRequestInfo request; |
| 8258 | request.method = "GET"; |
| 8259 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8260 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8261 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8262 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8263 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8264 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8266 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8267 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8268 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8269 | // 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] | 8270 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8271 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8272 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8273 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8274 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8276 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8277 | EXPECT_EQ(OK, rv); |
| 8278 | |
| 8279 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8280 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8281 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8282 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8283 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8284 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8285 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8286 | // 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] | 8287 | // we can tell if the next lookup hit the cache, or the "network". |
| 8288 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8289 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8290 | |
| 8291 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8292 | // 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] | 8293 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8294 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8296 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8297 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8298 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8299 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8300 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8301 | |
| 8302 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8303 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8304 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8305 | } |
| 8306 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8307 | // There are multiple load flags that should trigger the host cache bypass. |
| 8308 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8309 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8310 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8311 | } |
| 8312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8313 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8314 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8315 | } |
| 8316 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8317 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8318 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8319 | } |
| 8320 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8321 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8322 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8323 | HttpRequestInfo request; |
| 8324 | request.method = "GET"; |
| 8325 | request.url = GURL("http://www.foo.com/"); |
| 8326 | request.load_flags = 0; |
| 8327 | |
| 8328 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8329 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8330 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8331 | StaticSocketDataProvider data(NULL, 0, |
| 8332 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8334 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8336 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8337 | |
| 8338 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8339 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8341 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8342 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8343 | |
| 8344 | rv = callback.WaitForResult(); |
| 8345 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8346 | } |
| 8347 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8348 | // Check that a connection closed after the start of the headers finishes ok. |
| 8349 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | HttpRequestInfo request; |
| 8351 | request.method = "GET"; |
| 8352 | request.url = GURL("http://www.foo.com/"); |
| 8353 | request.load_flags = 0; |
| 8354 | |
| 8355 | MockRead data_reads[] = { |
| 8356 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8357 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8358 | }; |
| 8359 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8360 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8362 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8364 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8365 | |
| 8366 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8367 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8369 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8371 | |
| 8372 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8373 | EXPECT_EQ(OK, rv); |
| 8374 | |
| 8375 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8376 | ASSERT_TRUE(response != NULL); |
| 8377 | |
| 8378 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8379 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8380 | |
| 8381 | std::string response_data; |
| 8382 | rv = ReadTransaction(trans.get(), &response_data); |
| 8383 | EXPECT_EQ(OK, rv); |
| 8384 | EXPECT_EQ("", response_data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8385 | } |
| 8386 | |
| 8387 | // Make sure that a dropped connection while draining the body for auth |
| 8388 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8389 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8390 | HttpRequestInfo request; |
| 8391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8392 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8393 | request.load_flags = 0; |
| 8394 | |
| 8395 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8396 | MockWrite( |
| 8397 | "GET / HTTP/1.1\r\n" |
| 8398 | "Host: www.example.org\r\n" |
| 8399 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8400 | }; |
| 8401 | |
| 8402 | MockRead data_reads1[] = { |
| 8403 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8404 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8406 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8407 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8408 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8409 | }; |
| 8410 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8411 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8412 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8413 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8414 | |
| 8415 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8416 | // be issuing -- the final header line contains the credentials. |
| 8417 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8418 | MockWrite( |
| 8419 | "GET / HTTP/1.1\r\n" |
| 8420 | "Host: www.example.org\r\n" |
| 8421 | "Connection: keep-alive\r\n" |
| 8422 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8423 | }; |
| 8424 | |
| 8425 | // Lastly, the server responds with the actual content. |
| 8426 | MockRead data_reads2[] = { |
| 8427 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8428 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8429 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8430 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8431 | }; |
| 8432 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8433 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8434 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8435 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8436 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8438 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8439 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8440 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8443 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8445 | |
| 8446 | rv = callback1.WaitForResult(); |
| 8447 | EXPECT_EQ(OK, rv); |
| 8448 | |
| 8449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8450 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8451 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8453 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8455 | rv = trans->RestartWithAuth( |
| 8456 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8457 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8458 | |
| 8459 | rv = callback2.WaitForResult(); |
| 8460 | EXPECT_EQ(OK, rv); |
| 8461 | |
| 8462 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8463 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8464 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8465 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8466 | } |
| 8467 | |
| 8468 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8469 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8470 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8471 | |
| 8472 | HttpRequestInfo request; |
| 8473 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8474 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8475 | request.load_flags = 0; |
| 8476 | |
| 8477 | MockRead proxy_reads[] = { |
| 8478 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8479 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8480 | }; |
| 8481 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8482 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8483 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8484 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8485 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8488 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8489 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8490 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8491 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8492 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8493 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8494 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8496 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8498 | |
| 8499 | rv = callback.WaitForResult(); |
| 8500 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8501 | } |
| 8502 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8503 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8504 | HttpRequestInfo request; |
| 8505 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8507 | request.load_flags = 0; |
| 8508 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8509 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8510 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8512 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8513 | MockRead data_reads[] = { |
| 8514 | 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] | 8515 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8516 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8517 | |
| 8518 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8519 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8521 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8522 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8523 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8525 | |
| 8526 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8527 | |
| 8528 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8529 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8530 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8531 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8532 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8533 | |
| 8534 | std::string response_data; |
| 8535 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8536 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8537 | } |
| 8538 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8539 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8540 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8541 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8542 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8543 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8544 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8545 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8546 | ScopedVector<UploadElementReader> element_readers; |
| 8547 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8548 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8549 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8550 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8551 | |
| 8552 | HttpRequestInfo request; |
| 8553 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8554 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8555 | request.upload_data_stream = &upload_data_stream; |
| 8556 | request.load_flags = 0; |
| 8557 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8558 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8559 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8560 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8561 | |
| 8562 | MockRead data_reads[] = { |
| 8563 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8564 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8565 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8566 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8567 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8568 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8570 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8572 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8574 | |
| 8575 | rv = callback.WaitForResult(); |
| 8576 | EXPECT_EQ(OK, rv); |
| 8577 | |
| 8578 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8579 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8580 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8581 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8582 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8583 | |
| 8584 | std::string response_data; |
| 8585 | rv = ReadTransaction(trans.get(), &response_data); |
| 8586 | EXPECT_EQ(OK, rv); |
| 8587 | EXPECT_EQ("hello world", response_data); |
| 8588 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8589 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8590 | } |
| 8591 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8592 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8593 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8594 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8595 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8596 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8597 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8598 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8599 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8600 | ScopedVector<UploadElementReader> element_readers; |
| 8601 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8602 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8603 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8604 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8605 | |
| 8606 | HttpRequestInfo request; |
| 8607 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8608 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8609 | request.upload_data_stream = &upload_data_stream; |
| 8610 | request.load_flags = 0; |
| 8611 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8612 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8613 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8614 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8616 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8617 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8620 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8622 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8623 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8624 | |
| 8625 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8626 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8627 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8628 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8629 | } |
| 8630 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8631 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8632 | class FakeUploadElementReader : public UploadElementReader { |
| 8633 | public: |
| 8634 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8635 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8636 | |
| 8637 | const CompletionCallback& callback() const { return callback_; } |
| 8638 | |
| 8639 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8640 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8641 | callback_ = callback; |
| 8642 | return ERR_IO_PENDING; |
| 8643 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8644 | uint64 GetContentLength() const override { return 0; } |
| 8645 | uint64 BytesRemaining() const override { return 0; } |
| 8646 | int Read(IOBuffer* buf, |
| 8647 | int buf_length, |
| 8648 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8649 | return ERR_FAILED; |
| 8650 | } |
| 8651 | |
| 8652 | private: |
| 8653 | CompletionCallback callback_; |
| 8654 | }; |
| 8655 | |
| 8656 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8657 | ScopedVector<UploadElementReader> element_readers; |
| 8658 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8659 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8660 | |
| 8661 | HttpRequestInfo request; |
| 8662 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8663 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8664 | request.upload_data_stream = &upload_data_stream; |
| 8665 | request.load_flags = 0; |
| 8666 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8667 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8668 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8669 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8670 | |
| 8671 | StaticSocketDataProvider data; |
| 8672 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8673 | |
| 8674 | TestCompletionCallback callback; |
| 8675 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8677 | base::MessageLoop::current()->RunUntilIdle(); |
| 8678 | |
| 8679 | // Transaction is pending on request body initialization. |
| 8680 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8681 | |
| 8682 | // Return Init()'s result after the transaction gets destroyed. |
| 8683 | trans.reset(); |
| 8684 | fake_reader->callback().Run(OK); // Should not crash. |
| 8685 | } |
| 8686 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8687 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8688 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8689 | HttpRequestInfo request; |
| 8690 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8691 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8692 | request.load_flags = 0; |
| 8693 | |
| 8694 | // First transaction will request a resource and receive a Basic challenge |
| 8695 | // with realm="first_realm". |
| 8696 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8697 | MockWrite( |
| 8698 | "GET / HTTP/1.1\r\n" |
| 8699 | "Host: www.example.org\r\n" |
| 8700 | "Connection: keep-alive\r\n" |
| 8701 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8702 | }; |
| 8703 | MockRead data_reads1[] = { |
| 8704 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8705 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8706 | "\r\n"), |
| 8707 | }; |
| 8708 | |
| 8709 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8710 | // for first_realm. The server will reject and provide a challenge with |
| 8711 | // second_realm. |
| 8712 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8713 | MockWrite( |
| 8714 | "GET / HTTP/1.1\r\n" |
| 8715 | "Host: www.example.org\r\n" |
| 8716 | "Connection: keep-alive\r\n" |
| 8717 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8718 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8719 | }; |
| 8720 | MockRead data_reads2[] = { |
| 8721 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8722 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8723 | "\r\n"), |
| 8724 | }; |
| 8725 | |
| 8726 | // This again fails, and goes back to first_realm. Make sure that the |
| 8727 | // entry is removed from cache. |
| 8728 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8729 | MockWrite( |
| 8730 | "GET / HTTP/1.1\r\n" |
| 8731 | "Host: www.example.org\r\n" |
| 8732 | "Connection: keep-alive\r\n" |
| 8733 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8734 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8735 | }; |
| 8736 | MockRead data_reads3[] = { |
| 8737 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8738 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8739 | "\r\n"), |
| 8740 | }; |
| 8741 | |
| 8742 | // Try one last time (with the correct password) and get the resource. |
| 8743 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8744 | MockWrite( |
| 8745 | "GET / HTTP/1.1\r\n" |
| 8746 | "Host: www.example.org\r\n" |
| 8747 | "Connection: keep-alive\r\n" |
| 8748 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8749 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8750 | }; |
| 8751 | MockRead data_reads4[] = { |
| 8752 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8753 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8754 | "Content-Length: 5\r\n" |
| 8755 | "\r\n" |
| 8756 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8757 | }; |
| 8758 | |
| 8759 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8760 | data_writes1, arraysize(data_writes1)); |
| 8761 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8762 | data_writes2, arraysize(data_writes2)); |
| 8763 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8764 | data_writes3, arraysize(data_writes3)); |
| 8765 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8766 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8768 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8769 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8770 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8772 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8773 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8774 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8775 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8776 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8777 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8778 | // Issue the first request with Authorize headers. There should be a |
| 8779 | // password prompt for first_realm waiting to be filled in after the |
| 8780 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8781 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8782 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8783 | rv = callback1.WaitForResult(); |
| 8784 | EXPECT_EQ(OK, rv); |
| 8785 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8786 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8787 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8788 | ASSERT_FALSE(challenge == NULL); |
| 8789 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8790 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8791 | EXPECT_EQ("first_realm", challenge->realm); |
| 8792 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8793 | |
| 8794 | // Issue the second request with an incorrect password. There should be a |
| 8795 | // password prompt for second_realm waiting to be filled in after the |
| 8796 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8797 | TestCompletionCallback callback2; |
| 8798 | rv = trans->RestartWithAuth( |
| 8799 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8801 | rv = callback2.WaitForResult(); |
| 8802 | EXPECT_EQ(OK, rv); |
| 8803 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8804 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8805 | challenge = response->auth_challenge.get(); |
| 8806 | ASSERT_FALSE(challenge == NULL); |
| 8807 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8808 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8809 | EXPECT_EQ("second_realm", challenge->realm); |
| 8810 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8811 | |
| 8812 | // Issue the third request with another incorrect password. There should be |
| 8813 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8814 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8815 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8816 | TestCompletionCallback callback3; |
| 8817 | rv = trans->RestartWithAuth( |
| 8818 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8820 | rv = callback3.WaitForResult(); |
| 8821 | EXPECT_EQ(OK, rv); |
| 8822 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8823 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8824 | challenge = response->auth_challenge.get(); |
| 8825 | ASSERT_FALSE(challenge == NULL); |
| 8826 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8827 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8828 | EXPECT_EQ("first_realm", challenge->realm); |
| 8829 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8830 | |
| 8831 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8832 | TestCompletionCallback callback4; |
| 8833 | rv = trans->RestartWithAuth( |
| 8834 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8836 | rv = callback4.WaitForResult(); |
| 8837 | EXPECT_EQ(OK, rv); |
| 8838 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8839 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8840 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8841 | } |
| 8842 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8843 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 8844 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8845 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8846 | |
| 8847 | std::string alternative_service_http_header = |
| 8848 | GetAlternativeServiceHttpHeader(); |
| 8849 | |
| 8850 | MockRead data_reads[] = { |
| 8851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8852 | MockRead(alternative_service_http_header.c_str()), |
| 8853 | MockRead("\r\n"), |
| 8854 | MockRead("hello world"), |
| 8855 | MockRead(SYNCHRONOUS, OK), |
| 8856 | }; |
| 8857 | |
| 8858 | HttpRequestInfo request; |
| 8859 | request.method = "GET"; |
| 8860 | request.url = GURL("http://www.example.org/"); |
| 8861 | request.load_flags = 0; |
| 8862 | |
| 8863 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8864 | |
| 8865 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8866 | |
| 8867 | TestCompletionCallback callback; |
| 8868 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8869 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8870 | scoped_ptr<HttpTransaction> trans( |
| 8871 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8872 | |
| 8873 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8875 | |
| 8876 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8877 | HttpServerProperties& http_server_properties = |
| 8878 | *session->http_server_properties(); |
| 8879 | AlternativeServiceVector alternative_service_vector = |
| 8880 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8881 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8882 | |
| 8883 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8884 | |
| 8885 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8886 | ASSERT_TRUE(response != NULL); |
| 8887 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8888 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8889 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8890 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8891 | |
| 8892 | std::string response_data; |
| 8893 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8894 | EXPECT_EQ("hello world", response_data); |
| 8895 | |
| 8896 | alternative_service_vector = |
| 8897 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8898 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8899 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8900 | alternative_service_vector[0].protocol); |
| 8901 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8902 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8903 | } |
| 8904 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8905 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 8906 | // is false. |
| 8907 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 8908 | session_deps_.next_protos = SpdyNextProtos(); |
| 8909 | session_deps_.use_alternative_services = false; |
| 8910 | |
| 8911 | std::string alternative_service_http_header = |
| 8912 | GetAlternativeServiceHttpHeader(); |
| 8913 | |
| 8914 | MockRead data_reads[] = { |
| 8915 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8916 | MockRead(alternative_service_http_header.c_str()), |
| 8917 | MockRead("\r\n"), |
| 8918 | MockRead("hello world"), |
| 8919 | MockRead(SYNCHRONOUS, OK), |
| 8920 | }; |
| 8921 | |
| 8922 | HttpRequestInfo request; |
| 8923 | request.method = "GET"; |
| 8924 | request.url = GURL("http://www.example.org/"); |
| 8925 | request.load_flags = 0; |
| 8926 | |
| 8927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 8928 | |
| 8929 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8930 | |
| 8931 | TestCompletionCallback callback; |
| 8932 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8933 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8934 | scoped_ptr<HttpTransaction> trans( |
| 8935 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8936 | |
| 8937 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8938 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8939 | |
| 8940 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8941 | HttpServerProperties& http_server_properties = |
| 8942 | *session->http_server_properties(); |
| 8943 | AlternativeServiceVector alternative_service_vector = |
| 8944 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8945 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8946 | |
| 8947 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8948 | |
| 8949 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8950 | ASSERT_TRUE(response != nullptr); |
| 8951 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 8952 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8953 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8954 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8955 | |
| 8956 | std::string response_data; |
| 8957 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8958 | EXPECT_EQ("hello world", response_data); |
| 8959 | |
| 8960 | alternative_service_vector = |
| 8961 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8962 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8963 | } |
| 8964 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8965 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 8966 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8967 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8968 | |
| 8969 | MockRead data_reads[] = { |
| 8970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8971 | MockRead("Alt-Svc: "), |
| 8972 | MockRead(GetAlternateProtocolFromParam()), |
| 8973 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 8974 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 8975 | MockRead("hello world"), |
| 8976 | MockRead(SYNCHRONOUS, OK), |
| 8977 | }; |
| 8978 | |
| 8979 | HttpRequestInfo request; |
| 8980 | request.method = "GET"; |
| 8981 | request.url = GURL("http://www.example.org/"); |
| 8982 | request.load_flags = 0; |
| 8983 | |
| 8984 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8985 | |
| 8986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8987 | |
| 8988 | TestCompletionCallback callback; |
| 8989 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 8990 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8991 | scoped_ptr<HttpTransaction> trans( |
| 8992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8993 | |
| 8994 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8995 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8996 | |
| 8997 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8998 | HttpServerProperties& http_server_properties = |
| 8999 | *session->http_server_properties(); |
| 9000 | AlternativeServiceVector alternative_service_vector = |
| 9001 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9002 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9003 | |
| 9004 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9005 | |
| 9006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9007 | ASSERT_TRUE(response != NULL); |
| 9008 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9009 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9010 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9011 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9012 | |
| 9013 | std::string response_data; |
| 9014 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9015 | EXPECT_EQ("hello world", response_data); |
| 9016 | |
| 9017 | alternative_service_vector = |
| 9018 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9019 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 9020 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9021 | alternative_service_vector[0].protocol); |
| 9022 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9023 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9024 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9025 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9026 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9027 | } |
| 9028 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9029 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9030 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9031 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9032 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9033 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9034 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9035 | std::string alternate_protocol_http_header = |
| 9036 | GetAlternateProtocolHttpHeader(); |
| 9037 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9038 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9039 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9040 | MockRead(alternate_protocol_http_header.c_str()), |
| 9041 | MockRead("\r\n"), |
| 9042 | MockRead("hello world"), |
| 9043 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9044 | }; |
| 9045 | |
| 9046 | HttpRequestInfo request; |
| 9047 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9048 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9049 | request.load_flags = 0; |
| 9050 | |
| 9051 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9052 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9055 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9056 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9057 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9058 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9061 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9062 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9063 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9064 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9065 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9066 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9067 | AlternativeServiceVector alternative_service_vector = |
| 9068 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9069 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9070 | |
| 9071 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9072 | |
| 9073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9074 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9075 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9077 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9078 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9079 | |
| 9080 | std::string response_data; |
| 9081 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9082 | EXPECT_EQ("hello world", response_data); |
| 9083 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9084 | alternative_service_vector = |
| 9085 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9086 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9087 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9088 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9089 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9090 | } |
| 9091 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9092 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9093 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9094 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9095 | |
| 9096 | MockRead data_reads[] = { |
| 9097 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9098 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9099 | MockRead("hello world"), |
| 9100 | MockRead(SYNCHRONOUS, OK), |
| 9101 | }; |
| 9102 | |
| 9103 | HttpRequestInfo request; |
| 9104 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9105 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9106 | request.load_flags = 0; |
| 9107 | |
| 9108 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9109 | |
| 9110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9111 | |
| 9112 | TestCompletionCallback callback; |
| 9113 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9114 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9115 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9116 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9117 | HttpServerProperties& http_server_properties = |
| 9118 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9119 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9120 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9121 | http_server_properties.SetAlternativeService( |
| 9122 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9123 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9124 | AlternativeServiceVector alternative_service_vector = |
| 9125 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9126 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9127 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9128 | |
| 9129 | scoped_ptr<HttpTransaction> trans( |
| 9130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9131 | |
| 9132 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9134 | |
| 9135 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9136 | |
| 9137 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9138 | ASSERT_TRUE(response != NULL); |
| 9139 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9140 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9141 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9142 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9143 | |
| 9144 | std::string response_data; |
| 9145 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9146 | EXPECT_EQ("hello world", response_data); |
| 9147 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9148 | alternative_service_vector = |
| 9149 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9150 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9151 | } |
| 9152 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9153 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9154 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9155 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9156 | |
| 9157 | std::string alternative_service_http_header = |
| 9158 | GetAlternativeServiceHttpHeader(); |
| 9159 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9160 | |
| 9161 | MockRead data_reads[] = { |
| 9162 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9163 | MockRead(alternative_service_http_header.c_str()), |
| 9164 | MockRead(alternate_protocol_http_header.c_str()), |
| 9165 | MockRead("\r\n"), |
| 9166 | MockRead("hello world"), |
| 9167 | MockRead(SYNCHRONOUS, OK), |
| 9168 | }; |
| 9169 | |
| 9170 | HttpRequestInfo request; |
| 9171 | request.method = "GET"; |
| 9172 | request.url = GURL("http://www.example.org/"); |
| 9173 | request.load_flags = 0; |
| 9174 | |
| 9175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9176 | |
| 9177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9178 | |
| 9179 | TestCompletionCallback callback; |
| 9180 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9181 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9182 | scoped_ptr<HttpTransaction> trans( |
| 9183 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9184 | |
| 9185 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9186 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9187 | |
| 9188 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9189 | HttpServerProperties& http_server_properties = |
| 9190 | *session->http_server_properties(); |
| 9191 | AlternativeServiceVector alternative_service_vector = |
| 9192 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9193 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9194 | |
| 9195 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9196 | |
| 9197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9198 | ASSERT_TRUE(response != NULL); |
| 9199 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9200 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9201 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9202 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9203 | |
| 9204 | std::string response_data; |
| 9205 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9206 | EXPECT_EQ("hello world", response_data); |
| 9207 | |
| 9208 | alternative_service_vector = |
| 9209 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9210 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9211 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9212 | alternative_service_vector[0].protocol); |
| 9213 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9214 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9215 | } |
| 9216 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9217 | // When |use_alternative_services| is false, do not observe alternative service |
| 9218 | // entries that point to a different host. |
| 9219 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9220 | session_deps_.use_alternative_services = false; |
| 9221 | |
| 9222 | HttpRequestInfo request; |
| 9223 | request.method = "GET"; |
| 9224 | request.url = GURL("http://www.example.org/"); |
| 9225 | request.load_flags = 0; |
| 9226 | |
| 9227 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9228 | StaticSocketDataProvider first_data; |
| 9229 | first_data.set_connect_data(mock_connect); |
| 9230 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9231 | |
| 9232 | MockRead data_reads[] = { |
| 9233 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9234 | MockRead(ASYNC, OK), |
| 9235 | }; |
| 9236 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9237 | nullptr, 0); |
| 9238 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9239 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9240 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9241 | |
| 9242 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9243 | session->http_server_properties(); |
| 9244 | AlternativeService alternative_service( |
| 9245 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9246 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9247 | http_server_properties->SetAlternativeService( |
| 9248 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9249 | |
| 9250 | scoped_ptr<HttpTransaction> trans( |
| 9251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9252 | TestCompletionCallback callback; |
| 9253 | |
| 9254 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9255 | // The connetion to origin was refused, and the alternative service should not |
| 9256 | // be used (even though mock data are there), therefore the request should |
| 9257 | // fail. |
| 9258 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9259 | } |
| 9260 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9261 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9262 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9263 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9264 | |
| 9265 | HttpRequestInfo request; |
| 9266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9267 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9268 | request.load_flags = 0; |
| 9269 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9270 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9271 | StaticSocketDataProvider first_data; |
| 9272 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9273 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9274 | |
| 9275 | MockRead data_reads[] = { |
| 9276 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9277 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9278 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9279 | }; |
| 9280 | StaticSocketDataProvider second_data( |
| 9281 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9282 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9283 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9284 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9285 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9286 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9287 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9288 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9289 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9290 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9291 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9292 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9293 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9294 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9295 | http_server_properties->SetAlternativeService( |
| 9296 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9297 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9298 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9300 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9302 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9303 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9304 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9305 | |
| 9306 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9307 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9308 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9309 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9310 | |
| 9311 | std::string response_data; |
| 9312 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9313 | EXPECT_EQ("hello world", response_data); |
| 9314 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9315 | const AlternativeServiceVector alternative_service_vector = |
| 9316 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9317 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9318 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9319 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9320 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9321 | } |
| 9322 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9323 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9324 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9325 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9326 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9327 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9328 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9329 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9330 | |
| 9331 | HttpRequestInfo restricted_port_request; |
| 9332 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9333 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9334 | restricted_port_request.load_flags = 0; |
| 9335 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9336 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9337 | StaticSocketDataProvider first_data; |
| 9338 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9339 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9340 | |
| 9341 | MockRead data_reads[] = { |
| 9342 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9343 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9344 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9345 | }; |
| 9346 | StaticSocketDataProvider second_data( |
| 9347 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9348 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9349 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9350 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9351 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9352 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9353 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9354 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9355 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9356 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9357 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9358 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9359 | http_server_properties->SetAlternativeService( |
| 9360 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9361 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9362 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9363 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9364 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9365 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9367 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9368 | &restricted_port_request, |
| 9369 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9371 | // Invalid change to unrestricted port should fail. |
| 9372 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9373 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9374 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9375 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9376 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9377 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9378 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9379 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9380 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9381 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9382 | |
| 9383 | HttpRequestInfo restricted_port_request; |
| 9384 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9385 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9386 | restricted_port_request.load_flags = 0; |
| 9387 | |
| 9388 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9389 | StaticSocketDataProvider first_data; |
| 9390 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9391 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9392 | |
| 9393 | MockRead data_reads[] = { |
| 9394 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9395 | MockRead("hello world"), |
| 9396 | MockRead(ASYNC, OK), |
| 9397 | }; |
| 9398 | StaticSocketDataProvider second_data( |
| 9399 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9400 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9401 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9402 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9403 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9404 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9405 | session->http_server_properties(); |
| 9406 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9407 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9408 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9409 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9410 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9411 | http_server_properties->SetAlternativeService( |
| 9412 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9413 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9414 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9415 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9416 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9417 | TestCompletionCallback callback; |
| 9418 | |
| 9419 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9420 | &restricted_port_request, |
| 9421 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9422 | // Change to unrestricted port should succeed. |
| 9423 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9424 | } |
| 9425 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9426 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9427 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9428 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9429 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9430 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9431 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9432 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9433 | |
| 9434 | HttpRequestInfo restricted_port_request; |
| 9435 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9436 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9437 | restricted_port_request.load_flags = 0; |
| 9438 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9439 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9440 | StaticSocketDataProvider first_data; |
| 9441 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9442 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9443 | |
| 9444 | MockRead data_reads[] = { |
| 9445 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9446 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9447 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9448 | }; |
| 9449 | StaticSocketDataProvider second_data( |
| 9450 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9451 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9452 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9453 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9454 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9455 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9456 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9457 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9458 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9459 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9460 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9461 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9462 | http_server_properties->SetAlternativeService( |
| 9463 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9464 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9465 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9466 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9467 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9468 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9470 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9471 | &restricted_port_request, |
| 9472 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9473 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9474 | // Valid change to restricted port should pass. |
| 9475 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9476 | } |
| 9477 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9478 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9479 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9480 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9481 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9482 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9483 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9484 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9485 | |
| 9486 | HttpRequestInfo unrestricted_port_request; |
| 9487 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9488 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9489 | unrestricted_port_request.load_flags = 0; |
| 9490 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9491 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9492 | StaticSocketDataProvider first_data; |
| 9493 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9494 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9495 | |
| 9496 | MockRead data_reads[] = { |
| 9497 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9498 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9499 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9500 | }; |
| 9501 | StaticSocketDataProvider second_data( |
| 9502 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9503 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9504 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9505 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9506 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9507 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9508 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9509 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9510 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9511 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9512 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9513 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9514 | http_server_properties->SetAlternativeService( |
| 9515 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9516 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9517 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9518 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9519 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9520 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9521 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9522 | int rv = trans->Start( |
| 9523 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9525 | // Valid change to restricted port should pass. |
| 9526 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9527 | } |
| 9528 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9529 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9530 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9531 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9532 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9533 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9534 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9535 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9536 | |
| 9537 | HttpRequestInfo unrestricted_port_request; |
| 9538 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9539 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9540 | unrestricted_port_request.load_flags = 0; |
| 9541 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9542 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9543 | StaticSocketDataProvider first_data; |
| 9544 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9545 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9546 | |
| 9547 | MockRead data_reads[] = { |
| 9548 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9549 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9550 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9551 | }; |
| 9552 | StaticSocketDataProvider second_data( |
| 9553 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9554 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9555 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9556 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9557 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9558 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9559 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 9560 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9561 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9562 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9563 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9564 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9565 | http_server_properties->SetAlternativeService( |
| 9566 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9567 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9568 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9571 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9573 | int rv = trans->Start( |
| 9574 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9575 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9576 | // Valid change to an unrestricted port should pass. |
| 9577 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9578 | } |
| 9579 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9580 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9581 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 9582 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9583 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9584 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9585 | |
| 9586 | HttpRequestInfo request; |
| 9587 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9588 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9589 | request.load_flags = 0; |
| 9590 | |
| 9591 | // The alternate protocol request will error out before we attempt to connect, |
| 9592 | // so only the standard HTTP request will try to connect. |
| 9593 | MockRead data_reads[] = { |
| 9594 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9595 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9596 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9597 | }; |
| 9598 | StaticSocketDataProvider data( |
| 9599 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9600 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9601 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9602 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9603 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9604 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9605 | session->http_server_properties(); |
| 9606 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9607 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9608 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9609 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9610 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9611 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9612 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9613 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9614 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9616 | TestCompletionCallback callback; |
| 9617 | |
| 9618 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9620 | // The HTTP request should succeed. |
| 9621 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9622 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9624 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9625 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9626 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9627 | |
| 9628 | std::string response_data; |
| 9629 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9630 | EXPECT_EQ("hello world", response_data); |
| 9631 | } |
| 9632 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9633 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9634 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9635 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9636 | |
| 9637 | HttpRequestInfo request; |
| 9638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9639 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9640 | request.load_flags = 0; |
| 9641 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9642 | std::string alternate_protocol_http_header = |
| 9643 | GetAlternateProtocolHttpHeader(); |
| 9644 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9645 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9646 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9647 | MockRead(alternate_protocol_http_header.c_str()), |
| 9648 | MockRead("\r\n"), |
| 9649 | MockRead("hello world"), |
| 9650 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9651 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9652 | |
| 9653 | StaticSocketDataProvider first_transaction( |
| 9654 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9655 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9657 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9658 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9659 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9660 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9662 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9663 | scoped_ptr<SpdyFrame> req( |
| 9664 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9665 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9666 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9667 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9668 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9669 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9670 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9671 | }; |
| 9672 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9673 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9674 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9675 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9676 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9677 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9678 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9679 | NULL, 0, NULL, 0); |
| 9680 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9681 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9682 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9683 | &hanging_non_alternate_protocol_socket); |
| 9684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9685 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9686 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9687 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9688 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9689 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9691 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9692 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9693 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9694 | |
| 9695 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9696 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9697 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9698 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9699 | |
| 9700 | std::string response_data; |
| 9701 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9702 | EXPECT_EQ("hello world", response_data); |
| 9703 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9704 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9706 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9707 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9708 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9709 | |
| 9710 | response = trans->GetResponseInfo(); |
| 9711 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9712 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9713 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9714 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9715 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9716 | |
| 9717 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9718 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9719 | } |
| 9720 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9721 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9722 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9723 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9724 | |
| 9725 | HttpRequestInfo request; |
| 9726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9727 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9728 | request.load_flags = 0; |
| 9729 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9730 | std::string alternate_protocol_http_header = |
| 9731 | GetAlternateProtocolHttpHeader(); |
| 9732 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9733 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9734 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9735 | MockRead(alternate_protocol_http_header.c_str()), |
| 9736 | MockRead("\r\n"), |
| 9737 | MockRead("hello world"), |
| 9738 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9739 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9740 | }; |
| 9741 | |
| 9742 | StaticSocketDataProvider first_transaction( |
| 9743 | data_reads, arraysize(data_reads), NULL, 0); |
| 9744 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9745 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9746 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9747 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9748 | StaticSocketDataProvider hanging_socket( |
| 9749 | NULL, 0, NULL, 0); |
| 9750 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9751 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9752 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9753 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9754 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9755 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9756 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9757 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9758 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9759 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9761 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9762 | scoped_ptr<SpdyFrame> req1( |
| 9763 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9764 | scoped_ptr<SpdyFrame> req2( |
| 9765 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9766 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9767 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9768 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9769 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9770 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9771 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9772 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9773 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9774 | CreateMockRead(*resp1, 2), |
| 9775 | CreateMockRead(*data1, 3), |
| 9776 | CreateMockRead(*resp2, 4), |
| 9777 | CreateMockRead(*data2, 5), |
| 9778 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9779 | }; |
| 9780 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9781 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9782 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9783 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9784 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9785 | |
| 9786 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9787 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9788 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9789 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9790 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9791 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9793 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9794 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9795 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9796 | |
| 9797 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9798 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9799 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9800 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9801 | |
| 9802 | std::string response_data; |
| 9803 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9804 | EXPECT_EQ("hello world", response_data); |
| 9805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9806 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9807 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9808 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9811 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9812 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9813 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9815 | |
| 9816 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9817 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9818 | |
| 9819 | response = trans2.GetResponseInfo(); |
| 9820 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9821 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9822 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9823 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9824 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9825 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9826 | EXPECT_EQ("hello!", response_data); |
| 9827 | |
| 9828 | response = trans3.GetResponseInfo(); |
| 9829 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9830 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9831 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9832 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9833 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9834 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9835 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9836 | } |
| 9837 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9838 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9839 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9840 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9841 | |
| 9842 | HttpRequestInfo request; |
| 9843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9844 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9845 | request.load_flags = 0; |
| 9846 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9847 | std::string alternate_protocol_http_header = |
| 9848 | GetAlternateProtocolHttpHeader(); |
| 9849 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9850 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9852 | MockRead(alternate_protocol_http_header.c_str()), |
| 9853 | MockRead("\r\n"), |
| 9854 | MockRead("hello world"), |
| 9855 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9856 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9857 | }; |
| 9858 | |
| 9859 | StaticSocketDataProvider first_transaction( |
| 9860 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9861 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9862 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9863 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9864 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9866 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9867 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9868 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9869 | NULL, 0, NULL, 0); |
| 9870 | hanging_alternate_protocol_socket.set_connect_data( |
| 9871 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9872 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9873 | &hanging_alternate_protocol_socket); |
| 9874 | |
| 9875 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9876 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9878 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9879 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 9880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9881 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9884 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9885 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9886 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9887 | |
| 9888 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9889 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9890 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9891 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9892 | |
| 9893 | std::string response_data; |
| 9894 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9895 | EXPECT_EQ("hello world", response_data); |
| 9896 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9897 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9899 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9901 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9902 | |
| 9903 | response = trans->GetResponseInfo(); |
| 9904 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9905 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9906 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9907 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9908 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9909 | |
| 9910 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9911 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9912 | } |
| 9913 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9914 | class CapturingProxyResolver : public ProxyResolver { |
| 9915 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9916 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9917 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9918 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9919 | int GetProxyForURL(const GURL& url, |
| 9920 | ProxyInfo* results, |
| 9921 | const CompletionCallback& callback, |
| 9922 | RequestHandle* request, |
| 9923 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9924 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9925 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9926 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9927 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9928 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9929 | } |
| 9930 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9931 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9932 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9933 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9934 | NOTREACHED(); |
| 9935 | return LOAD_STATE_IDLE; |
| 9936 | } |
| 9937 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9938 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9939 | |
| 9940 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9941 | std::vector<GURL> resolved_; |
| 9942 | |
| 9943 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9944 | }; |
| 9945 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9946 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9947 | public: |
| 9948 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9949 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9950 | |
| 9951 | int CreateProxyResolver( |
| 9952 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9953 | scoped_ptr<ProxyResolver>* resolver, |
| 9954 | const net::CompletionCallback& callback, |
| 9955 | scoped_ptr<Request>* request) override { |
| 9956 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9957 | return OK; |
| 9958 | } |
| 9959 | |
| 9960 | private: |
| 9961 | ProxyResolver* resolver_; |
| 9962 | }; |
| 9963 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9964 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9965 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9966 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9967 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9968 | |
| 9969 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9970 | proxy_config.set_auto_detect(true); |
| 9971 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9972 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9973 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9974 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9975 | new ProxyConfigServiceFixed(proxy_config), |
| 9976 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9977 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9978 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9979 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9980 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9981 | |
| 9982 | HttpRequestInfo request; |
| 9983 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9984 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9985 | request.load_flags = 0; |
| 9986 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9987 | std::string alternate_protocol_http_header = |
| 9988 | GetAlternateProtocolHttpHeader(); |
| 9989 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9990 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9991 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9992 | MockRead(alternate_protocol_http_header.c_str()), |
| 9993 | MockRead("\r\n"), |
| 9994 | MockRead("hello world"), |
| 9995 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9996 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9997 | }; |
| 9998 | |
| 9999 | StaticSocketDataProvider first_transaction( |
| 10000 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10001 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10002 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10003 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10004 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10005 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10006 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10007 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10008 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10009 | scoped_ptr<SpdyFrame> req( |
| 10010 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10011 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10012 | MockWrite(ASYNC, 0, |
| 10013 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10014 | "Host: www.example.org\r\n" |
| 10015 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10016 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10017 | }; |
| 10018 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10019 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10020 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10021 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10022 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10023 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10024 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10025 | CreateMockRead(*resp.get(), 3), |
| 10026 | CreateMockRead(*data.get(), 4), |
| 10027 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10028 | }; |
| 10029 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10030 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10031 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10032 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10033 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10034 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10035 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10036 | NULL, 0, NULL, 0); |
| 10037 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10038 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10039 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10040 | &hanging_non_alternate_protocol_socket); |
| 10041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10042 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10043 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10044 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10045 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10046 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10048 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10050 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10051 | |
| 10052 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10053 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10054 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10055 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10056 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10057 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10058 | |
| 10059 | std::string response_data; |
| 10060 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10061 | EXPECT_EQ("hello world", response_data); |
| 10062 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10063 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10065 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10067 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10068 | |
| 10069 | response = trans->GetResponseInfo(); |
| 10070 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10071 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10073 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10074 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10075 | |
| 10076 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10077 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10078 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10079 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10080 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10081 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10082 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10083 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10084 | LoadTimingInfo load_timing_info; |
| 10085 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10086 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10087 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10088 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10089 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10090 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10091 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10092 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10093 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10094 | |
| 10095 | HttpRequestInfo request; |
| 10096 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10097 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10098 | request.load_flags = 0; |
| 10099 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10100 | std::string alternate_protocol_http_header = |
| 10101 | GetAlternateProtocolHttpHeader(); |
| 10102 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10103 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10104 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10105 | MockRead(alternate_protocol_http_header.c_str()), |
| 10106 | MockRead("\r\n"), |
| 10107 | MockRead("hello world"), |
| 10108 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10109 | }; |
| 10110 | |
| 10111 | StaticSocketDataProvider first_transaction( |
| 10112 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10113 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10114 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10115 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10116 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10117 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10118 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10119 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10120 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10121 | scoped_ptr<SpdyFrame> req( |
| 10122 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10123 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10124 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10125 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10126 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10127 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10128 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10129 | }; |
| 10130 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10131 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10132 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10133 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10134 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10135 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10136 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10137 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10138 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10139 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10142 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10144 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10145 | |
| 10146 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10147 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10148 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10150 | |
| 10151 | std::string response_data; |
| 10152 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10153 | EXPECT_EQ("hello world", response_data); |
| 10154 | |
| 10155 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10156 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10157 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10158 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10159 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10160 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10161 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10162 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10164 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10165 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10166 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10167 | |
| 10168 | response = trans->GetResponseInfo(); |
| 10169 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10170 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10171 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10172 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10173 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10174 | |
| 10175 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10176 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10177 | } |
| 10178 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10179 | // GenerateAuthToken is a mighty big test. |
| 10180 | // It tests all permutation of GenerateAuthToken behavior: |
| 10181 | // - Synchronous and Asynchronous completion. |
| 10182 | // - OK or error on completion. |
| 10183 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10184 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10185 | // - Non-authenticating and authenticating backend. |
| 10186 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10187 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10188 | // problems generating an auth token for an authenticating proxy, we don't |
| 10189 | // need to test all permutations of the backend server). |
| 10190 | // |
| 10191 | // The test proceeds by going over each of the configuration cases, and |
| 10192 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10193 | // specifies both the configuration for the test as well as the expectations |
| 10194 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10195 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10196 | static const char kServer[] = "http://www.example.com"; |
| 10197 | static const char kSecureServer[] = "https://www.example.com"; |
| 10198 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10199 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10200 | |
| 10201 | enum AuthTiming { |
| 10202 | AUTH_NONE, |
| 10203 | AUTH_SYNC, |
| 10204 | AUTH_ASYNC, |
| 10205 | }; |
| 10206 | |
| 10207 | const MockWrite kGet( |
| 10208 | "GET / HTTP/1.1\r\n" |
| 10209 | "Host: www.example.com\r\n" |
| 10210 | "Connection: keep-alive\r\n\r\n"); |
| 10211 | const MockWrite kGetProxy( |
| 10212 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10213 | "Host: www.example.com\r\n" |
| 10214 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10215 | const MockWrite kGetAuth( |
| 10216 | "GET / HTTP/1.1\r\n" |
| 10217 | "Host: www.example.com\r\n" |
| 10218 | "Connection: keep-alive\r\n" |
| 10219 | "Authorization: auth_token\r\n\r\n"); |
| 10220 | const MockWrite kGetProxyAuth( |
| 10221 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10222 | "Host: www.example.com\r\n" |
| 10223 | "Proxy-Connection: keep-alive\r\n" |
| 10224 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10225 | const MockWrite kGetAuthThroughProxy( |
| 10226 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10227 | "Host: www.example.com\r\n" |
| 10228 | "Proxy-Connection: keep-alive\r\n" |
| 10229 | "Authorization: auth_token\r\n\r\n"); |
| 10230 | const MockWrite kGetAuthWithProxyAuth( |
| 10231 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10232 | "Host: www.example.com\r\n" |
| 10233 | "Proxy-Connection: keep-alive\r\n" |
| 10234 | "Proxy-Authorization: auth_token\r\n" |
| 10235 | "Authorization: auth_token\r\n\r\n"); |
| 10236 | const MockWrite kConnect( |
| 10237 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10238 | "Host: www.example.com\r\n" |
| 10239 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10240 | const MockWrite kConnectProxyAuth( |
| 10241 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10242 | "Host: www.example.com\r\n" |
| 10243 | "Proxy-Connection: keep-alive\r\n" |
| 10244 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10245 | |
| 10246 | const MockRead kSuccess( |
| 10247 | "HTTP/1.1 200 OK\r\n" |
| 10248 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10249 | "Content-Length: 3\r\n\r\n" |
| 10250 | "Yes"); |
| 10251 | const MockRead kFailure( |
| 10252 | "Should not be called."); |
| 10253 | const MockRead kServerChallenge( |
| 10254 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10255 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10256 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10257 | "Content-Length: 14\r\n\r\n" |
| 10258 | "Unauthorized\r\n"); |
| 10259 | const MockRead kProxyChallenge( |
| 10260 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10261 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10262 | "Proxy-Connection: close\r\n" |
| 10263 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10264 | "Content-Length: 14\r\n\r\n" |
| 10265 | "Unauthorized\r\n"); |
| 10266 | const MockRead kProxyConnected( |
| 10267 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10268 | |
| 10269 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10270 | // no constructors, but the C++ compiler on Windows warns about |
| 10271 | // unspecified data in compound literals. So, moved to using constructors, |
| 10272 | // and TestRound's created with the default constructor should not be used. |
| 10273 | struct TestRound { |
| 10274 | TestRound() |
| 10275 | : expected_rv(ERR_UNEXPECTED), |
| 10276 | extra_write(NULL), |
| 10277 | extra_read(NULL) { |
| 10278 | } |
| 10279 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10280 | int expected_rv_arg) |
| 10281 | : write(write_arg), |
| 10282 | read(read_arg), |
| 10283 | expected_rv(expected_rv_arg), |
| 10284 | extra_write(NULL), |
| 10285 | extra_read(NULL) { |
| 10286 | } |
| 10287 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10288 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10289 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10290 | : write(write_arg), |
| 10291 | read(read_arg), |
| 10292 | expected_rv(expected_rv_arg), |
| 10293 | extra_write(extra_write_arg), |
| 10294 | extra_read(extra_read_arg) { |
| 10295 | } |
| 10296 | MockWrite write; |
| 10297 | MockRead read; |
| 10298 | int expected_rv; |
| 10299 | const MockWrite* extra_write; |
| 10300 | const MockRead* extra_read; |
| 10301 | }; |
| 10302 | |
| 10303 | static const int kNoSSL = 500; |
| 10304 | |
| 10305 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10306 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10307 | AuthTiming proxy_auth_timing; |
| 10308 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10309 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10310 | AuthTiming server_auth_timing; |
| 10311 | int server_auth_rv; |
| 10312 | int num_auth_rounds; |
| 10313 | int first_ssl_round; |
| 10314 | TestRound rounds[3]; |
| 10315 | } test_configs[] = { |
| 10316 | // Non-authenticating HTTP server with a direct connection. |
| 10317 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10318 | { TestRound(kGet, kSuccess, OK)}}, |
| 10319 | // Authenticating HTTP server with a direct connection. |
| 10320 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10321 | { TestRound(kGet, kServerChallenge, OK), |
| 10322 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10323 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10324 | { TestRound(kGet, kServerChallenge, OK), |
| 10325 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10326 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10327 | { TestRound(kGet, kServerChallenge, OK), |
| 10328 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10329 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10330 | { TestRound(kGet, kServerChallenge, OK), |
| 10331 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10332 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10333 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10334 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10335 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10336 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10337 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10338 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10339 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10340 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10341 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10342 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10343 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10344 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10345 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10346 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10347 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10348 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10349 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10350 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10351 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10352 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10353 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10354 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10355 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10356 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10357 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10358 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10359 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10360 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10361 | // Authenticating HTTP server through an authenticating proxy. |
| 10362 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10363 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10364 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10365 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10366 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10367 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10368 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10369 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10370 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10371 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10372 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10373 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10374 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10375 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10376 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10377 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10378 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10379 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10380 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10381 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10382 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10383 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10384 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10385 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10386 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10387 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10388 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10389 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10390 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10391 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10392 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10393 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10394 | // Non-authenticating HTTPS server with a direct connection. |
| 10395 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10396 | { TestRound(kGet, kSuccess, OK)}}, |
| 10397 | // Authenticating HTTPS server with a direct connection. |
| 10398 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10399 | { TestRound(kGet, kServerChallenge, OK), |
| 10400 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10401 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10402 | { TestRound(kGet, kServerChallenge, OK), |
| 10403 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10404 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10405 | { TestRound(kGet, kServerChallenge, OK), |
| 10406 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10407 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10408 | { TestRound(kGet, kServerChallenge, OK), |
| 10409 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10410 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10411 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10412 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10413 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10414 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10415 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10416 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10417 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10418 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10419 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10420 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10421 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10422 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10423 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10424 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10425 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10426 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10427 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10428 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10429 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10430 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10431 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10432 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10433 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10434 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10435 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10436 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10437 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10438 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10439 | // Authenticating HTTPS server through an authenticating proxy. |
| 10440 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10441 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10442 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10443 | &kGet, &kServerChallenge), |
| 10444 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10445 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10446 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10447 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10448 | &kGet, &kServerChallenge), |
| 10449 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10450 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10451 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10452 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10453 | &kGet, &kServerChallenge), |
| 10454 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10455 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10456 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10457 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10458 | &kGet, &kServerChallenge), |
| 10459 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10460 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10461 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10462 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10463 | &kGet, &kServerChallenge), |
| 10464 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10465 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10466 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10467 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10468 | &kGet, &kServerChallenge), |
| 10469 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10470 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10471 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10472 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10473 | &kGet, &kServerChallenge), |
| 10474 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10475 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10476 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10477 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10478 | &kGet, &kServerChallenge), |
| 10479 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10480 | }; |
| 10481 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10482 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10483 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10484 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10485 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10486 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10487 | |
| 10488 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10489 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10490 | for (int n = 0; n < 2; n++) { |
| 10491 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10492 | std::string auth_challenge = "Mock realm=proxy"; |
| 10493 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10494 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10495 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10496 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10497 | origin, BoundNetLog()); |
| 10498 | auth_handler->SetGenerateExpectation( |
| 10499 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10500 | test_config.proxy_auth_rv); |
| 10501 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10502 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10503 | } |
| 10504 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10505 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10506 | std::string auth_challenge = "Mock realm=server"; |
| 10507 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10508 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10509 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10510 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10511 | origin, BoundNetLog()); |
| 10512 | auth_handler->SetGenerateExpectation( |
| 10513 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10514 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10515 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10516 | } |
| 10517 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10518 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10519 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10520 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10521 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10522 | } |
| 10523 | |
| 10524 | HttpRequestInfo request; |
| 10525 | request.method = "GET"; |
| 10526 | request.url = GURL(test_config.server_url); |
| 10527 | request.load_flags = 0; |
| 10528 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10529 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10531 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10532 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10533 | |
| 10534 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10535 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10536 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10537 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10538 | |
| 10539 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10540 | mock_reads.back().push_back(read_write_round.read); |
| 10541 | mock_writes.back().push_back(read_write_round.write); |
| 10542 | |
| 10543 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10544 | // socket is closed and a new one will be created for the next request. |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 10545 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10546 | mock_reads.push_back(std::vector<MockRead>()); |
| 10547 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10548 | } |
| 10549 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10550 | if (read_write_round.extra_read) { |
| 10551 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10552 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10553 | if (read_write_round.extra_write) { |
| 10554 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10555 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10556 | |
| 10557 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10558 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10559 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10560 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10561 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10562 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10563 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10564 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10565 | data_providers.push_back(new StaticSocketDataProvider( |
| 10566 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10567 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10568 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10569 | data_providers.back()); |
| 10570 | } |
| 10571 | |
| 10572 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10573 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10574 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10575 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10576 | int rv; |
| 10577 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10578 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10579 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10580 | rv = trans.RestartWithAuth( |
| 10581 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10582 | } |
| 10583 | if (rv == ERR_IO_PENDING) |
| 10584 | rv = callback.WaitForResult(); |
| 10585 | |
| 10586 | // Compare results with expected data. |
| 10587 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10589 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10590 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10591 | continue; |
| 10592 | } |
| 10593 | if (round + 1 < test_config.num_auth_rounds) { |
| 10594 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10595 | } else { |
| 10596 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10597 | } |
| 10598 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10599 | } |
| 10600 | } |
| 10601 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10602 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10603 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10604 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10605 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10606 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10607 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10608 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10609 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10610 | |
| 10611 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10612 | auth_handler->set_connection_based(true); |
| 10613 | std::string auth_challenge = "Mock realm=server"; |
| 10614 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10615 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10616 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10617 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10618 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10619 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10620 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10621 | int rv = OK; |
| 10622 | const HttpResponseInfo* response = NULL; |
| 10623 | HttpRequestInfo request; |
| 10624 | request.method = "GET"; |
| 10625 | request.url = origin; |
| 10626 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10627 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10628 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10629 | |
| 10630 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10631 | // to validate that the TCP socket is not released to the pool between |
| 10632 | // each round of multi-round authentication. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10633 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10634 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10635 | 50, // Max sockets for pool |
| 10636 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10637 | session_deps_.host_resolver.get(), |
| 10638 | session_deps_.socket_factory.get(), |
| 10639 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10640 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10641 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10642 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10643 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10644 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10645 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10646 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10647 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10648 | |
| 10649 | const MockWrite kGet( |
| 10650 | "GET / HTTP/1.1\r\n" |
| 10651 | "Host: www.example.com\r\n" |
| 10652 | "Connection: keep-alive\r\n\r\n"); |
| 10653 | const MockWrite kGetAuth( |
| 10654 | "GET / HTTP/1.1\r\n" |
| 10655 | "Host: www.example.com\r\n" |
| 10656 | "Connection: keep-alive\r\n" |
| 10657 | "Authorization: auth_token\r\n\r\n"); |
| 10658 | |
| 10659 | const MockRead kServerChallenge( |
| 10660 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10661 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10662 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10663 | "Content-Length: 14\r\n\r\n" |
| 10664 | "Unauthorized\r\n"); |
| 10665 | const MockRead kSuccess( |
| 10666 | "HTTP/1.1 200 OK\r\n" |
| 10667 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10668 | "Content-Length: 3\r\n\r\n" |
| 10669 | "Yes"); |
| 10670 | |
| 10671 | MockWrite writes[] = { |
| 10672 | // First round |
| 10673 | kGet, |
| 10674 | // Second round |
| 10675 | kGetAuth, |
| 10676 | // Third round |
| 10677 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10678 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10679 | kGetAuth, |
| 10680 | // Competing request |
| 10681 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10682 | }; |
| 10683 | MockRead reads[] = { |
| 10684 | // First round |
| 10685 | kServerChallenge, |
| 10686 | // Second round |
| 10687 | kServerChallenge, |
| 10688 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10689 | kServerChallenge, |
| 10690 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10691 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10692 | // Competing response |
| 10693 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10694 | }; |
| 10695 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10696 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10697 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10698 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10699 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10700 | |
| 10701 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10702 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10703 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10704 | if (rv == ERR_IO_PENDING) |
| 10705 | rv = callback.WaitForResult(); |
| 10706 | EXPECT_EQ(OK, rv); |
| 10707 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10708 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10709 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10710 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10711 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10712 | // In between rounds, another request comes in for the same domain. |
| 10713 | // It should not be able to grab the TCP socket that trans has already |
| 10714 | // claimed. |
| 10715 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10717 | TestCompletionCallback callback_compete; |
| 10718 | rv = trans_compete->Start( |
| 10719 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10720 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10721 | // callback_compete.WaitForResult at this point would stall forever, |
| 10722 | // since the HttpNetworkTransaction does not release the request back to |
| 10723 | // the pool until after authentication completes. |
| 10724 | |
| 10725 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10726 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10727 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10728 | if (rv == ERR_IO_PENDING) |
| 10729 | rv = callback.WaitForResult(); |
| 10730 | EXPECT_EQ(OK, rv); |
| 10731 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10732 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10733 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10734 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10735 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10736 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10737 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10738 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10739 | if (rv == ERR_IO_PENDING) |
| 10740 | rv = callback.WaitForResult(); |
| 10741 | EXPECT_EQ(OK, rv); |
| 10742 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10743 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10744 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10745 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10746 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10747 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10748 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10749 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10750 | if (rv == ERR_IO_PENDING) |
| 10751 | rv = callback.WaitForResult(); |
| 10752 | EXPECT_EQ(OK, rv); |
| 10753 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10754 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10755 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10756 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10757 | |
| 10758 | // Read the body since the fourth round was successful. This will also |
| 10759 | // release the socket back to the pool. |
| 10760 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10761 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10762 | if (rv == ERR_IO_PENDING) |
| 10763 | rv = callback.WaitForResult(); |
| 10764 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10765 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10766 | EXPECT_EQ(0, rv); |
| 10767 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10768 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10769 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10770 | |
| 10771 | // The competing request can now finish. Wait for the headers and then |
| 10772 | // read the body. |
| 10773 | rv = callback_compete.WaitForResult(); |
| 10774 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10775 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10776 | if (rv == ERR_IO_PENDING) |
| 10777 | rv = callback.WaitForResult(); |
| 10778 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10779 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10780 | EXPECT_EQ(0, rv); |
| 10781 | |
| 10782 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10783 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10784 | } |
| 10785 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10786 | // This tests the case that a request is issued via http instead of spdy after |
| 10787 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10788 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10789 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10790 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10791 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10792 | session_deps_.next_protos = next_protos; |
| 10793 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10794 | HttpRequestInfo request; |
| 10795 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10796 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10797 | request.load_flags = 0; |
| 10798 | |
| 10799 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10800 | MockWrite( |
| 10801 | "GET / HTTP/1.1\r\n" |
| 10802 | "Host: www.example.org\r\n" |
| 10803 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10804 | }; |
| 10805 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10806 | std::string alternate_protocol_http_header = |
| 10807 | GetAlternateProtocolHttpHeader(); |
| 10808 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10809 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10810 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10811 | MockRead(alternate_protocol_http_header.c_str()), |
| 10812 | MockRead("\r\n"), |
| 10813 | MockRead("hello world"), |
| 10814 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10815 | }; |
| 10816 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10817 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10818 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10819 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10820 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10821 | |
| 10822 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10823 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10826 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10827 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10828 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10829 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10830 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10832 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10833 | |
| 10834 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10835 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10836 | |
| 10837 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10838 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10839 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10840 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10841 | |
| 10842 | std::string response_data; |
| 10843 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10844 | EXPECT_EQ("hello world", response_data); |
| 10845 | |
| 10846 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10847 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10848 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10849 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10850 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 10851 | // immediate server closing of the socket. |
| 10852 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10853 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10854 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10855 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10856 | |
| 10857 | HttpRequestInfo request; |
| 10858 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10859 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10860 | request.load_flags = 0; |
| 10861 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10862 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10863 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10864 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10865 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10866 | scoped_ptr<SpdyFrame> req( |
| 10867 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10868 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10869 | |
| 10870 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10871 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10872 | }; |
| 10873 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10874 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10875 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10876 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10878 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10879 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 10880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10881 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10884 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10885 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10886 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10887 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10888 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10889 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10890 | // it gets it. This is needed since the auth handler may get destroyed |
| 10891 | // before we get a chance to query it. |
| 10892 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10893 | public: |
| 10894 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10895 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10896 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10897 | |
| 10898 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10899 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10900 | const HttpRequestInfo* request, |
| 10901 | const CompletionCallback& callback, |
| 10902 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10903 | *url_ = request->url; |
| 10904 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10905 | credentials, request, callback, auth_token); |
| 10906 | } |
| 10907 | |
| 10908 | private: |
| 10909 | GURL* url_; |
| 10910 | }; |
| 10911 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10912 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 10913 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10914 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10915 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10916 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10917 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10918 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10919 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10920 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10921 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10922 | GURL request_url; |
| 10923 | { |
| 10924 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10925 | new HttpAuthHandlerMock::Factory(); |
| 10926 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10927 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10928 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10929 | auth_factory->set_do_init_from_challenge(true); |
| 10930 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10931 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10932 | |
| 10933 | HttpRequestInfo request; |
| 10934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10935 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10936 | request.load_flags = 0; |
| 10937 | |
| 10938 | // First round goes unauthenticated through the proxy. |
| 10939 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10940 | MockWrite( |
| 10941 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10942 | "Host: www.example.org\r\n" |
| 10943 | "Proxy-Connection: keep-alive\r\n" |
| 10944 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10945 | }; |
| 10946 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10947 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10948 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10949 | MockRead("Alternate-Protocol: 443:"), |
| 10950 | MockRead(GetAlternateProtocolFromParam()), |
| 10951 | MockRead("\r\n"), |
| 10952 | MockRead("Proxy-Connection: close\r\n"), |
| 10953 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10954 | }; |
| 10955 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10956 | data_writes_1, arraysize(data_writes_1)); |
| 10957 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10958 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10959 | // Alternate-Protocol announcement in the first round. It fails due |
| 10960 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10961 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10962 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10963 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10964 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10965 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10966 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10967 | // to obtain a new one. |
| 10968 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10969 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10970 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10971 | // establishment and SPDY framing issues. Alas, the |
| 10972 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10973 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10974 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10975 | scoped_ptr<SpdyFrame> req( |
| 10976 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10977 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10978 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10979 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10980 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10981 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10982 | MockWrite(ASYNC, 0, |
| 10983 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10984 | "Host: www.example.org\r\n" |
| 10985 | "Proxy-Connection: keep-alive\r\n" |
| 10986 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10987 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10988 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10989 | MockWrite(ASYNC, 2, |
| 10990 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10991 | "Host: www.example.org\r\n" |
| 10992 | "Proxy-Connection: keep-alive\r\n" |
| 10993 | "Proxy-Authorization: auth_token\r\n" |
| 10994 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10995 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10996 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10997 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10998 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10999 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11000 | // First connection attempt fails |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 11001 | MockRead(ASYNC, 1, |
| 11002 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11003 | "Proxy-Authenticate: Mock\r\n" |
| 11004 | "Content-Length: 0\r\n" |
| 11005 | "Proxy-Connection: keep-alive\r\n" |
| 11006 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11007 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11008 | // Second connection attempt passes |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 11009 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11010 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11011 | // SPDY response |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 11012 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11013 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11014 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11015 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11016 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11017 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11018 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11019 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11020 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11021 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11022 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11023 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11024 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11025 | NULL, 0, NULL, 0); |
| 11026 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11027 | never_finishing_connect); |
| 11028 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11029 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11030 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11031 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11032 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11033 | &hanging_non_alternate_protocol_socket); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11034 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11035 | |
| 11036 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11037 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11038 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11039 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11040 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11042 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11043 | |
| 11044 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11045 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11046 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11047 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11048 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11050 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11051 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11052 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11053 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11054 | |
| 11055 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11056 | TestCompletionCallback callback_3; |
| 11057 | rv = trans_2->RestartWithAuth( |
| 11058 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11059 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11060 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11061 | |
| 11062 | // After all that work, these two lines (or actually, just the scheme) are |
| 11063 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11064 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11065 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11066 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11067 | LoadTimingInfo load_timing_info; |
| 11068 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11069 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11070 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11071 | } |
| 11072 | |
| 11073 | // Test that if we cancel the transaction as the connection is completing, that |
| 11074 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11075 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11076 | // Setup everything about the connection to complete synchronously, so that |
| 11077 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11078 | // for is the callback from the HttpStreamRequest. |
| 11079 | // Then cancel the transaction. |
| 11080 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11081 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11082 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11083 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11084 | MockRead(SYNCHRONOUS, "hello world"), |
| 11085 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11086 | }; |
| 11087 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11088 | HttpRequestInfo request; |
| 11089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11090 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11091 | request.load_flags = 0; |
| 11092 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11093 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11094 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11095 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11097 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11099 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11102 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11103 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11104 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11105 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11106 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11107 | trans.reset(); // Cancel the transaction here. |
| 11108 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11109 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11110 | } |
| 11111 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11112 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11113 | // stream is drained properly and added back to the socket pool. The main |
| 11114 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11115 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11116 | // deleted. |
| 11117 | // See http://crbug.com/368418 |
| 11118 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11119 | MockRead data_reads[] = { |
| 11120 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11121 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11122 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11123 | MockRead(ASYNC, "1"), |
| 11124 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11125 | // HttpNetworkTransaction has been deleted. |
| 11126 | MockRead(ASYNC, "2"), |
| 11127 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11128 | }; |
| 11129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11130 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11131 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11132 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11133 | |
| 11134 | { |
| 11135 | HttpRequestInfo request; |
| 11136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11137 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11138 | request.load_flags = 0; |
| 11139 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11140 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11141 | TestCompletionCallback callback; |
| 11142 | |
| 11143 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11145 | callback.WaitForResult(); |
| 11146 | |
| 11147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11148 | ASSERT_TRUE(response != NULL); |
| 11149 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11151 | |
| 11152 | // The transaction and HttpRequestInfo are deleted. |
| 11153 | } |
| 11154 | |
| 11155 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11156 | base::MessageLoop::current()->RunUntilIdle(); |
| 11157 | |
| 11158 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11159 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11160 | } |
| 11161 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11162 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11163 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11164 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11165 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11166 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11167 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11168 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11169 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11170 | HttpRequestInfo request; |
| 11171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11172 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11173 | |
| 11174 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11175 | MockWrite( |
| 11176 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11177 | "Host: www.example.org\r\n" |
| 11178 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11179 | }; |
| 11180 | |
| 11181 | MockRead data_reads1[] = { |
| 11182 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11183 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11184 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11185 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11186 | }; |
| 11187 | |
| 11188 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11189 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11190 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11191 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11192 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11193 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11194 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11196 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11197 | trans->SetBeforeProxyHeadersSentCallback( |
| 11198 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11199 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11201 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11203 | |
| 11204 | rv = callback1.WaitForResult(); |
| 11205 | EXPECT_EQ(OK, rv); |
| 11206 | |
| 11207 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11208 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11209 | |
| 11210 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11211 | EXPECT_EQ(200, response->headers->response_code()); |
| 11212 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11213 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11214 | EXPECT_TRUE( |
| 11215 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11216 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11217 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11218 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11219 | |
| 11220 | LoadTimingInfo load_timing_info; |
| 11221 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11222 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11223 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11224 | } |
| 11225 | |
| 11226 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11227 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11228 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11229 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11230 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11231 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11232 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11233 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11234 | HttpRequestInfo request; |
| 11235 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11236 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11237 | |
| 11238 | // Since we have proxy, should try to establish tunnel. |
| 11239 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11240 | MockWrite( |
| 11241 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11242 | "Host: www.example.org\r\n" |
| 11243 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11244 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11245 | MockWrite( |
| 11246 | "GET / HTTP/1.1\r\n" |
| 11247 | "Host: www.example.org\r\n" |
| 11248 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11249 | }; |
| 11250 | |
| 11251 | MockRead data_reads1[] = { |
| 11252 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11253 | |
| 11254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11256 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11257 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11258 | }; |
| 11259 | |
| 11260 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11261 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11263 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11266 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11267 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11268 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11271 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11272 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11273 | |
| 11274 | rv = callback1.WaitForResult(); |
| 11275 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11276 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11277 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11278 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11279 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11280 | NetLog::PHASE_NONE); |
| 11281 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11282 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11283 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11284 | NetLog::PHASE_NONE); |
| 11285 | |
| 11286 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11287 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11288 | |
| 11289 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11290 | EXPECT_EQ(200, response->headers->response_code()); |
| 11291 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11292 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11293 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11294 | EXPECT_TRUE( |
| 11295 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11296 | |
| 11297 | LoadTimingInfo load_timing_info; |
| 11298 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11299 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11300 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11301 | } |
| 11302 | |
| 11303 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11304 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11305 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11306 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11307 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11308 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11310 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11311 | HttpRequestInfo request; |
| 11312 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11313 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11314 | |
| 11315 | // Since we have proxy, should try to establish tunnel. |
| 11316 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11317 | MockWrite( |
| 11318 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11319 | "Host: www.example.org\r\n" |
| 11320 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11321 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11322 | MockWrite( |
| 11323 | "GET / HTTP/1.1\r\n" |
| 11324 | "Host: www.example.org\r\n" |
| 11325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11326 | }; |
| 11327 | |
| 11328 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11329 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11330 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11331 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11332 | }; |
| 11333 | |
| 11334 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11335 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11337 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11340 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11341 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11342 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11343 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11345 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11346 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11347 | |
| 11348 | rv = callback1.WaitForResult(); |
| 11349 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11350 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11351 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11352 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11353 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11354 | NetLog::PHASE_NONE); |
| 11355 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11356 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11357 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11358 | NetLog::PHASE_NONE); |
| 11359 | } |
| 11360 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11361 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11362 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11363 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11364 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11365 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11366 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11367 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11368 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11369 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11370 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11371 | }; |
| 11372 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11373 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11374 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11375 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11376 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11377 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11378 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11380 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11381 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11382 | |
| 11383 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11384 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11385 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11386 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11387 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11388 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11389 | |
| 11390 | HttpRequestInfo request; |
| 11391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11392 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11393 | request.load_flags = 0; |
| 11394 | |
| 11395 | // This is the important line that marks this as a preconnect. |
| 11396 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11397 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11398 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11400 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11401 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11404 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11405 | } |
| 11406 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11407 | // Given a net error, cause that error to be returned from the first Write() |
| 11408 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11409 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11410 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11411 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11412 | request_info.url = GURL("https://www.example.com/"); |
| 11413 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11414 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11415 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11416 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11417 | MockWrite data_writes[] = { |
| 11418 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11419 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11420 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11421 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11423 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11424 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11425 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11426 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11428 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11429 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11430 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11431 | rv = callback.WaitForResult(); |
| 11432 | ASSERT_EQ(error, rv); |
| 11433 | } |
| 11434 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11435 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11436 | // Just check a grab bag of cert errors. |
| 11437 | static const int kErrors[] = { |
| 11438 | ERR_CERT_COMMON_NAME_INVALID, |
| 11439 | ERR_CERT_AUTHORITY_INVALID, |
| 11440 | ERR_CERT_DATE_INVALID, |
| 11441 | }; |
| 11442 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11443 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11444 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11445 | } |
| 11446 | } |
| 11447 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11448 | // Ensure that a client certificate is removed from the SSL client auth |
| 11449 | // cache when: |
| 11450 | // 1) No proxy is involved. |
| 11451 | // 2) TLS False Start is disabled. |
| 11452 | // 3) The initial TLS handshake requests a client certificate. |
| 11453 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11454 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11455 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11456 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11457 | request_info.url = GURL("https://www.example.com/"); |
| 11458 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11459 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11460 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11461 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11462 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11463 | |
| 11464 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11465 | // CertificateRequest is received for the first time, the handshake will |
| 11466 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11467 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11468 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11470 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11471 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11472 | |
| 11473 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11474 | // False Start is not being used, the result of the SSL handshake will be |
| 11475 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11476 | // matches the result of a server sending a handshake_failure alert, |
| 11477 | // rather than a Finished message, because it requires a client |
| 11478 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11479 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11480 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11482 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11483 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11484 | |
| 11485 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11486 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11487 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11488 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11489 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11490 | // requiring a client certificate, this fallback handshake should also |
| 11491 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11492 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11493 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11495 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11496 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11497 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11498 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11499 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11500 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11501 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11502 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11503 | // requiring a client certificate, this fallback handshake should also |
| 11504 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11505 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11506 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11508 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11509 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11510 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11511 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11512 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11514 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11515 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11516 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11517 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11518 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11519 | |
| 11520 | // Complete the SSL handshake, which should abort due to requiring a |
| 11521 | // client certificate. |
| 11522 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11523 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11524 | |
| 11525 | // Indicate that no certificate should be supplied. From the perspective |
| 11526 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11527 | // certificate, so this is the same as supply a |
| 11528 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11529 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11530 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11531 | |
| 11532 | // Ensure the certificate was added to the client auth cache before |
| 11533 | // allowing the connection to continue restarting. |
| 11534 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11535 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11536 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11537 | ASSERT_EQ(NULL, client_cert.get()); |
| 11538 | |
| 11539 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11540 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11541 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11542 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11543 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11544 | |
| 11545 | // Ensure that the client certificate is removed from the cache on a |
| 11546 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11547 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11548 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11549 | } |
| 11550 | |
| 11551 | // Ensure that a client certificate is removed from the SSL client auth |
| 11552 | // cache when: |
| 11553 | // 1) No proxy is involved. |
| 11554 | // 2) TLS False Start is enabled. |
| 11555 | // 3) The initial TLS handshake requests a client certificate. |
| 11556 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11557 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11558 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11559 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11560 | request_info.url = GURL("https://www.example.com/"); |
| 11561 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11562 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11563 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11564 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11565 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11566 | |
| 11567 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11568 | // return successfully after reading up to the peer's Certificate message. |
| 11569 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11570 | // enqueue application data to be sent in the same packet as the |
| 11571 | // ChangeCipherSpec and Finished messages. |
| 11572 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11573 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11574 | // Finished messages. If there was an error negotiating with the peer, |
| 11575 | // such as due to the peer requiring a client certificate when none was |
| 11576 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11577 | // called. |
| 11578 | |
| 11579 | // Like the non-False Start case, when a client certificate is requested by |
| 11580 | // the peer, the handshake is aborted during the Connect() call. |
| 11581 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11582 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11583 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11585 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11587 | |
| 11588 | // When a client certificate is supplied, Connect() will not be aborted |
| 11589 | // when the peer requests the certificate. Instead, the handshake will |
| 11590 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11591 | // the socket. The handshake messages are not processed until Read() is |
| 11592 | // called, which then detects that the handshake was aborted, due to the |
| 11593 | // peer sending a handshake_failure because it requires a client |
| 11594 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11595 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11596 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11598 | MockRead data2_reads[] = { |
| 11599 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11600 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11601 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11602 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11603 | |
| 11604 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11605 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11606 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11607 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11608 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11610 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11611 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11612 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11613 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11614 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11615 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11616 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11618 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11619 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11620 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11621 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11622 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11623 | ssl_data5.cert_request_info = cert_request.get(); |
| 11624 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11625 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11626 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11627 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11628 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11629 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11631 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11632 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11633 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11634 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11635 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11636 | |
| 11637 | // Complete the SSL handshake, which should abort due to requiring a |
| 11638 | // client certificate. |
| 11639 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11640 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11641 | |
| 11642 | // Indicate that no certificate should be supplied. From the perspective |
| 11643 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11644 | // certificate, so this is the same as supply a |
| 11645 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11646 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11647 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11648 | |
| 11649 | // Ensure the certificate was added to the client auth cache before |
| 11650 | // allowing the connection to continue restarting. |
| 11651 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11652 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11653 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11654 | ASSERT_EQ(NULL, client_cert.get()); |
| 11655 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11656 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11657 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11658 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11659 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11660 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11661 | |
| 11662 | // Ensure that the client certificate is removed from the cache on a |
| 11663 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11664 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11665 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11666 | } |
| 11667 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11668 | // Ensure that a client certificate is removed from the SSL client auth |
| 11669 | // cache when: |
| 11670 | // 1) An HTTPS proxy is involved. |
| 11671 | // 3) The HTTPS proxy requests a client certificate. |
| 11672 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11673 | // proxy. |
| 11674 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11675 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11676 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11677 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11678 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11679 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11680 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11681 | |
| 11682 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11683 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11684 | |
| 11685 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11686 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11687 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11688 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11689 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11690 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11692 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11693 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11694 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11695 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11696 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11697 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11698 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11700 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11701 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11702 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11703 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11704 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11706 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11707 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11708 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11709 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11710 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11711 | requests[0].url = GURL("https://www.example.com/"); |
| 11712 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11713 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11714 | |
| 11715 | requests[1].url = GURL("http://www.example.com/"); |
| 11716 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11717 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11718 | |
| 11719 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11720 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11721 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11722 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11723 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11724 | |
| 11725 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11726 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11727 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11728 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11729 | |
| 11730 | // Complete the SSL handshake, which should abort due to requiring a |
| 11731 | // client certificate. |
| 11732 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11733 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11734 | |
| 11735 | // Indicate that no certificate should be supplied. From the perspective |
| 11736 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11737 | // certificate, so this is the same as supply a |
| 11738 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11739 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11740 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11741 | |
| 11742 | // Ensure the certificate was added to the client auth cache before |
| 11743 | // allowing the connection to continue restarting. |
| 11744 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11745 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11746 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11747 | ASSERT_EQ(NULL, client_cert.get()); |
| 11748 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11749 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11750 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11751 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11752 | |
| 11753 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11754 | // then consume ssl_data3, which should also fail. The result code is |
| 11755 | // checked against what ssl_data3 should return. |
| 11756 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11757 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11758 | |
| 11759 | // Now that the new handshake has failed, ensure that the client |
| 11760 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11761 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11762 | HostPortPair("proxy", 70), &client_cert)); |
| 11763 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11764 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11765 | } |
| 11766 | } |
| 11767 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11768 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11769 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11770 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11771 | |
| 11772 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11773 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11774 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11775 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11776 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11777 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11778 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11779 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11780 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11781 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11782 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11783 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11784 | scoped_ptr<SpdyFrame> host2_req( |
| 11785 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11786 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11787 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11788 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11789 | scoped_ptr<SpdyFrame> host1_resp( |
| 11790 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11791 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11792 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11793 | scoped_ptr<SpdyFrame> host2_resp( |
| 11794 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11795 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11796 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11797 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11798 | CreateMockRead(*host1_resp, 1), |
| 11799 | CreateMockRead(*host1_resp_body, 2), |
| 11800 | CreateMockRead(*host2_resp, 4), |
| 11801 | CreateMockRead(*host2_resp_body, 5), |
| 11802 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11803 | }; |
| 11804 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11805 | IPAddressNumber ip; |
| 11806 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11807 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11808 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11809 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11810 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11811 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11812 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11813 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11814 | HttpRequestInfo request1; |
| 11815 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11816 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11817 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11818 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11820 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11822 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11823 | |
| 11824 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11825 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11826 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11827 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11828 | |
| 11829 | std::string response_data; |
| 11830 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11831 | EXPECT_EQ("hello!", response_data); |
| 11832 | |
| 11833 | // Preload www.gmail.com into HostCache. |
| 11834 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11835 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11836 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11837 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11838 | DEFAULT_PRIORITY, |
| 11839 | &ignored, |
| 11840 | callback.callback(), |
| 11841 | NULL, |
| 11842 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11844 | rv = callback.WaitForResult(); |
| 11845 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11846 | |
| 11847 | HttpRequestInfo request2; |
| 11848 | request2.method = "GET"; |
| 11849 | request2.url = GURL("https://www.gmail.com/"); |
| 11850 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11851 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11853 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11854 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11855 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11856 | |
| 11857 | response = trans2.GetResponseInfo(); |
| 11858 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11859 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11860 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11861 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11862 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11863 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11864 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11865 | } |
| 11866 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11867 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11868 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11869 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11870 | |
| 11871 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11872 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 11873 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11874 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11875 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11876 | |
| 11877 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11878 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11880 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11881 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11882 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11883 | scoped_ptr<SpdyFrame> host2_req( |
| 11884 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11885 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11886 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11887 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11888 | scoped_ptr<SpdyFrame> host1_resp( |
| 11889 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11890 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11891 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11892 | scoped_ptr<SpdyFrame> host2_resp( |
| 11893 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11894 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11895 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11896 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11897 | CreateMockRead(*host1_resp, 1), |
| 11898 | CreateMockRead(*host1_resp_body, 2), |
| 11899 | CreateMockRead(*host2_resp, 4), |
| 11900 | CreateMockRead(*host2_resp_body, 5), |
| 11901 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11902 | }; |
| 11903 | |
| 11904 | IPAddressNumber ip; |
| 11905 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11906 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11907 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11908 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11909 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11910 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11911 | |
| 11912 | TestCompletionCallback callback; |
| 11913 | HttpRequestInfo request1; |
| 11914 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11915 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11916 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11917 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11918 | |
| 11919 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11921 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11922 | |
| 11923 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11924 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11925 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11926 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11927 | |
| 11928 | std::string response_data; |
| 11929 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11930 | EXPECT_EQ("hello!", response_data); |
| 11931 | |
| 11932 | HttpRequestInfo request2; |
| 11933 | request2.method = "GET"; |
| 11934 | request2.url = GURL("https://www.gmail.com/"); |
| 11935 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11936 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11937 | |
| 11938 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11939 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11940 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11941 | |
| 11942 | response = trans2.GetResponseInfo(); |
| 11943 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11944 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11945 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11946 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11947 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11948 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11949 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11950 | } |
| 11951 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11952 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11953 | public: |
| 11954 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11955 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11956 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11957 | |
| 11958 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11959 | |
| 11960 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11961 | int Resolve(const RequestInfo& info, |
| 11962 | RequestPriority priority, |
| 11963 | AddressList* addresses, |
| 11964 | const CompletionCallback& callback, |
| 11965 | RequestHandle* out_req, |
| 11966 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11967 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11968 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11969 | } |
| 11970 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11971 | int ResolveFromCache(const RequestInfo& info, |
| 11972 | AddressList* addresses, |
| 11973 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11974 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11975 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11976 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11977 | return rv; |
| 11978 | } |
| 11979 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11980 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11981 | host_resolver_.CancelRequest(req); |
| 11982 | } |
| 11983 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11984 | MockCachingHostResolver* GetMockHostResolver() { |
| 11985 | return &host_resolver_; |
| 11986 | } |
| 11987 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11988 | private: |
| 11989 | MockCachingHostResolver host_resolver_; |
| 11990 | const HostPortPair host_port_; |
| 11991 | }; |
| 11992 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11993 | TEST_P(HttpNetworkTransactionTest, |
| 11994 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11995 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11996 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11997 | |
| 11998 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11999 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12000 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12001 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12002 | params.host_resolver = &host_resolver; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12003 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12004 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12005 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12006 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12007 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12008 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12009 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12010 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12011 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12012 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12013 | scoped_ptr<SpdyFrame> host2_req( |
| 12014 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12015 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12016 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12017 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12018 | scoped_ptr<SpdyFrame> host1_resp( |
| 12019 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12020 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12021 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12022 | scoped_ptr<SpdyFrame> host2_resp( |
| 12023 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12024 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12025 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12026 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12027 | CreateMockRead(*host1_resp, 1), |
| 12028 | CreateMockRead(*host1_resp_body, 2), |
| 12029 | CreateMockRead(*host2_resp, 4), |
| 12030 | CreateMockRead(*host2_resp_body, 5), |
| 12031 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12032 | }; |
| 12033 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12034 | IPAddressNumber ip; |
| 12035 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12036 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12037 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12038 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12039 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12040 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12041 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12042 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12043 | HttpRequestInfo request1; |
| 12044 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12045 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12046 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12047 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12049 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12050 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12051 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12052 | |
| 12053 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12054 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12055 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12056 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12057 | |
| 12058 | std::string response_data; |
| 12059 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12060 | EXPECT_EQ("hello!", response_data); |
| 12061 | |
| 12062 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12063 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12064 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12065 | rv = host_resolver.Resolve(resolve_info, |
| 12066 | DEFAULT_PRIORITY, |
| 12067 | &ignored, |
| 12068 | callback.callback(), |
| 12069 | NULL, |
| 12070 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12072 | rv = callback.WaitForResult(); |
| 12073 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12074 | |
| 12075 | HttpRequestInfo request2; |
| 12076 | request2.method = "GET"; |
| 12077 | request2.url = GURL("https://www.gmail.com/"); |
| 12078 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12079 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12081 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12083 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12084 | |
| 12085 | response = trans2.GetResponseInfo(); |
| 12086 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12087 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12089 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12090 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12091 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12092 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12093 | } |
| 12094 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12095 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12096 | const std::string https_url = "https://www.example.org:8080/"; |
| 12097 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12098 | |
| 12099 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12100 | scoped_ptr<SpdyFrame> req1( |
| 12101 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12102 | |
| 12103 | MockWrite writes1[] = { |
| 12104 | CreateMockWrite(*req1, 0), |
| 12105 | }; |
| 12106 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12107 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12108 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12109 | MockRead reads1[] = { |
| 12110 | CreateMockRead(*resp1, 1), |
| 12111 | CreateMockRead(*body1, 2), |
| 12112 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12113 | }; |
| 12114 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12115 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12116 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12117 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12118 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12119 | |
| 12120 | // HTTP GET for the HTTP URL |
| 12121 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12122 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12123 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12124 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12125 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12126 | }; |
| 12127 | |
| 12128 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12129 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12130 | MockRead(ASYNC, 2, "hello"), |
| 12131 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12132 | }; |
| 12133 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12134 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12135 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12136 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12137 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12138 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12139 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12140 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12141 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12142 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12143 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12144 | |
| 12145 | // Start the first transaction to set up the SpdySession |
| 12146 | HttpRequestInfo request1; |
| 12147 | request1.method = "GET"; |
| 12148 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12149 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12150 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12151 | TestCompletionCallback callback1; |
| 12152 | EXPECT_EQ(ERR_IO_PENDING, |
| 12153 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12154 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12155 | |
| 12156 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12157 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12158 | |
| 12159 | // Now, start the HTTP request |
| 12160 | HttpRequestInfo request2; |
| 12161 | request2.method = "GET"; |
| 12162 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12163 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12164 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12165 | TestCompletionCallback callback2; |
| 12166 | EXPECT_EQ(ERR_IO_PENDING, |
| 12167 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12168 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12169 | |
| 12170 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12171 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12172 | } |
| 12173 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12174 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12175 | public: |
| 12176 | void Run(bool pooling, bool valid) { |
| 12177 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12178 | 443); |
| 12179 | HostPortPair alternative("www.example.org", 443); |
| 12180 | |
| 12181 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12182 | scoped_refptr<X509Certificate> cert( |
| 12183 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12184 | ASSERT_TRUE(cert.get()); |
| 12185 | bool common_name_fallback_used; |
| 12186 | EXPECT_EQ(valid, |
| 12187 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12188 | EXPECT_TRUE( |
| 12189 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12190 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12191 | ssl.SetNextProto(GetParam()); |
| 12192 | ssl.cert = cert; |
| 12193 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12194 | |
| 12195 | // If pooling, then start a request to alternative first to create a |
| 12196 | // SpdySession. |
| 12197 | std::string url0 = "https://www.example.org:443"; |
| 12198 | // Second request to origin, which has an alternative service, and could |
| 12199 | // open a connection to the alternative host or pool to the existing one. |
| 12200 | std::string url1("https://"); |
| 12201 | url1.append(origin.host()); |
| 12202 | url1.append(":443"); |
| 12203 | |
| 12204 | scoped_ptr<SpdyFrame> req0; |
| 12205 | scoped_ptr<SpdyFrame> req1; |
| 12206 | scoped_ptr<SpdyFrame> resp0; |
| 12207 | scoped_ptr<SpdyFrame> body0; |
| 12208 | scoped_ptr<SpdyFrame> resp1; |
| 12209 | scoped_ptr<SpdyFrame> body1; |
| 12210 | std::vector<MockWrite> writes; |
| 12211 | std::vector<MockRead> reads; |
| 12212 | |
| 12213 | if (pooling) { |
| 12214 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12215 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12216 | |
| 12217 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12218 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12219 | |
| 12220 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12221 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12222 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12223 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12224 | |
| 12225 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12226 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12227 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12228 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12229 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12230 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12231 | } else { |
| 12232 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12233 | |
| 12234 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12235 | |
| 12236 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12237 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12238 | |
| 12239 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12240 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12241 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12242 | } |
| 12243 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12244 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12245 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12246 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12247 | |
| 12248 | // Connection to the origin fails. |
| 12249 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12250 | StaticSocketDataProvider data_refused; |
| 12251 | data_refused.set_connect_data(mock_connect); |
| 12252 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12253 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12254 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12255 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12256 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12257 | session->http_server_properties(); |
| 12258 | AlternativeService alternative_service( |
| 12259 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12260 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12261 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12262 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12263 | |
| 12264 | // First request to alternative. |
| 12265 | if (pooling) { |
| 12266 | scoped_ptr<HttpTransaction> trans0( |
| 12267 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12268 | HttpRequestInfo request0; |
| 12269 | request0.method = "GET"; |
| 12270 | request0.url = GURL(url0); |
| 12271 | request0.load_flags = 0; |
| 12272 | TestCompletionCallback callback0; |
| 12273 | |
| 12274 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12276 | rv = callback0.WaitForResult(); |
| 12277 | EXPECT_EQ(OK, rv); |
| 12278 | } |
| 12279 | |
| 12280 | // Second request to origin. |
| 12281 | scoped_ptr<HttpTransaction> trans1( |
| 12282 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12283 | HttpRequestInfo request1; |
| 12284 | request1.method = "GET"; |
| 12285 | request1.url = GURL(url1); |
| 12286 | request1.load_flags = 0; |
| 12287 | TestCompletionCallback callback1; |
| 12288 | |
| 12289 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12291 | base::MessageLoop::current()->RunUntilIdle(); |
| 12292 | if (data.IsReadPaused()) { |
| 12293 | data.CompleteRead(); |
| 12294 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12295 | rv = callback1.WaitForResult(); |
| 12296 | if (valid) { |
| 12297 | EXPECT_EQ(OK, rv); |
| 12298 | } else { |
| 12299 | if (pooling) { |
| 12300 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12301 | } else { |
| 12302 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12303 | } |
| 12304 | } |
| 12305 | } |
| 12306 | }; |
| 12307 | |
| 12308 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12309 | AltSvcCertificateVerificationTest, |
| 12310 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12311 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12312 | |
| 12313 | // The alternative service host must exhibit a certificate that is valid for the |
| 12314 | // origin host. Test that this is enforced when pooling to an existing |
| 12315 | // connection. |
| 12316 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12317 | Run(true, true); |
| 12318 | } |
| 12319 | |
| 12320 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12321 | Run(true, false); |
| 12322 | } |
| 12323 | |
| 12324 | // The alternative service host must exhibit a certificate that is valid for the |
| 12325 | // origin host. Test that this is enforced when opening a new connection. |
| 12326 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12327 | Run(false, true); |
| 12328 | } |
| 12329 | |
| 12330 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12331 | Run(false, false); |
| 12332 | } |
| 12333 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12334 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12335 | // with the alternative server. That connection should not be used. |
| 12336 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12337 | HostPortPair origin("origin.example.org", 443); |
| 12338 | HostPortPair alternative("alternative.example.org", 443); |
| 12339 | |
| 12340 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12341 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12342 | ssl.SetNextProto(kProtoHTTP11); |
| 12343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12344 | |
| 12345 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12346 | // negotiated. |
| 12347 | StaticSocketDataProvider data; |
| 12348 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12349 | |
| 12350 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12351 | // negotiated. In order to test this, a failed connection to the origin is |
| 12352 | // mocked. This way the request relies on the alternate Job. |
| 12353 | StaticSocketDataProvider data_refused; |
| 12354 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12355 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12356 | |
| 12357 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12358 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12359 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12360 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12361 | session->http_server_properties(); |
| 12362 | AlternativeService alternative_service( |
| 12363 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12364 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12365 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12366 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12367 | |
| 12368 | scoped_ptr<HttpTransaction> trans( |
| 12369 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12370 | HttpRequestInfo request; |
| 12371 | request.method = "GET"; |
| 12372 | request.url = GURL("https://origin.example.org:443"); |
| 12373 | request.load_flags = 0; |
| 12374 | TestCompletionCallback callback; |
| 12375 | |
| 12376 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12377 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12378 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12379 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12380 | } |
| 12381 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12382 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12383 | // origin, and an alternate one to the alternative server. If the former |
| 12384 | // succeeds, the request should succeed, even if the latter fails because |
| 12385 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12386 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12387 | HostPortPair origin("origin.example.org", 443); |
| 12388 | HostPortPair alternative("alternative.example.org", 443); |
| 12389 | |
| 12390 | // Negotiate HTTP/1.1 with alternative. |
| 12391 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12392 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12394 | |
| 12395 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12396 | // negotiated. |
| 12397 | StaticSocketDataProvider data; |
| 12398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12399 | |
| 12400 | // Negotiate HTTP/1.1 with origin. |
| 12401 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12402 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12404 | |
| 12405 | MockWrite http_writes[] = { |
| 12406 | MockWrite( |
| 12407 | "GET / HTTP/1.1\r\n" |
| 12408 | "Host: origin.example.org\r\n" |
| 12409 | "Connection: keep-alive\r\n\r\n"), |
| 12410 | MockWrite( |
| 12411 | "GET /second HTTP/1.1\r\n" |
| 12412 | "Host: origin.example.org\r\n" |
| 12413 | "Connection: keep-alive\r\n\r\n"), |
| 12414 | }; |
| 12415 | |
| 12416 | MockRead http_reads[] = { |
| 12417 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12418 | MockRead("Content-Type: text/html\r\n"), |
| 12419 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12420 | MockRead("foobar"), |
| 12421 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12422 | MockRead("Content-Type: text/html\r\n"), |
| 12423 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12424 | MockRead("another"), |
| 12425 | }; |
| 12426 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12427 | http_writes, arraysize(http_writes)); |
| 12428 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12429 | |
| 12430 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12431 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12432 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12433 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12434 | session->http_server_properties(); |
| 12435 | AlternativeService alternative_service( |
| 12436 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12437 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12438 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12439 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12440 | |
| 12441 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12442 | HttpRequestInfo request1; |
| 12443 | request1.method = "GET"; |
| 12444 | request1.url = GURL("https://origin.example.org:443"); |
| 12445 | request1.load_flags = 0; |
| 12446 | TestCompletionCallback callback1; |
| 12447 | |
| 12448 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12449 | rv = callback1.GetResult(rv); |
| 12450 | EXPECT_EQ(OK, rv); |
| 12451 | |
| 12452 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12453 | ASSERT_TRUE(response1 != nullptr); |
| 12454 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12455 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12456 | |
| 12457 | std::string response_data1; |
| 12458 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12459 | EXPECT_EQ("foobar", response_data1); |
| 12460 | |
| 12461 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12462 | // for alternative service. |
| 12463 | EXPECT_TRUE( |
| 12464 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12465 | |
| 12466 | // Since |alternative_service| is broken, a second transaction to origin |
| 12467 | // should not start an alternate Job. It should pool to existing connection |
| 12468 | // to origin. |
| 12469 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12470 | HttpRequestInfo request2; |
| 12471 | request2.method = "GET"; |
| 12472 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12473 | request2.load_flags = 0; |
| 12474 | TestCompletionCallback callback2; |
| 12475 | |
| 12476 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12477 | rv = callback2.GetResult(rv); |
| 12478 | EXPECT_EQ(OK, rv); |
| 12479 | |
| 12480 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12481 | ASSERT_TRUE(response2 != nullptr); |
| 12482 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12483 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12484 | |
| 12485 | std::string response_data2; |
| 12486 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12487 | EXPECT_EQ("another", response_data2); |
| 12488 | } |
| 12489 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12490 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12491 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12492 | // used. |
| 12493 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12494 | HostPortPair origin("origin.example.org", 443); |
| 12495 | HostPortPair alternative("alternative.example.org", 443); |
| 12496 | std::string origin_url = "https://origin.example.org:443"; |
| 12497 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12498 | |
| 12499 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12501 | ssl.SetNextProto(kProtoHTTP11); |
| 12502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12503 | |
| 12504 | // HTTP/1.1 data for |request1| and |request2|. |
| 12505 | MockWrite http_writes[] = { |
| 12506 | MockWrite( |
| 12507 | "GET / HTTP/1.1\r\n" |
| 12508 | "Host: alternative.example.org\r\n" |
| 12509 | "Connection: keep-alive\r\n\r\n"), |
| 12510 | MockWrite( |
| 12511 | "GET / HTTP/1.1\r\n" |
| 12512 | "Host: alternative.example.org\r\n" |
| 12513 | "Connection: keep-alive\r\n\r\n"), |
| 12514 | }; |
| 12515 | |
| 12516 | MockRead http_reads[] = { |
| 12517 | MockRead( |
| 12518 | "HTTP/1.1 200 OK\r\n" |
| 12519 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12520 | "Content-Length: 40\r\n\r\n" |
| 12521 | "first HTTP/1.1 response from alternative"), |
| 12522 | MockRead( |
| 12523 | "HTTP/1.1 200 OK\r\n" |
| 12524 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12525 | "Content-Length: 41\r\n\r\n" |
| 12526 | "second HTTP/1.1 response from alternative"), |
| 12527 | }; |
| 12528 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12529 | http_writes, arraysize(http_writes)); |
| 12530 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12531 | |
| 12532 | // This test documents that an alternate Job should not pool to an already |
| 12533 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12534 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12535 | StaticSocketDataProvider data_refused; |
| 12536 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12537 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12538 | |
| 12539 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12540 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12541 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12542 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12543 | session->http_server_properties(); |
| 12544 | AlternativeService alternative_service( |
| 12545 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12546 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12547 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12548 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12549 | |
| 12550 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12551 | scoped_ptr<HttpTransaction> trans1( |
| 12552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12553 | HttpRequestInfo request1; |
| 12554 | request1.method = "GET"; |
| 12555 | request1.url = GURL(alternative_url); |
| 12556 | request1.load_flags = 0; |
| 12557 | TestCompletionCallback callback1; |
| 12558 | |
| 12559 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12560 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12561 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12562 | ASSERT_TRUE(response1); |
| 12563 | ASSERT_TRUE(response1->headers.get()); |
| 12564 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12565 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12566 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12567 | std::string response_data1; |
| 12568 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12569 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12570 | |
| 12571 | // Request for origin.example.org, which has an alternative service. This |
| 12572 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12573 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12574 | // open other connections to alternative server. The Job to origin fails, so |
| 12575 | // this request fails. |
| 12576 | scoped_ptr<HttpTransaction> trans2( |
| 12577 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12578 | HttpRequestInfo request2; |
| 12579 | request2.method = "GET"; |
| 12580 | request2.url = GURL(origin_url); |
| 12581 | request2.load_flags = 0; |
| 12582 | TestCompletionCallback callback2; |
| 12583 | |
| 12584 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12585 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12586 | |
| 12587 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12588 | // socket is still open and in the pool. |
| 12589 | scoped_ptr<HttpTransaction> trans3( |
| 12590 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12591 | HttpRequestInfo request3; |
| 12592 | request3.method = "GET"; |
| 12593 | request3.url = GURL(alternative_url); |
| 12594 | request3.load_flags = 0; |
| 12595 | TestCompletionCallback callback3; |
| 12596 | |
| 12597 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12598 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12599 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12600 | ASSERT_TRUE(response3); |
| 12601 | ASSERT_TRUE(response3->headers.get()); |
| 12602 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12603 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12604 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12605 | std::string response_data3; |
| 12606 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12607 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12608 | } |
| 12609 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12610 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12611 | const std::string https_url = "https://www.example.org:8080/"; |
| 12612 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12613 | |
| 12614 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12615 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12616 | scoped_ptr<SpdyFrame> connect( |
| 12617 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12618 | scoped_ptr<SpdyFrame> req1( |
| 12619 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12620 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12621 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12622 | |
| 12623 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12624 | SpdyHeaderBlock req2_block; |
| 12625 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 12626 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12627 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12628 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 12629 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12630 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12631 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12632 | |
| 12633 | MockWrite writes1[] = { |
| 12634 | CreateMockWrite(*connect, 0), |
| 12635 | CreateMockWrite(*wrapped_req1, 2), |
| 12636 | CreateMockWrite(*req2, 5), |
| 12637 | }; |
| 12638 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12639 | scoped_ptr<SpdyFrame> conn_resp( |
| 12640 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12641 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12642 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12643 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12644 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12645 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12646 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12647 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12648 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12649 | MockRead reads1[] = { |
| 12650 | CreateMockRead(*conn_resp, 1), |
| 12651 | CreateMockRead(*wrapped_resp1, 3), |
| 12652 | CreateMockRead(*wrapped_body1, 4), |
| 12653 | CreateMockRead(*resp2, 6), |
| 12654 | CreateMockRead(*body2, 7), |
| 12655 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12656 | }; |
| 12657 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12658 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12659 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12660 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12661 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12662 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12663 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12664 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12665 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12666 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12667 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12668 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12669 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12670 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12671 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12672 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12673 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12674 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12675 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12676 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12677 | |
| 12678 | // Start the first transaction to set up the SpdySession |
| 12679 | HttpRequestInfo request1; |
| 12680 | request1.method = "GET"; |
| 12681 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12682 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12683 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12684 | TestCompletionCallback callback1; |
| 12685 | EXPECT_EQ(ERR_IO_PENDING, |
| 12686 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12687 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12688 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12689 | |
| 12690 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12691 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12692 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12693 | LoadTimingInfo load_timing_info1; |
| 12694 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12695 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12696 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12697 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12698 | // Now, start the HTTP request |
| 12699 | HttpRequestInfo request2; |
| 12700 | request2.method = "GET"; |
| 12701 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12702 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12703 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12704 | TestCompletionCallback callback2; |
| 12705 | EXPECT_EQ(ERR_IO_PENDING, |
| 12706 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12707 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12708 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12709 | |
| 12710 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12711 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12712 | |
| 12713 | LoadTimingInfo load_timing_info2; |
| 12714 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12715 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12716 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12717 | // HTTP requests over a SPDY session should have a different connection |
| 12718 | // socket_log_id than requests over a tunnel. |
| 12719 | 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] | 12720 | } |
| 12721 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12722 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12723 | // that we do not pool other origins that resolve to the same IP when |
| 12724 | // the certificate does not match the new origin. |
| 12725 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12726 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12727 | const std::string url1 = "http://www.example.org/"; |
| 12728 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12729 | const std::string ip_addr = "1.2.3.4"; |
| 12730 | |
| 12731 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12732 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12733 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12734 | scoped_ptr<SpdyFrame> req1( |
| 12735 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12736 | |
| 12737 | MockWrite writes1[] = { |
| 12738 | CreateMockWrite(*req1, 0), |
| 12739 | }; |
| 12740 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12741 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12742 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12743 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12744 | CreateMockRead(*resp1, 1), |
| 12745 | CreateMockRead(*body1, 2), |
| 12746 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12747 | }; |
| 12748 | |
| 12749 | scoped_ptr<DeterministicSocketData> data1( |
| 12750 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12751 | writes1, arraysize(writes1))); |
| 12752 | IPAddressNumber ip; |
| 12753 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12754 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12755 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12756 | data1->set_connect_data(connect_data1); |
| 12757 | |
| 12758 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12759 | scoped_ptr<SpdyFrame> req2( |
| 12760 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12761 | |
| 12762 | MockWrite writes2[] = { |
| 12763 | CreateMockWrite(*req2, 0), |
| 12764 | }; |
| 12765 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12766 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12767 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12768 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12769 | CreateMockRead(*resp2, 1), |
| 12770 | CreateMockRead(*body2, 2), |
| 12771 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12772 | }; |
| 12773 | |
| 12774 | scoped_ptr<DeterministicSocketData> data2( |
| 12775 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12776 | writes2, arraysize(writes2))); |
| 12777 | MockConnect connect_data2(ASYNC, OK); |
| 12778 | data2->set_connect_data(connect_data2); |
| 12779 | |
| 12780 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12781 | // all others direct. |
| 12782 | ProxyConfig proxy_config; |
| 12783 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12784 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12785 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12786 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12787 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12788 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12789 | // Load a valid cert. Note, that this does not need to |
| 12790 | // be valid for proxy because the MockSSLClientSocket does |
| 12791 | // not actually verify it. But SpdySession will use this |
| 12792 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12793 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12794 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12795 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12796 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12797 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12798 | |
| 12799 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12800 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12801 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12802 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12803 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12804 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12805 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12806 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12807 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12808 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12809 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12810 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12811 | |
| 12812 | // Start the first transaction to set up the SpdySession |
| 12813 | HttpRequestInfo request1; |
| 12814 | request1.method = "GET"; |
| 12815 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12816 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12817 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12818 | TestCompletionCallback callback1; |
| 12819 | ASSERT_EQ(ERR_IO_PENDING, |
| 12820 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12821 | data1->RunFor(3); |
| 12822 | |
| 12823 | ASSERT_TRUE(callback1.have_result()); |
| 12824 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12825 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12826 | |
| 12827 | // Now, start the HTTP request |
| 12828 | HttpRequestInfo request2; |
| 12829 | request2.method = "GET"; |
| 12830 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12831 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12832 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12833 | TestCompletionCallback callback2; |
| 12834 | EXPECT_EQ(ERR_IO_PENDING, |
| 12835 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12836 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12837 | data2->RunFor(3); |
| 12838 | |
| 12839 | ASSERT_TRUE(callback2.have_result()); |
| 12840 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12841 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12842 | } |
| 12843 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12844 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12845 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12846 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12847 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12848 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12849 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12850 | |
| 12851 | MockRead reads1[] = { |
| 12852 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12853 | }; |
| 12854 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12855 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12856 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12857 | scoped_ptr<SpdyFrame> req2( |
| 12858 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12859 | MockWrite writes2[] = { |
| 12860 | CreateMockWrite(*req2, 0), |
| 12861 | }; |
| 12862 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12863 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12864 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12865 | MockRead reads2[] = { |
| 12866 | CreateMockRead(*resp2, 1), |
| 12867 | CreateMockRead(*body2, 2), |
| 12868 | MockRead(ASYNC, OK, 3) // EOF |
| 12869 | }; |
| 12870 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12871 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12872 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12873 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12874 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12875 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12876 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12878 | |
| 12879 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12880 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12882 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12883 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12884 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12885 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12886 | |
| 12887 | // Start the first transaction to set up the SpdySession and verify that |
| 12888 | // connection was closed. |
| 12889 | HttpRequestInfo request1; |
| 12890 | request1.method = "GET"; |
| 12891 | request1.url = GURL(https_url); |
| 12892 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12893 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12894 | TestCompletionCallback callback1; |
| 12895 | EXPECT_EQ(ERR_IO_PENDING, |
| 12896 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12897 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12898 | |
| 12899 | // Now, start the second request and make sure it succeeds. |
| 12900 | HttpRequestInfo request2; |
| 12901 | request2.method = "GET"; |
| 12902 | request2.url = GURL(https_url); |
| 12903 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12904 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12905 | TestCompletionCallback callback2; |
| 12906 | EXPECT_EQ(ERR_IO_PENDING, |
| 12907 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12908 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12909 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12910 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12911 | } |
| 12912 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12913 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12914 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12915 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12916 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12917 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12918 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12919 | |
| 12920 | // Use two different hosts with different IPs so they don't get pooled. |
| 12921 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12922 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 12923 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12924 | |
| 12925 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12926 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12927 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12928 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12931 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12932 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12933 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12934 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12935 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12936 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12937 | scoped_ptr<SpdyFrame> host1_resp( |
| 12938 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12939 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12940 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12941 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12942 | CreateMockRead(*host1_resp, 1), |
| 12943 | CreateMockRead(*host1_resp_body, 2), |
| 12944 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12945 | }; |
| 12946 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12947 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12948 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12949 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12950 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12951 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12952 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12953 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12954 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12955 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12956 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12957 | scoped_ptr<SpdyFrame> host2_resp( |
| 12958 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12959 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12960 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12961 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12962 | CreateMockRead(*host2_resp, 1), |
| 12963 | CreateMockRead(*host2_resp_body, 2), |
| 12964 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12965 | }; |
| 12966 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12967 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12968 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12969 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12970 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12971 | |
| 12972 | MockWrite http_write[] = { |
| 12973 | MockWrite("GET / HTTP/1.1\r\n" |
| 12974 | "Host: www.a.com\r\n" |
| 12975 | "Connection: keep-alive\r\n\r\n"), |
| 12976 | }; |
| 12977 | |
| 12978 | MockRead http_read[] = { |
| 12979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12980 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12981 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12982 | MockRead("hello!"), |
| 12983 | }; |
| 12984 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12985 | http_write, arraysize(http_write)); |
| 12986 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12987 | |
| 12988 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12989 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12990 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12991 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12992 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12993 | |
| 12994 | TestCompletionCallback callback; |
| 12995 | HttpRequestInfo request1; |
| 12996 | request1.method = "GET"; |
| 12997 | request1.url = GURL("https://www.a.com/"); |
| 12998 | request1.load_flags = 0; |
| 12999 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13001 | |
| 13002 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13004 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13005 | |
| 13006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13007 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13008 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13009 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13010 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13011 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13012 | |
| 13013 | std::string response_data; |
| 13014 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13015 | EXPECT_EQ("hello!", response_data); |
| 13016 | trans.reset(); |
| 13017 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13018 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13019 | |
| 13020 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13021 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13022 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13023 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13024 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13025 | HttpRequestInfo request2; |
| 13026 | request2.method = "GET"; |
| 13027 | request2.url = GURL("https://www.b.com/"); |
| 13028 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13029 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13030 | |
| 13031 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13033 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13034 | |
| 13035 | response = trans->GetResponseInfo(); |
| 13036 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13037 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13038 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13039 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13040 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13041 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13042 | EXPECT_EQ("hello!", response_data); |
| 13043 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13044 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13045 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13046 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13047 | |
| 13048 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13049 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13050 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13051 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13052 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13053 | HttpRequestInfo request3; |
| 13054 | request3.method = "GET"; |
| 13055 | request3.url = GURL("http://www.a.com/"); |
| 13056 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13057 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13058 | |
| 13059 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13061 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13062 | |
| 13063 | response = trans->GetResponseInfo(); |
| 13064 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13065 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13066 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13067 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13068 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13069 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13070 | EXPECT_EQ("hello!", response_data); |
| 13071 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13072 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13073 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13074 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13075 | } |
| 13076 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13077 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13078 | HttpRequestInfo request; |
| 13079 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13080 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13081 | request.load_flags = 0; |
| 13082 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13083 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13084 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13085 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13086 | |
| 13087 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 13088 | StaticSocketDataProvider data; |
| 13089 | data.set_connect_data(mock_connect); |
| 13090 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13091 | |
| 13092 | TestCompletionCallback callback; |
| 13093 | |
| 13094 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13096 | |
| 13097 | rv = callback.WaitForResult(); |
| 13098 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13099 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13100 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13101 | HttpRequestHeaders request_headers; |
| 13102 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13103 | |
| 13104 | ConnectionAttempts attempts; |
| 13105 | trans->GetConnectionAttempts(&attempts); |
| 13106 | ASSERT_EQ(1u, attempts.size()); |
| 13107 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13108 | } |
| 13109 | |
| 13110 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13111 | HttpRequestInfo request; |
| 13112 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13113 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13114 | request.load_flags = 0; |
| 13115 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13116 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13117 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13119 | |
| 13120 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13121 | StaticSocketDataProvider data; |
| 13122 | data.set_connect_data(mock_connect); |
| 13123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13124 | |
| 13125 | TestCompletionCallback callback; |
| 13126 | |
| 13127 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13129 | |
| 13130 | rv = callback.WaitForResult(); |
| 13131 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13132 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13133 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13134 | HttpRequestHeaders request_headers; |
| 13135 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13136 | |
| 13137 | ConnectionAttempts attempts; |
| 13138 | trans->GetConnectionAttempts(&attempts); |
| 13139 | ASSERT_EQ(1u, attempts.size()); |
| 13140 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13141 | } |
| 13142 | |
| 13143 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13144 | HttpRequestInfo request; |
| 13145 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13146 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13147 | request.load_flags = 0; |
| 13148 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13149 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13150 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13151 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13152 | |
| 13153 | MockWrite data_writes[] = { |
| 13154 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13155 | }; |
| 13156 | MockRead data_reads[] = { |
| 13157 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13158 | }; |
| 13159 | |
| 13160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13161 | data_writes, arraysize(data_writes)); |
| 13162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13163 | |
| 13164 | TestCompletionCallback callback; |
| 13165 | |
| 13166 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13167 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13168 | |
| 13169 | rv = callback.WaitForResult(); |
| 13170 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13171 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13172 | HttpRequestHeaders request_headers; |
| 13173 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13174 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13175 | } |
| 13176 | |
| 13177 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13178 | HttpRequestInfo request; |
| 13179 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13180 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13181 | request.load_flags = 0; |
| 13182 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13183 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13184 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13185 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13186 | |
| 13187 | MockWrite data_writes[] = { |
| 13188 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13189 | }; |
| 13190 | MockRead data_reads[] = { |
| 13191 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13192 | }; |
| 13193 | |
| 13194 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13195 | data_writes, arraysize(data_writes)); |
| 13196 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13197 | |
| 13198 | TestCompletionCallback callback; |
| 13199 | |
| 13200 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13201 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13202 | |
| 13203 | rv = callback.WaitForResult(); |
| 13204 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13205 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13206 | HttpRequestHeaders request_headers; |
| 13207 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13208 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13209 | } |
| 13210 | |
| 13211 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13212 | HttpRequestInfo request; |
| 13213 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13214 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13215 | request.load_flags = 0; |
| 13216 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13217 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13218 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13219 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13220 | |
| 13221 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13222 | MockWrite( |
| 13223 | "GET / HTTP/1.1\r\n" |
| 13224 | "Host: www.example.org\r\n" |
| 13225 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13226 | }; |
| 13227 | MockRead data_reads[] = { |
| 13228 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13229 | }; |
| 13230 | |
| 13231 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13232 | data_writes, arraysize(data_writes)); |
| 13233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13234 | |
| 13235 | TestCompletionCallback callback; |
| 13236 | |
| 13237 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13238 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13239 | |
| 13240 | rv = callback.WaitForResult(); |
| 13241 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13242 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13243 | HttpRequestHeaders request_headers; |
| 13244 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13245 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13246 | } |
| 13247 | |
| 13248 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13249 | HttpRequestInfo request; |
| 13250 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13251 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13252 | request.load_flags = 0; |
| 13253 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13254 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13255 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13256 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13257 | |
| 13258 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13259 | MockWrite( |
| 13260 | "GET / HTTP/1.1\r\n" |
| 13261 | "Host: www.example.org\r\n" |
| 13262 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13263 | }; |
| 13264 | MockRead data_reads[] = { |
| 13265 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13266 | }; |
| 13267 | |
| 13268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13269 | data_writes, arraysize(data_writes)); |
| 13270 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13271 | |
| 13272 | TestCompletionCallback callback; |
| 13273 | |
| 13274 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13276 | |
| 13277 | rv = callback.WaitForResult(); |
| 13278 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13279 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13280 | HttpRequestHeaders request_headers; |
| 13281 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13282 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13283 | } |
| 13284 | |
| 13285 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13286 | HttpRequestInfo request; |
| 13287 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13288 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13289 | request.load_flags = 0; |
| 13290 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13291 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13292 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13293 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13295 | |
| 13296 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13297 | MockWrite( |
| 13298 | "GET / HTTP/1.1\r\n" |
| 13299 | "Host: www.example.org\r\n" |
| 13300 | "Connection: keep-alive\r\n" |
| 13301 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13302 | }; |
| 13303 | MockRead data_reads[] = { |
| 13304 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13305 | "Content-Length: 5\r\n\r\n" |
| 13306 | "hello"), |
| 13307 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13308 | }; |
| 13309 | |
| 13310 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13311 | data_writes, arraysize(data_writes)); |
| 13312 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13313 | |
| 13314 | TestCompletionCallback callback; |
| 13315 | |
| 13316 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13317 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13318 | |
| 13319 | rv = callback.WaitForResult(); |
| 13320 | EXPECT_EQ(OK, rv); |
| 13321 | |
| 13322 | HttpRequestHeaders request_headers; |
| 13323 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13324 | std::string foo; |
| 13325 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13326 | EXPECT_EQ("bar", foo); |
| 13327 | } |
| 13328 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13329 | namespace { |
| 13330 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13331 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13332 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13333 | public base::SupportsWeakPtr<FakeStream> { |
| 13334 | public: |
| 13335 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13336 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13337 | |
| 13338 | RequestPriority priority() const { return priority_; } |
| 13339 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13340 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13341 | RequestPriority priority, |
| 13342 | const BoundNetLog& net_log, |
| 13343 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13344 | return ERR_IO_PENDING; |
| 13345 | } |
| 13346 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13347 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13348 | HttpResponseInfo* response, |
| 13349 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13350 | ADD_FAILURE(); |
| 13351 | return ERR_UNEXPECTED; |
| 13352 | } |
| 13353 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13354 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13355 | ADD_FAILURE(); |
| 13356 | return ERR_UNEXPECTED; |
| 13357 | } |
| 13358 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13359 | int ReadResponseBody(IOBuffer* buf, |
| 13360 | int buf_len, |
| 13361 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13362 | ADD_FAILURE(); |
| 13363 | return ERR_UNEXPECTED; |
| 13364 | } |
| 13365 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13366 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13367 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13368 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13369 | ADD_FAILURE(); |
| 13370 | return false; |
| 13371 | } |
| 13372 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13373 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13374 | ADD_FAILURE(); |
| 13375 | return false; |
| 13376 | } |
| 13377 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13378 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13379 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13380 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13381 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13382 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13383 | ADD_FAILURE(); |
| 13384 | return 0; |
| 13385 | } |
| 13386 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 13387 | int64_t GetTotalSentBytes() const override { |
| 13388 | ADD_FAILURE(); |
| 13389 | return 0; |
| 13390 | } |
| 13391 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13392 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13393 | ADD_FAILURE(); |
| 13394 | return false; |
| 13395 | } |
| 13396 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13397 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13398 | |
| 13399 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13400 | ADD_FAILURE(); |
| 13401 | } |
| 13402 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13403 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13404 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13405 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13406 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13407 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13408 | |
| 13409 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13410 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13411 | private: |
| 13412 | RequestPriority priority_; |
| 13413 | |
| 13414 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13415 | }; |
| 13416 | |
| 13417 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13418 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13419 | class FakeStreamRequest : public HttpStreamRequest, |
| 13420 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13421 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13422 | FakeStreamRequest(RequestPriority priority, |
| 13423 | HttpStreamRequest::Delegate* delegate) |
| 13424 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13425 | delegate_(delegate), |
| 13426 | websocket_stream_create_helper_(NULL) {} |
| 13427 | |
| 13428 | FakeStreamRequest(RequestPriority priority, |
| 13429 | HttpStreamRequest::Delegate* delegate, |
| 13430 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13431 | : priority_(priority), |
| 13432 | delegate_(delegate), |
| 13433 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13434 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13435 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13436 | |
| 13437 | RequestPriority priority() const { return priority_; } |
| 13438 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13439 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13440 | websocket_stream_create_helper() const { |
| 13441 | return websocket_stream_create_helper_; |
| 13442 | } |
| 13443 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13444 | // Create a new FakeStream and pass it to the request's |
| 13445 | // delegate. Returns a weak pointer to the FakeStream. |
| 13446 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13447 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13448 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13449 | // immediately delete |fake_stream|. |
| 13450 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13451 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13452 | return weak_stream; |
| 13453 | } |
| 13454 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13455 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13456 | ADD_FAILURE(); |
| 13457 | return ERR_UNEXPECTED; |
| 13458 | } |
| 13459 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13460 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13461 | ADD_FAILURE(); |
| 13462 | return LoadState(); |
| 13463 | } |
| 13464 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13465 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13466 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13467 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13468 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13469 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13470 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13471 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13472 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13473 | const ConnectionAttempts& connection_attempts() const override { |
| 13474 | static ConnectionAttempts no_attempts; |
| 13475 | return no_attempts; |
| 13476 | } |
| 13477 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13478 | private: |
| 13479 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13480 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13481 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13482 | |
| 13483 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13484 | }; |
| 13485 | |
| 13486 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13487 | class FakeStreamFactory : public HttpStreamFactory { |
| 13488 | public: |
| 13489 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13490 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13491 | |
| 13492 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13493 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13494 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13495 | return last_stream_request_; |
| 13496 | } |
| 13497 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13498 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13499 | RequestPriority priority, |
| 13500 | const SSLConfig& server_ssl_config, |
| 13501 | const SSLConfig& proxy_ssl_config, |
| 13502 | HttpStreamRequest::Delegate* delegate, |
| 13503 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13504 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13505 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13506 | return fake_request; |
| 13507 | } |
| 13508 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13509 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13510 | const HttpRequestInfo& info, |
| 13511 | RequestPriority priority, |
| 13512 | const SSLConfig& server_ssl_config, |
| 13513 | const SSLConfig& proxy_ssl_config, |
| 13514 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13515 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13516 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13517 | FakeStreamRequest* fake_request = |
| 13518 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13519 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13520 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13521 | } |
| 13522 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13523 | void PreconnectStreams(int num_streams, |
| 13524 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13525 | const SSLConfig& server_ssl_config, |
| 13526 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13527 | ADD_FAILURE(); |
| 13528 | } |
| 13529 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13530 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13531 | ADD_FAILURE(); |
| 13532 | return NULL; |
| 13533 | } |
| 13534 | |
| 13535 | private: |
| 13536 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13537 | |
| 13538 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13539 | }; |
| 13540 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13541 | // TODO(ricea): Maybe unify this with the one in |
| 13542 | // url_request_http_job_unittest.cc ? |
| 13543 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13544 | public: |
| 13545 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13546 | bool using_proxy) |
| 13547 | : state_(connection.release(), using_proxy) {} |
| 13548 | |
| 13549 | // Fake implementation of HttpStreamBase methods. |
| 13550 | // This ends up being quite "real" because this object has to really send data |
| 13551 | // on the mock socket. It might be easier to use the real implementation, but |
| 13552 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13553 | // difficult. |
| 13554 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13555 | RequestPriority priority, |
| 13556 | const BoundNetLog& net_log, |
| 13557 | const CompletionCallback& callback) override { |
| 13558 | state_.Initialize(request_info, priority, net_log, callback); |
| 13559 | return OK; |
| 13560 | } |
| 13561 | |
| 13562 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13563 | HttpResponseInfo* response, |
| 13564 | const CompletionCallback& callback) override { |
| 13565 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13566 | response, callback); |
| 13567 | } |
| 13568 | |
| 13569 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13570 | return parser()->ReadResponseHeaders(callback); |
| 13571 | } |
| 13572 | |
| 13573 | int ReadResponseBody(IOBuffer* buf, |
| 13574 | int buf_len, |
| 13575 | const CompletionCallback& callback) override { |
| 13576 | NOTREACHED(); |
| 13577 | return ERR_IO_PENDING; |
| 13578 | } |
| 13579 | |
| 13580 | void Close(bool not_reusable) override { |
| 13581 | if (parser()) |
| 13582 | parser()->Close(true); |
| 13583 | } |
| 13584 | |
| 13585 | bool IsResponseBodyComplete() const override { |
| 13586 | NOTREACHED(); |
| 13587 | return false; |
| 13588 | } |
| 13589 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13590 | bool IsConnectionReused() const override { |
| 13591 | NOTREACHED(); |
| 13592 | return false; |
| 13593 | } |
| 13594 | void SetConnectionReused() override { NOTREACHED(); } |
| 13595 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13596 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13597 | |
| 13598 | int64 GetTotalReceivedBytes() const override { |
| 13599 | NOTREACHED(); |
| 13600 | return 0; |
| 13601 | } |
| 13602 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 13603 | int64_t GetTotalSentBytes() const override { |
| 13604 | NOTREACHED(); |
| 13605 | return 0; |
| 13606 | } |
| 13607 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13608 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13609 | NOTREACHED(); |
| 13610 | return false; |
| 13611 | } |
| 13612 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13613 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13614 | |
| 13615 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13616 | NOTREACHED(); |
| 13617 | } |
| 13618 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13619 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13620 | |
| 13621 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13622 | |
| 13623 | UploadProgress GetUploadProgress() const override { |
| 13624 | NOTREACHED(); |
| 13625 | return UploadProgress(); |
| 13626 | } |
| 13627 | |
| 13628 | HttpStream* RenewStreamForAuth() override { |
| 13629 | NOTREACHED(); |
| 13630 | return nullptr; |
| 13631 | } |
| 13632 | |
| 13633 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13634 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13635 | NOTREACHED(); |
| 13636 | return scoped_ptr<WebSocketStream>(); |
| 13637 | } |
| 13638 | |
| 13639 | private: |
| 13640 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13641 | HttpBasicState state_; |
| 13642 | |
| 13643 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13644 | }; |
| 13645 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13646 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13647 | // worth doing. |
| 13648 | class FakeWebSocketStreamCreateHelper : |
| 13649 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13650 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13651 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13652 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13653 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13654 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13655 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13656 | } |
| 13657 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13658 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13659 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13660 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13661 | NOTREACHED(); |
| 13662 | return NULL; |
| 13663 | }; |
| 13664 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13665 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13666 | |
| 13667 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13668 | NOTREACHED(); |
| 13669 | return scoped_ptr<WebSocketStream>(); |
| 13670 | } |
| 13671 | }; |
| 13672 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13673 | } // namespace |
| 13674 | |
| 13675 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13676 | // stream request on start. |
| 13677 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13678 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13679 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13680 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13681 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13682 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13683 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13684 | |
| 13685 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13686 | |
| 13687 | HttpRequestInfo request; |
| 13688 | TestCompletionCallback callback; |
| 13689 | EXPECT_EQ(ERR_IO_PENDING, |
| 13690 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13691 | |
| 13692 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13693 | fake_factory->last_stream_request(); |
| 13694 | ASSERT_TRUE(fake_request != NULL); |
| 13695 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13696 | } |
| 13697 | |
| 13698 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13699 | // updates to its stream request. |
| 13700 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13701 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13702 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13703 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13704 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13705 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13706 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13707 | |
| 13708 | HttpRequestInfo request; |
| 13709 | TestCompletionCallback callback; |
| 13710 | EXPECT_EQ(ERR_IO_PENDING, |
| 13711 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13712 | |
| 13713 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13714 | fake_factory->last_stream_request(); |
| 13715 | ASSERT_TRUE(fake_request != NULL); |
| 13716 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13717 | |
| 13718 | trans.SetPriority(LOWEST); |
| 13719 | ASSERT_TRUE(fake_request != NULL); |
| 13720 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13721 | } |
| 13722 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13723 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13724 | // updates to its stream. |
| 13725 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13726 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13727 | HttpNetworkSessionPeer peer(session); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13728 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13729 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13730 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13731 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13732 | |
| 13733 | HttpRequestInfo request; |
| 13734 | TestCompletionCallback callback; |
| 13735 | EXPECT_EQ(ERR_IO_PENDING, |
| 13736 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13737 | |
| 13738 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13739 | fake_factory->last_stream_request(); |
| 13740 | ASSERT_TRUE(fake_request != NULL); |
| 13741 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13742 | ASSERT_TRUE(fake_stream != NULL); |
| 13743 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13744 | |
| 13745 | trans.SetPriority(LOWEST); |
| 13746 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13747 | } |
| 13748 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13749 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13750 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13751 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13752 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13753 | std::string test_cases[] = {"ws://www.example.org/", |
| 13754 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13755 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13756 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13757 | HttpNetworkSessionPeer peer(session); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13758 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13759 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13760 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13761 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13762 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13763 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13764 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13765 | &websocket_stream_create_helper); |
| 13766 | |
| 13767 | HttpRequestInfo request; |
| 13768 | TestCompletionCallback callback; |
| 13769 | request.method = "GET"; |
| 13770 | request.url = GURL(test_cases[i]); |
| 13771 | |
| 13772 | EXPECT_EQ(ERR_IO_PENDING, |
| 13773 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13774 | |
| 13775 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13776 | fake_factory->last_stream_request(); |
| 13777 | ASSERT_TRUE(fake_request != NULL); |
| 13778 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13779 | fake_request->websocket_stream_create_helper()); |
| 13780 | } |
| 13781 | } |
| 13782 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13783 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13784 | // if the transport socket pool is stalled on the global socket limit. |
| 13785 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13786 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13787 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13788 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13789 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13790 | |
| 13791 | // Set up SSL request. |
| 13792 | |
| 13793 | HttpRequestInfo ssl_request; |
| 13794 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13795 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13796 | |
| 13797 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13798 | MockWrite( |
| 13799 | "GET / HTTP/1.1\r\n" |
| 13800 | "Host: www.example.org\r\n" |
| 13801 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13802 | }; |
| 13803 | MockRead ssl_reads[] = { |
| 13804 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13805 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13806 | MockRead("hello world"), |
| 13807 | MockRead(SYNCHRONOUS, OK), |
| 13808 | }; |
| 13809 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13810 | ssl_writes, arraysize(ssl_writes)); |
| 13811 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13812 | |
| 13813 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13814 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13815 | |
| 13816 | // Set up HTTP request. |
| 13817 | |
| 13818 | HttpRequestInfo http_request; |
| 13819 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13820 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13821 | |
| 13822 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13823 | MockWrite( |
| 13824 | "GET / HTTP/1.1\r\n" |
| 13825 | "Host: www.example.org\r\n" |
| 13826 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13827 | }; |
| 13828 | MockRead http_reads[] = { |
| 13829 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13830 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13831 | MockRead("falafel"), |
| 13832 | MockRead(SYNCHRONOUS, OK), |
| 13833 | }; |
| 13834 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13835 | http_writes, arraysize(http_writes)); |
| 13836 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13837 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13838 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13839 | |
| 13840 | // Start the SSL request. |
| 13841 | TestCompletionCallback ssl_callback; |
| 13842 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13843 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13844 | ASSERT_EQ(ERR_IO_PENDING, |
| 13845 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13846 | BoundNetLog())); |
| 13847 | |
| 13848 | // Start the HTTP request. Pool should stall. |
| 13849 | TestCompletionCallback http_callback; |
| 13850 | scoped_ptr<HttpTransaction> http_trans( |
| 13851 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13852 | ASSERT_EQ(ERR_IO_PENDING, |
| 13853 | http_trans->Start(&http_request, http_callback.callback(), |
| 13854 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13855 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13856 | |
| 13857 | // Wait for response from SSL request. |
| 13858 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13859 | std::string response_data; |
| 13860 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13861 | EXPECT_EQ("hello world", response_data); |
| 13862 | |
| 13863 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13864 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13865 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13866 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13867 | |
| 13868 | // The HTTP request can now complete. |
| 13869 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13870 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13871 | EXPECT_EQ("falafel", response_data); |
| 13872 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13873 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13874 | } |
| 13875 | |
| 13876 | // Tests that when a SSL connection is established but there's no corresponding |
| 13877 | // request that needs it, the new socket is closed if the transport socket pool |
| 13878 | // is stalled on the global socket limit. |
| 13879 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13880 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13881 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13882 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13883 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13884 | |
| 13885 | // Set up an ssl request. |
| 13886 | |
| 13887 | HttpRequestInfo ssl_request; |
| 13888 | ssl_request.method = "GET"; |
| 13889 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13890 | |
| 13891 | // No data will be sent on the SSL socket. |
| 13892 | StaticSocketDataProvider ssl_data; |
| 13893 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13894 | |
| 13895 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13897 | |
| 13898 | // Set up HTTP request. |
| 13899 | |
| 13900 | HttpRequestInfo http_request; |
| 13901 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13902 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13903 | |
| 13904 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13905 | MockWrite( |
| 13906 | "GET / HTTP/1.1\r\n" |
| 13907 | "Host: www.example.org\r\n" |
| 13908 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13909 | }; |
| 13910 | MockRead http_reads[] = { |
| 13911 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13912 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13913 | MockRead("falafel"), |
| 13914 | MockRead(SYNCHRONOUS, OK), |
| 13915 | }; |
| 13916 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13917 | http_writes, arraysize(http_writes)); |
| 13918 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13919 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13920 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13921 | |
| 13922 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13923 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13924 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13925 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13926 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 13927 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 13928 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13929 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13930 | |
| 13931 | // Start the HTTP request. Pool should stall. |
| 13932 | TestCompletionCallback http_callback; |
| 13933 | scoped_ptr<HttpTransaction> http_trans( |
| 13934 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13935 | ASSERT_EQ(ERR_IO_PENDING, |
| 13936 | http_trans->Start(&http_request, http_callback.callback(), |
| 13937 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13938 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13939 | |
| 13940 | // The SSL connection will automatically be closed once the connection is |
| 13941 | // established, to let the HTTP request start. |
| 13942 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13943 | std::string response_data; |
| 13944 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13945 | EXPECT_EQ("falafel", response_data); |
| 13946 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13947 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13948 | } |
| 13949 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13950 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13951 | ScopedVector<UploadElementReader> element_readers; |
| 13952 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13953 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13954 | |
| 13955 | HttpRequestInfo request; |
| 13956 | request.method = "POST"; |
| 13957 | request.url = GURL("http://www.foo.com/"); |
| 13958 | request.upload_data_stream = &upload_data_stream; |
| 13959 | request.load_flags = 0; |
| 13960 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 13961 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13962 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13963 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13964 | // Send headers successfully, but get an error while sending the body. |
| 13965 | MockWrite data_writes[] = { |
| 13966 | MockWrite("POST / HTTP/1.1\r\n" |
| 13967 | "Host: www.foo.com\r\n" |
| 13968 | "Connection: keep-alive\r\n" |
| 13969 | "Content-Length: 3\r\n\r\n"), |
| 13970 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13971 | }; |
| 13972 | |
| 13973 | MockRead data_reads[] = { |
| 13974 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13975 | MockRead("hello world"), |
| 13976 | MockRead(SYNCHRONOUS, OK), |
| 13977 | }; |
| 13978 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13979 | arraysize(data_writes)); |
| 13980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13981 | |
| 13982 | TestCompletionCallback callback; |
| 13983 | |
| 13984 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13986 | |
| 13987 | rv = callback.WaitForResult(); |
| 13988 | EXPECT_EQ(OK, rv); |
| 13989 | |
| 13990 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13991 | ASSERT_TRUE(response != NULL); |
| 13992 | |
| 13993 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13994 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13995 | |
| 13996 | std::string response_data; |
| 13997 | rv = ReadTransaction(trans.get(), &response_data); |
| 13998 | EXPECT_EQ(OK, rv); |
| 13999 | EXPECT_EQ("hello world", response_data); |
| 14000 | } |
| 14001 | |
| 14002 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14003 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14004 | TEST_P(HttpNetworkTransactionTest, |
| 14005 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14006 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14007 | MockWrite data_writes[] = { |
| 14008 | MockWrite("GET / HTTP/1.1\r\n" |
| 14009 | "Host: www.foo.com\r\n" |
| 14010 | "Connection: keep-alive\r\n\r\n"), |
| 14011 | MockWrite("POST / HTTP/1.1\r\n" |
| 14012 | "Host: www.foo.com\r\n" |
| 14013 | "Connection: keep-alive\r\n" |
| 14014 | "Content-Length: 3\r\n\r\n"), |
| 14015 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14016 | }; |
| 14017 | |
| 14018 | MockRead data_reads[] = { |
| 14019 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14020 | "Content-Length: 14\r\n\r\n"), |
| 14021 | MockRead("first response"), |
| 14022 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14023 | "Content-Length: 15\r\n\r\n"), |
| 14024 | MockRead("second response"), |
| 14025 | MockRead(SYNCHRONOUS, OK), |
| 14026 | }; |
| 14027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14028 | arraysize(data_writes)); |
| 14029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14030 | |
| 14031 | TestCompletionCallback callback; |
| 14032 | HttpRequestInfo request1; |
| 14033 | request1.method = "GET"; |
| 14034 | request1.url = GURL("http://www.foo.com/"); |
| 14035 | request1.load_flags = 0; |
| 14036 | |
| 14037 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14039 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14041 | |
| 14042 | rv = callback.WaitForResult(); |
| 14043 | EXPECT_EQ(OK, rv); |
| 14044 | |
| 14045 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14046 | ASSERT_TRUE(response1 != NULL); |
| 14047 | |
| 14048 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14049 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14050 | |
| 14051 | std::string response_data1; |
| 14052 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14053 | EXPECT_EQ(OK, rv); |
| 14054 | EXPECT_EQ("first response", response_data1); |
| 14055 | // Delete the transaction to release the socket back into the socket pool. |
| 14056 | trans1.reset(); |
| 14057 | |
| 14058 | ScopedVector<UploadElementReader> element_readers; |
| 14059 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14060 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14061 | |
| 14062 | HttpRequestInfo request2; |
| 14063 | request2.method = "POST"; |
| 14064 | request2.url = GURL("http://www.foo.com/"); |
| 14065 | request2.upload_data_stream = &upload_data_stream; |
| 14066 | request2.load_flags = 0; |
| 14067 | |
| 14068 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14069 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14070 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14072 | |
| 14073 | rv = callback.WaitForResult(); |
| 14074 | EXPECT_EQ(OK, rv); |
| 14075 | |
| 14076 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14077 | ASSERT_TRUE(response2 != NULL); |
| 14078 | |
| 14079 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14080 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14081 | |
| 14082 | std::string response_data2; |
| 14083 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14084 | EXPECT_EQ(OK, rv); |
| 14085 | EXPECT_EQ("second response", response_data2); |
| 14086 | } |
| 14087 | |
| 14088 | TEST_P(HttpNetworkTransactionTest, |
| 14089 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14090 | ScopedVector<UploadElementReader> element_readers; |
| 14091 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14092 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14093 | |
| 14094 | HttpRequestInfo request; |
| 14095 | request.method = "POST"; |
| 14096 | request.url = GURL("http://www.foo.com/"); |
| 14097 | request.upload_data_stream = &upload_data_stream; |
| 14098 | request.load_flags = 0; |
| 14099 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14100 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14101 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14102 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14103 | // Send headers successfully, but get an error while sending the body. |
| 14104 | MockWrite data_writes[] = { |
| 14105 | MockWrite("POST / HTTP/1.1\r\n" |
| 14106 | "Host: www.foo.com\r\n" |
| 14107 | "Connection: keep-alive\r\n" |
| 14108 | "Content-Length: 3\r\n\r\n" |
| 14109 | "fo"), |
| 14110 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14111 | }; |
| 14112 | |
| 14113 | MockRead data_reads[] = { |
| 14114 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14115 | MockRead("hello world"), |
| 14116 | MockRead(SYNCHRONOUS, OK), |
| 14117 | }; |
| 14118 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14119 | arraysize(data_writes)); |
| 14120 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14121 | |
| 14122 | TestCompletionCallback callback; |
| 14123 | |
| 14124 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14125 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14126 | |
| 14127 | rv = callback.WaitForResult(); |
| 14128 | EXPECT_EQ(OK, rv); |
| 14129 | |
| 14130 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14131 | ASSERT_TRUE(response != NULL); |
| 14132 | |
| 14133 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14134 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14135 | |
| 14136 | std::string response_data; |
| 14137 | rv = ReadTransaction(trans.get(), &response_data); |
| 14138 | EXPECT_EQ(OK, rv); |
| 14139 | EXPECT_EQ("hello world", response_data); |
| 14140 | } |
| 14141 | |
| 14142 | // This tests the more common case than the previous test, where headers and |
| 14143 | // body are not merged into a single request. |
| 14144 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14145 | ScopedVector<UploadElementReader> element_readers; |
| 14146 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14147 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14148 | |
| 14149 | HttpRequestInfo request; |
| 14150 | request.method = "POST"; |
| 14151 | request.url = GURL("http://www.foo.com/"); |
| 14152 | request.upload_data_stream = &upload_data_stream; |
| 14153 | request.load_flags = 0; |
| 14154 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14155 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14156 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14158 | // Send headers successfully, but get an error while sending the body. |
| 14159 | MockWrite data_writes[] = { |
| 14160 | MockWrite("POST / HTTP/1.1\r\n" |
| 14161 | "Host: www.foo.com\r\n" |
| 14162 | "Connection: keep-alive\r\n" |
| 14163 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14164 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14165 | }; |
| 14166 | |
| 14167 | MockRead data_reads[] = { |
| 14168 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14169 | MockRead("hello world"), |
| 14170 | MockRead(SYNCHRONOUS, OK), |
| 14171 | }; |
| 14172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14173 | arraysize(data_writes)); |
| 14174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14175 | |
| 14176 | TestCompletionCallback callback; |
| 14177 | |
| 14178 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14180 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14181 | // they can't be merged with the body in a single send. Not currently |
| 14182 | // necessary since a chunked body is never merged with headers, but this makes |
| 14183 | // the test more future proof. |
| 14184 | base::RunLoop().RunUntilIdle(); |
| 14185 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14186 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14187 | |
| 14188 | rv = callback.WaitForResult(); |
| 14189 | EXPECT_EQ(OK, rv); |
| 14190 | |
| 14191 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14192 | ASSERT_TRUE(response != NULL); |
| 14193 | |
| 14194 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14195 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14196 | |
| 14197 | std::string response_data; |
| 14198 | rv = ReadTransaction(trans.get(), &response_data); |
| 14199 | EXPECT_EQ(OK, rv); |
| 14200 | EXPECT_EQ("hello world", response_data); |
| 14201 | } |
| 14202 | |
| 14203 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 14204 | ScopedVector<UploadElementReader> element_readers; |
| 14205 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14206 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14207 | |
| 14208 | HttpRequestInfo request; |
| 14209 | request.method = "POST"; |
| 14210 | request.url = GURL("http://www.foo.com/"); |
| 14211 | request.upload_data_stream = &upload_data_stream; |
| 14212 | request.load_flags = 0; |
| 14213 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14214 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14215 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14216 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14217 | |
| 14218 | MockWrite data_writes[] = { |
| 14219 | MockWrite("POST / HTTP/1.1\r\n" |
| 14220 | "Host: www.foo.com\r\n" |
| 14221 | "Connection: keep-alive\r\n" |
| 14222 | "Content-Length: 3\r\n\r\n"), |
| 14223 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14224 | }; |
| 14225 | |
| 14226 | MockRead data_reads[] = { |
| 14227 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14228 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14229 | MockRead("hello world"), |
| 14230 | MockRead(SYNCHRONOUS, OK), |
| 14231 | }; |
| 14232 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14233 | arraysize(data_writes)); |
| 14234 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14235 | |
| 14236 | TestCompletionCallback callback; |
| 14237 | |
| 14238 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14239 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14240 | |
| 14241 | rv = callback.WaitForResult(); |
| 14242 | EXPECT_EQ(OK, rv); |
| 14243 | |
| 14244 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14245 | ASSERT_TRUE(response != NULL); |
| 14246 | |
| 14247 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14248 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14249 | |
| 14250 | std::string response_data; |
| 14251 | rv = ReadTransaction(trans.get(), &response_data); |
| 14252 | EXPECT_EQ(OK, rv); |
| 14253 | EXPECT_EQ("hello world", response_data); |
| 14254 | } |
| 14255 | |
| 14256 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14257 | ScopedVector<UploadElementReader> element_readers; |
| 14258 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14259 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14260 | |
| 14261 | HttpRequestInfo request; |
| 14262 | request.method = "POST"; |
| 14263 | request.url = GURL("http://www.foo.com/"); |
| 14264 | request.upload_data_stream = &upload_data_stream; |
| 14265 | request.load_flags = 0; |
| 14266 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14267 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14268 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14270 | // Send headers successfully, but get an error while sending the body. |
| 14271 | MockWrite data_writes[] = { |
| 14272 | MockWrite("POST / HTTP/1.1\r\n" |
| 14273 | "Host: www.foo.com\r\n" |
| 14274 | "Connection: keep-alive\r\n" |
| 14275 | "Content-Length: 3\r\n\r\n"), |
| 14276 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14277 | }; |
| 14278 | |
| 14279 | MockRead data_reads[] = { |
| 14280 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14281 | MockRead("hello world"), |
| 14282 | MockRead(SYNCHRONOUS, OK), |
| 14283 | }; |
| 14284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14285 | arraysize(data_writes)); |
| 14286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14287 | |
| 14288 | TestCompletionCallback callback; |
| 14289 | |
| 14290 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14292 | |
| 14293 | rv = callback.WaitForResult(); |
| 14294 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14295 | } |
| 14296 | |
| 14297 | TEST_P(HttpNetworkTransactionTest, |
| 14298 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14299 | ScopedVector<UploadElementReader> element_readers; |
| 14300 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14301 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14302 | |
| 14303 | HttpRequestInfo request; |
| 14304 | request.method = "POST"; |
| 14305 | request.url = GURL("http://www.foo.com/"); |
| 14306 | request.upload_data_stream = &upload_data_stream; |
| 14307 | request.load_flags = 0; |
| 14308 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14310 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14312 | // Send headers successfully, but get an error while sending the body. |
| 14313 | MockWrite data_writes[] = { |
| 14314 | MockWrite("POST / HTTP/1.1\r\n" |
| 14315 | "Host: www.foo.com\r\n" |
| 14316 | "Connection: keep-alive\r\n" |
| 14317 | "Content-Length: 3\r\n\r\n"), |
| 14318 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14319 | }; |
| 14320 | |
| 14321 | MockRead data_reads[] = { |
| 14322 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14323 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14324 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14325 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14326 | MockRead(SYNCHRONOUS, OK), |
| 14327 | }; |
| 14328 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14329 | arraysize(data_writes)); |
| 14330 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14331 | |
| 14332 | TestCompletionCallback callback; |
| 14333 | |
| 14334 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14335 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14336 | |
| 14337 | rv = callback.WaitForResult(); |
| 14338 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14339 | } |
| 14340 | |
| 14341 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14342 | ScopedVector<UploadElementReader> element_readers; |
| 14343 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14344 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14345 | |
| 14346 | HttpRequestInfo request; |
| 14347 | request.method = "POST"; |
| 14348 | request.url = GURL("http://www.foo.com/"); |
| 14349 | request.upload_data_stream = &upload_data_stream; |
| 14350 | request.load_flags = 0; |
| 14351 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14352 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14353 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14355 | // Send headers successfully, but get an error while sending the body. |
| 14356 | MockWrite data_writes[] = { |
| 14357 | MockWrite("POST / HTTP/1.1\r\n" |
| 14358 | "Host: www.foo.com\r\n" |
| 14359 | "Connection: keep-alive\r\n" |
| 14360 | "Content-Length: 3\r\n\r\n"), |
| 14361 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14362 | }; |
| 14363 | |
| 14364 | MockRead data_reads[] = { |
| 14365 | MockRead("HTTP 0.9 rocks!"), |
| 14366 | MockRead(SYNCHRONOUS, OK), |
| 14367 | }; |
| 14368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14369 | arraysize(data_writes)); |
| 14370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14371 | |
| 14372 | TestCompletionCallback callback; |
| 14373 | |
| 14374 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14375 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14376 | |
| 14377 | rv = callback.WaitForResult(); |
| 14378 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14379 | } |
| 14380 | |
| 14381 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14382 | ScopedVector<UploadElementReader> element_readers; |
| 14383 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14384 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14385 | |
| 14386 | HttpRequestInfo request; |
| 14387 | request.method = "POST"; |
| 14388 | request.url = GURL("http://www.foo.com/"); |
| 14389 | request.upload_data_stream = &upload_data_stream; |
| 14390 | request.load_flags = 0; |
| 14391 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14392 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14393 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14394 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14395 | // Send headers successfully, but get an error while sending the body. |
| 14396 | MockWrite data_writes[] = { |
| 14397 | MockWrite("POST / HTTP/1.1\r\n" |
| 14398 | "Host: www.foo.com\r\n" |
| 14399 | "Connection: keep-alive\r\n" |
| 14400 | "Content-Length: 3\r\n\r\n"), |
| 14401 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14402 | }; |
| 14403 | |
| 14404 | MockRead data_reads[] = { |
| 14405 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14406 | MockRead(SYNCHRONOUS, OK), |
| 14407 | }; |
| 14408 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14409 | arraysize(data_writes)); |
| 14410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14411 | |
| 14412 | TestCompletionCallback callback; |
| 14413 | |
| 14414 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14416 | |
| 14417 | rv = callback.WaitForResult(); |
| 14418 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14419 | } |
| 14420 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14421 | // Verify that proxy headers are not sent to the destination server when |
| 14422 | // establishing a tunnel for a secure WebSocket connection. |
| 14423 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14424 | HttpRequestInfo request; |
| 14425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14426 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14427 | AddWebSocketHeaders(&request.extra_headers); |
| 14428 | |
| 14429 | // Configure against proxy server "myproxy:70". |
| 14430 | session_deps_.proxy_service.reset( |
| 14431 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14432 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14433 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14434 | |
| 14435 | // Since a proxy is configured, try to establish a tunnel. |
| 14436 | MockWrite data_writes[] = { |
| 14437 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14438 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14439 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14440 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14441 | |
| 14442 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14443 | // be issuing -- the final header line contains the credentials. |
| 14444 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14445 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14446 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14447 | "Proxy-Connection: keep-alive\r\n" |
| 14448 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14449 | |
| 14450 | MockWrite( |
| 14451 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14452 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14453 | "Connection: Upgrade\r\n" |
| 14454 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14455 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14456 | "Sec-WebSocket-Version: 13\r\n" |
| 14457 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14458 | }; |
| 14459 | |
| 14460 | // The proxy responds to the connect with a 407, using a persistent |
| 14461 | // connection. |
| 14462 | MockRead data_reads[] = { |
| 14463 | // No credentials. |
| 14464 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14465 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 14466 | MockRead("Content-Length: 0\r\n"), |
| 14467 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14468 | |
| 14469 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14470 | |
| 14471 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14472 | MockRead("Upgrade: websocket\r\n"), |
| 14473 | MockRead("Connection: Upgrade\r\n"), |
| 14474 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14475 | }; |
| 14476 | |
| 14477 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14478 | arraysize(data_writes)); |
| 14479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14480 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14482 | |
| 14483 | scoped_ptr<HttpTransaction> trans( |
| 14484 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14485 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14486 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14487 | &websocket_stream_create_helper); |
| 14488 | |
| 14489 | { |
| 14490 | TestCompletionCallback callback; |
| 14491 | |
| 14492 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14494 | |
| 14495 | rv = callback.WaitForResult(); |
| 14496 | EXPECT_EQ(OK, rv); |
| 14497 | } |
| 14498 | |
| 14499 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14500 | ASSERT_TRUE(response); |
| 14501 | ASSERT_TRUE(response->headers.get()); |
| 14502 | EXPECT_EQ(407, response->headers->response_code()); |
| 14503 | |
| 14504 | { |
| 14505 | TestCompletionCallback callback; |
| 14506 | |
| 14507 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14508 | callback.callback()); |
| 14509 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14510 | |
| 14511 | rv = callback.WaitForResult(); |
| 14512 | EXPECT_EQ(OK, rv); |
| 14513 | } |
| 14514 | |
| 14515 | response = trans->GetResponseInfo(); |
| 14516 | ASSERT_TRUE(response); |
| 14517 | ASSERT_TRUE(response->headers.get()); |
| 14518 | |
| 14519 | EXPECT_EQ(101, response->headers->response_code()); |
| 14520 | |
| 14521 | trans.reset(); |
| 14522 | session->CloseAllConnections(); |
| 14523 | } |
| 14524 | |
| 14525 | // Verify that proxy headers are not sent to the destination server when |
| 14526 | // establishing a tunnel for an insecure WebSocket connection. |
| 14527 | // This requires the authentication info to be injected into the auth cache |
| 14528 | // due to crbug.com/395064 |
| 14529 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14530 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14531 | HttpRequestInfo request; |
| 14532 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14533 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14534 | AddWebSocketHeaders(&request.extra_headers); |
| 14535 | |
| 14536 | // Configure against proxy server "myproxy:70". |
| 14537 | session_deps_.proxy_service.reset( |
| 14538 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14539 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14540 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14541 | |
| 14542 | MockWrite data_writes[] = { |
| 14543 | // Try to establish a tunnel for the WebSocket connection, with |
| 14544 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14545 | // they cannot and will not use the same TCP/IP connection as the |
| 14546 | // preflight HTTP request. |
| 14547 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14548 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14549 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14550 | "Proxy-Connection: keep-alive\r\n" |
| 14551 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14552 | |
| 14553 | MockWrite( |
| 14554 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14555 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14556 | "Connection: Upgrade\r\n" |
| 14557 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14558 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14559 | "Sec-WebSocket-Version: 13\r\n" |
| 14560 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14561 | }; |
| 14562 | |
| 14563 | MockRead data_reads[] = { |
| 14564 | // HTTP CONNECT with credentials. |
| 14565 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14566 | |
| 14567 | // WebSocket connection established inside tunnel. |
| 14568 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14569 | MockRead("Upgrade: websocket\r\n"), |
| 14570 | MockRead("Connection: Upgrade\r\n"), |
| 14571 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14572 | }; |
| 14573 | |
| 14574 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14575 | arraysize(data_writes)); |
| 14576 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14577 | |
| 14578 | session->http_auth_cache()->Add( |
| 14579 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14580 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14581 | |
| 14582 | scoped_ptr<HttpTransaction> trans( |
| 14583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14584 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14585 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14586 | &websocket_stream_create_helper); |
| 14587 | |
| 14588 | TestCompletionCallback callback; |
| 14589 | |
| 14590 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14592 | |
| 14593 | rv = callback.WaitForResult(); |
| 14594 | EXPECT_EQ(OK, rv); |
| 14595 | |
| 14596 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14597 | ASSERT_TRUE(response); |
| 14598 | ASSERT_TRUE(response->headers.get()); |
| 14599 | |
| 14600 | EXPECT_EQ(101, response->headers->response_code()); |
| 14601 | |
| 14602 | trans.reset(); |
| 14603 | session->CloseAllConnections(); |
| 14604 | } |
| 14605 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14606 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
| 14607 | ScopedVector<UploadElementReader> element_readers; |
| 14608 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14609 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14610 | |
| 14611 | HttpRequestInfo request; |
| 14612 | request.method = "POST"; |
| 14613 | request.url = GURL("http://www.foo.com/"); |
| 14614 | request.upload_data_stream = &upload_data_stream; |
| 14615 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14616 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14617 | scoped_ptr<HttpTransaction> trans( |
| 14618 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14619 | MockWrite data_writes[] = { |
| 14620 | MockWrite("POST / HTTP/1.1\r\n" |
| 14621 | "Host: www.foo.com\r\n" |
| 14622 | "Connection: keep-alive\r\n" |
| 14623 | "Content-Length: 3\r\n\r\n"), |
| 14624 | MockWrite("foo"), |
| 14625 | }; |
| 14626 | |
| 14627 | MockRead data_reads[] = { |
| 14628 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14629 | MockRead(SYNCHRONOUS, OK), |
| 14630 | }; |
| 14631 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14632 | arraysize(data_writes)); |
| 14633 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14634 | |
| 14635 | TestCompletionCallback callback; |
| 14636 | |
| 14637 | EXPECT_EQ(ERR_IO_PENDING, |
| 14638 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14639 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14640 | |
| 14641 | std::string response_data; |
| 14642 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14643 | |
| 14644 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14645 | trans->GetTotalSentBytes()); |
| 14646 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14647 | trans->GetTotalReceivedBytes()); |
| 14648 | } |
| 14649 | |
| 14650 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
| 14651 | ScopedVector<UploadElementReader> element_readers; |
| 14652 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14653 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14654 | |
| 14655 | HttpRequestInfo request; |
| 14656 | request.method = "POST"; |
| 14657 | request.url = GURL("http://www.foo.com/"); |
| 14658 | request.upload_data_stream = &upload_data_stream; |
| 14659 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14660 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14661 | scoped_ptr<HttpTransaction> trans( |
| 14662 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14663 | MockWrite data_writes[] = { |
| 14664 | MockWrite("POST / HTTP/1.1\r\n" |
| 14665 | "Host: www.foo.com\r\n" |
| 14666 | "Connection: keep-alive\r\n" |
| 14667 | "Content-Length: 3\r\n\r\n"), |
| 14668 | MockWrite("foo"), |
| 14669 | }; |
| 14670 | |
| 14671 | MockRead data_reads[] = { |
| 14672 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 14673 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14674 | MockRead(SYNCHRONOUS, OK), |
| 14675 | }; |
| 14676 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14677 | arraysize(data_writes)); |
| 14678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14679 | |
| 14680 | TestCompletionCallback callback; |
| 14681 | |
| 14682 | EXPECT_EQ(ERR_IO_PENDING, |
| 14683 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14684 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14685 | |
| 14686 | std::string response_data; |
| 14687 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14688 | |
| 14689 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14690 | trans->GetTotalSentBytes()); |
| 14691 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14692 | trans->GetTotalReceivedBytes()); |
| 14693 | } |
| 14694 | |
| 14695 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
| 14696 | ScopedVector<UploadElementReader> element_readers; |
| 14697 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14698 | ChunkedUploadDataStream upload_data_stream(0); |
| 14699 | |
| 14700 | HttpRequestInfo request; |
| 14701 | request.method = "POST"; |
| 14702 | request.url = GURL("http://www.foo.com/"); |
| 14703 | request.upload_data_stream = &upload_data_stream; |
| 14704 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame^] | 14705 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14706 | scoped_ptr<HttpTransaction> trans( |
| 14707 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14708 | // Send headers successfully, but get an error while sending the body. |
| 14709 | MockWrite data_writes[] = { |
| 14710 | MockWrite("POST / HTTP/1.1\r\n" |
| 14711 | "Host: www.foo.com\r\n" |
| 14712 | "Connection: keep-alive\r\n" |
| 14713 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14714 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 14715 | }; |
| 14716 | |
| 14717 | MockRead data_reads[] = { |
| 14718 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14719 | MockRead(SYNCHRONOUS, OK), |
| 14720 | }; |
| 14721 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14722 | arraysize(data_writes)); |
| 14723 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14724 | |
| 14725 | TestCompletionCallback callback; |
| 14726 | |
| 14727 | EXPECT_EQ(ERR_IO_PENDING, |
| 14728 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14729 | |
| 14730 | base::RunLoop().RunUntilIdle(); |
| 14731 | upload_data_stream.AppendData("f", 1, false); |
| 14732 | |
| 14733 | base::RunLoop().RunUntilIdle(); |
| 14734 | upload_data_stream.AppendData("oo", 2, true); |
| 14735 | |
| 14736 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14737 | |
| 14738 | std::string response_data; |
| 14739 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14740 | |
| 14741 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14742 | trans->GetTotalSentBytes()); |
| 14743 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14744 | trans->GetTotalReceivedBytes()); |
| 14745 | } |
| 14746 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14747 | } // namespace net |