[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
| 9 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 11 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 20 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 21 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 23 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 24 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 25 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 26 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 27 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 28 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 30 | #include "net/base/load_timing_info.h" |
| 31 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 32 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 33 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 34 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 35 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 36 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 37 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 38 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 39 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 40 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 41 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 42 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 45 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 46 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 47 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 48 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 49 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 50 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 51 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 52 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 54 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 55 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 56 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 57 | #include "net/log/test_net_log_entry.h" |
| 58 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 59 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 60 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 61 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 62 | #include "net/proxy/proxy_resolver.h" |
| 63 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 64 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 65 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 66 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 67 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 68 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 69 | #include "net/socket/socket_test_util.h" |
| 70 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 71 | #include "net/spdy/spdy_framer.h" |
| 72 | #include "net/spdy/spdy_session.h" |
| 73 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 74 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 75 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 76 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_config_service_defaults.h" |
| 78 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 79 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 80 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 81 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 82 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 83 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 84 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 85 | using base::ASCIIToUTF16; |
| 86 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 87 | //----------------------------------------------------------------------------- |
| 88 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 89 | namespace net { |
| 90 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 91 | namespace { |
| 92 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 93 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 94 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 95 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 96 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 97 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 98 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 99 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 100 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 101 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 102 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 103 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 104 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 105 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 106 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 107 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 108 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 109 | } |
| 110 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 111 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 112 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 113 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 114 | } |
| 115 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 116 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 117 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 118 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 121 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 122 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 123 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 124 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 125 | if (!params) |
| 126 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 127 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 128 | if (!params->GetList("headers", &header_list)) |
| 129 | return false; |
| 130 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 131 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 132 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 133 | return true; |
| 134 | } |
| 135 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 136 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 137 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 138 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 139 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 141 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 142 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 143 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 144 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 145 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 146 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 147 | |
| 148 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 150 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 152 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 154 | } |
| 155 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 157 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 158 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 159 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 160 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | |
| 163 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 164 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 165 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 167 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 168 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 169 | load_timing_info.send_start); |
| 170 | |
| 171 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 173 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 175 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
| 187 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 188 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 189 | load_timing_info.proxy_resolve_end); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 191 | load_timing_info.send_start); |
| 192 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 194 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 196 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 201 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | int connect_timing_flags) { |
| 204 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 205 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | |
| 207 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 208 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 209 | load_timing_info.proxy_resolve_end); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 211 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 212 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 213 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 215 | load_timing_info.send_start); |
| 216 | |
| 217 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 219 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 221 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 223 | } |
| 224 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 226 | headers->SetHeader("Connection", "Upgrade"); |
| 227 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 228 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 229 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 230 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 231 | } |
| 232 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 233 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 234 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 237 | } // namespace |
| 238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 239 | class HttpNetworkTransactionTest |
| 240 | : public PlatformTest, |
| 241 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 242 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 243 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | // Important to restore the per-pool limit first, since the pool limit must |
| 245 | // always be greater than group limit, and the tests reduce both limits. |
| 246 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 247 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 248 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 250 | } |
| 251 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 252 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 253 | HttpNetworkTransactionTest() |
| 254 | : spdy_util_(GetParam()), |
| 255 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 256 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 257 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 258 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 260 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 261 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 262 | struct SimpleGetHelperResult { |
| 263 | int rv; |
| 264 | std::string status_line; |
| 265 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 266 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 267 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 268 | ConnectionAttempts connection_attempts; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 269 | }; |
| 270 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 271 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 272 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 273 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 274 | } |
| 275 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 276 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 277 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 278 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 279 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 280 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 281 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 282 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 283 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 284 | } |
| 285 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 286 | const char* GetAlternateProtocolFromParam() { |
| 287 | return |
| 288 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 289 | } |
| 290 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 291 | std::string GetAlternativeServiceHttpHeader() { |
| 292 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 293 | "=\"www.example.com:443\"\r\n"; |
| 294 | } |
| 295 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 296 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 297 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 298 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 301 | // Either |write_failure| specifies a write failure or |read_failure| |
| 302 | // specifies a read failure when using a reused socket. In either case, the |
| 303 | // failure should cause the network transaction to resend the request, and the |
| 304 | // other argument should be NULL. |
| 305 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 306 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 307 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 308 | // Either |write_failure| specifies a write failure or |read_failure| |
| 309 | // specifies a read failure when using a reused socket. In either case, the |
| 310 | // failure should cause the network transaction to resend the request, and the |
| 311 | // other argument should be NULL. |
| 312 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 313 | const MockRead* read_failure, |
| 314 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 315 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 316 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 317 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 318 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 319 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 320 | HttpRequestInfo request; |
| 321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 322 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 324 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 325 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 326 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 327 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 328 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 330 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 331 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 332 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 333 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 335 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 336 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 337 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 338 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 340 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 341 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 342 | |
| 343 | // Even in the failure cases that use this function, connections are always |
| 344 | // successfully established before the error. |
| 345 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 346 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 347 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 348 | if (out.rv != OK) |
| 349 | return out; |
| 350 | |
| 351 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 352 | // Can't use ASSERT_* inside helper functions like this, so |
| 353 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 354 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 355 | out.rv = ERR_UNEXPECTED; |
| 356 | return out; |
| 357 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | out.status_line = response->headers->GetStatusLine(); |
| 359 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 360 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 361 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 362 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 363 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 364 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 365 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 366 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 367 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 368 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 369 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 370 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 371 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 372 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 373 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 374 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 375 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 376 | std::string line; |
| 377 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 378 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 379 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 380 | HttpRequestHeaders request_headers; |
| 381 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 382 | std::string value; |
| 383 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 384 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 385 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 386 | EXPECT_EQ("keep-alive", value); |
| 387 | |
| 388 | std::string response_headers; |
| 389 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 390 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 391 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 392 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 393 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 394 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 395 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 396 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 397 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 398 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 399 | size_t reads_count) { |
| 400 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 401 | StaticSocketDataProvider* data[] = { &reads }; |
| 402 | return SimpleGetHelperForData(data, 1); |
| 403 | } |
| 404 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 405 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 406 | int64 size = 0; |
| 407 | for (size_t i = 0; i < reads_count; ++i) |
| 408 | size += data_reads[i].data_len; |
| 409 | return size; |
| 410 | } |
| 411 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 412 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 413 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 414 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 415 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 416 | |
| 417 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 418 | |
| 419 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 420 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 421 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 422 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 423 | |
| 424 | // Original socket limits. Some tests set these. Safest to always restore |
| 425 | // them once each test has been run. |
| 426 | int old_max_group_sockets_; |
| 427 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 428 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 429 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 430 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 431 | HttpNetworkTransactionTest, |
| 432 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 433 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 434 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 435 | namespace { |
| 436 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 437 | class BeforeNetworkStartHandler { |
| 438 | public: |
| 439 | explicit BeforeNetworkStartHandler(bool defer) |
| 440 | : defer_on_before_network_start_(defer), |
| 441 | observed_before_network_start_(false) {} |
| 442 | |
| 443 | void OnBeforeNetworkStart(bool* defer) { |
| 444 | *defer = defer_on_before_network_start_; |
| 445 | observed_before_network_start_ = true; |
| 446 | } |
| 447 | |
| 448 | bool observed_before_network_start() const { |
| 449 | return observed_before_network_start_; |
| 450 | } |
| 451 | |
| 452 | private: |
| 453 | const bool defer_on_before_network_start_; |
| 454 | bool observed_before_network_start_; |
| 455 | |
| 456 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 457 | }; |
| 458 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 459 | class BeforeProxyHeadersSentHandler { |
| 460 | public: |
| 461 | BeforeProxyHeadersSentHandler() |
| 462 | : observed_before_proxy_headers_sent_(false) {} |
| 463 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 464 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 465 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 466 | observed_before_proxy_headers_sent_ = true; |
| 467 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 468 | } |
| 469 | |
| 470 | bool observed_before_proxy_headers_sent() const { |
| 471 | return observed_before_proxy_headers_sent_; |
| 472 | } |
| 473 | |
| 474 | std::string observed_proxy_server_uri() const { |
| 475 | return observed_proxy_server_uri_; |
| 476 | } |
| 477 | |
| 478 | private: |
| 479 | bool observed_before_proxy_headers_sent_; |
| 480 | std::string observed_proxy_server_uri_; |
| 481 | |
| 482 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 483 | }; |
| 484 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 485 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 486 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 487 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 488 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 489 | const int sizeof_row = strlen(row); |
| 490 | const int num_rows = static_cast<int>( |
| 491 | ceil(static_cast<float>(size) / sizeof_row)); |
| 492 | const int sizeof_data = num_rows * sizeof_row; |
| 493 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 494 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 495 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 496 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 497 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 498 | } |
| 499 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 500 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 501 | // Alternative functions that eliminate randomness and dependency on the local |
| 502 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 503 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 504 | static const uint8 bytes[] = { |
| 505 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 506 | }; |
| 507 | static size_t current_byte = 0; |
| 508 | for (size_t i = 0; i < n; ++i) { |
| 509 | output[i] = bytes[current_byte++]; |
| 510 | current_byte %= arraysize(bytes); |
| 511 | } |
| 512 | } |
| 513 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 514 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 515 | static const uint8 bytes[] = { |
| 516 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 517 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 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 | std::string MockGetHostName() { |
| 527 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 528 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 529 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 530 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 531 | template<typename ParentPool> |
| 532 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 533 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 534 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 535 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 536 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 537 | const std::string last_group_name_received() const { |
| 538 | return last_group_name_; |
| 539 | } |
| 540 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 541 | int RequestSocket(const std::string& group_name, |
| 542 | const void* socket_params, |
| 543 | RequestPriority priority, |
| 544 | ClientSocketHandle* handle, |
| 545 | const CompletionCallback& callback, |
| 546 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 547 | last_group_name_ = group_name; |
| 548 | return ERR_IO_PENDING; |
| 549 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 550 | void CancelRequest(const std::string& group_name, |
| 551 | ClientSocketHandle* handle) override {} |
| 552 | void ReleaseSocket(const std::string& group_name, |
| 553 | scoped_ptr<StreamSocket> socket, |
| 554 | int id) override {} |
| 555 | void CloseIdleSockets() override {} |
| 556 | int IdleSocketCount() const override { return 0; } |
| 557 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 558 | return 0; |
| 559 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 560 | LoadState GetLoadState(const std::string& group_name, |
| 561 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 562 | return LOAD_STATE_IDLE; |
| 563 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 564 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 565 | return base::TimeDelta(); |
| 566 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 567 | |
| 568 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 569 | std::string last_group_name_; |
| 570 | }; |
| 571 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 572 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 573 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 574 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 575 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 576 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 577 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 578 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 579 | CaptureGroupNameSSLSocketPool; |
| 580 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 581 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 582 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 583 | HostResolver* host_resolver, |
| 584 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 585 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 586 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 587 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 588 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 589 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 590 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 591 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 592 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 593 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 594 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 595 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 596 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 597 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 598 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 599 | : SSLClientSocketPool(0, |
| 600 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 601 | cert_verifier, |
| 602 | NULL, |
| 603 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 604 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 605 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 606 | std::string(), |
| 607 | NULL, |
| 608 | NULL, |
| 609 | NULL, |
| 610 | NULL, |
| 611 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 612 | NULL) { |
| 613 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 614 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 615 | //----------------------------------------------------------------------------- |
| 616 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 617 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 618 | // configured for common cases. |
| 619 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 620 | if (!auth_challenge) |
| 621 | return false; |
| 622 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 623 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 624 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 625 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 630 | if (!auth_challenge) |
| 631 | return false; |
| 632 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 633 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 634 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 635 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 640 | if (!auth_challenge) |
| 641 | return false; |
| 642 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 643 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 644 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 645 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 646 | return true; |
| 647 | } |
| 648 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 649 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 650 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 651 | if (!auth_challenge) |
| 652 | return false; |
| 653 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 654 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 655 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 656 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 657 | return true; |
| 658 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 659 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 660 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 661 | } // namespace |
| 662 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 663 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 664 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 665 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 667 | } |
| 668 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 669 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 670 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 671 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 672 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 673 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 674 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 675 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 676 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 677 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 678 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 679 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 680 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 681 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 682 | EXPECT_EQ(0u, out.connection_attempts.size()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 686 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 687 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 688 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 689 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 690 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 691 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 692 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 693 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 695 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 696 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 697 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 701 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 702 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 703 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 704 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 705 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 706 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 707 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 708 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 709 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 710 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 711 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 712 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 716 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 717 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 718 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 719 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 720 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 721 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 722 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 723 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 725 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 726 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 727 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | // 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] | 731 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 732 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 733 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 734 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 736 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 737 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 738 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 739 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 740 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 741 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 742 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 746 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 747 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 748 | MockRead("\n"), |
| 749 | MockRead("\n"), |
| 750 | MockRead("Q"), |
| 751 | MockRead("J"), |
| 752 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 753 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 754 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 755 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 756 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 757 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 758 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 759 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 760 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 761 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 765 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 766 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 767 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 769 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 770 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 771 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 772 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 773 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 774 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 775 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 776 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 777 | } |
| 778 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 779 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 780 | // persistent connection. The response should still terminate since a 204 |
| 781 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 782 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 783 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 784 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 785 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 786 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 788 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 789 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 790 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 791 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 792 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 793 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 794 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 795 | int64 response_size = reads_size - strlen(junk); |
| 796 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 797 | } |
| 798 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 799 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 800 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 801 | std::string final_chunk = "0\r\n\r\n"; |
| 802 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 803 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 804 | MockRead data_reads[] = { |
| 805 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 806 | MockRead("5\r\nHello\r\n"), |
| 807 | MockRead("1\r\n"), |
| 808 | MockRead(" \r\n"), |
| 809 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 810 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 812 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 813 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 814 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 815 | EXPECT_EQ(OK, out.rv); |
| 816 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 817 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 818 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 819 | int64 response_size = reads_size - extra_data.size(); |
| 820 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 821 | } |
| 822 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 823 | // Next tests deal with http://crbug.com/56344. |
| 824 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 825 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 826 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 827 | MockRead data_reads[] = { |
| 828 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 829 | MockRead("Content-Length: 10\r\n"), |
| 830 | MockRead("Content-Length: 5\r\n\r\n"), |
| 831 | }; |
| 832 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 833 | arraysize(data_reads)); |
| 834 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 835 | } |
| 836 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 837 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 838 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 839 | MockRead data_reads[] = { |
| 840 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 841 | MockRead("Content-Length: 5\r\n"), |
| 842 | MockRead("Content-Length: 5\r\n\r\n"), |
| 843 | MockRead("Hello"), |
| 844 | }; |
| 845 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 846 | arraysize(data_reads)); |
| 847 | EXPECT_EQ(OK, out.rv); |
| 848 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 849 | EXPECT_EQ("Hello", out.response_data); |
| 850 | } |
| 851 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 852 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 853 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 854 | // More than 2 dupes. |
| 855 | { |
| 856 | MockRead data_reads[] = { |
| 857 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 858 | MockRead("Content-Length: 5\r\n"), |
| 859 | MockRead("Content-Length: 5\r\n"), |
| 860 | MockRead("Content-Length: 5\r\n\r\n"), |
| 861 | MockRead("Hello"), |
| 862 | }; |
| 863 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 864 | arraysize(data_reads)); |
| 865 | EXPECT_EQ(OK, out.rv); |
| 866 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 867 | EXPECT_EQ("Hello", out.response_data); |
| 868 | } |
| 869 | // HTTP/1.0 |
| 870 | { |
| 871 | MockRead data_reads[] = { |
| 872 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 873 | MockRead("Content-Length: 5\r\n"), |
| 874 | MockRead("Content-Length: 5\r\n"), |
| 875 | MockRead("Content-Length: 5\r\n\r\n"), |
| 876 | MockRead("Hello"), |
| 877 | }; |
| 878 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 879 | arraysize(data_reads)); |
| 880 | EXPECT_EQ(OK, out.rv); |
| 881 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 882 | EXPECT_EQ("Hello", out.response_data); |
| 883 | } |
| 884 | // 2 dupes and one mismatched. |
| 885 | { |
| 886 | MockRead data_reads[] = { |
| 887 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 888 | MockRead("Content-Length: 10\r\n"), |
| 889 | MockRead("Content-Length: 10\r\n"), |
| 890 | MockRead("Content-Length: 5\r\n\r\n"), |
| 891 | }; |
| 892 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 893 | arraysize(data_reads)); |
| 894 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 895 | } |
| 896 | } |
| 897 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 898 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 899 | MultipleContentLengthHeadersTransferEncoding) { |
| 900 | MockRead data_reads[] = { |
| 901 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 902 | MockRead("Content-Length: 666\r\n"), |
| 903 | MockRead("Content-Length: 1337\r\n"), |
| 904 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 905 | MockRead("5\r\nHello\r\n"), |
| 906 | MockRead("1\r\n"), |
| 907 | MockRead(" \r\n"), |
| 908 | MockRead("5\r\nworld\r\n"), |
| 909 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 911 | }; |
| 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
| 914 | EXPECT_EQ(OK, out.rv); |
| 915 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 916 | EXPECT_EQ("Hello world", out.response_data); |
| 917 | } |
| 918 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 919 | // Next tests deal with http://crbug.com/98895. |
| 920 | |
| 921 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 922 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 923 | MockRead data_reads[] = { |
| 924 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 925 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 926 | MockRead("Content-Length: 5\r\n\r\n"), |
| 927 | MockRead("Hello"), |
| 928 | }; |
| 929 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 930 | arraysize(data_reads)); |
| 931 | EXPECT_EQ(OK, out.rv); |
| 932 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 933 | EXPECT_EQ("Hello", out.response_data); |
| 934 | } |
| 935 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 936 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 937 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 938 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 939 | MockRead data_reads[] = { |
| 940 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 941 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 942 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 943 | MockRead("Content-Length: 5\r\n\r\n"), |
| 944 | MockRead("Hello"), |
| 945 | }; |
| 946 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 947 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 948 | EXPECT_EQ(OK, out.rv); |
| 949 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 950 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 954 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 955 | MockRead data_reads[] = { |
| 956 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 957 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 958 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 959 | MockRead("Content-Length: 5\r\n\r\n"), |
| 960 | MockRead("Hello"), |
| 961 | }; |
| 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 963 | arraysize(data_reads)); |
| 964 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 965 | } |
| 966 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 967 | // Checks that two identical Location headers result in no error. |
| 968 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 969 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 970 | MockRead data_reads[] = { |
| 971 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 972 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 973 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 974 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 975 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | }; |
| 977 | |
| 978 | HttpRequestInfo request; |
| 979 | request.method = "GET"; |
| 980 | request.url = GURL("http://redirect.com/"); |
| 981 | request.load_flags = 0; |
| 982 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 983 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 984 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 986 | |
| 987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 990 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 992 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 994 | |
| 995 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 996 | |
| 997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 998 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 999 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1000 | std::string url; |
| 1001 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1002 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1003 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1004 | } |
| 1005 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1007 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1008 | MockRead data_reads[] = { |
| 1009 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1010 | MockRead("Location: http://good.com/\r\n"), |
| 1011 | MockRead("Location: http://evil.com/\r\n"), |
| 1012 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1014 | }; |
| 1015 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1016 | arraysize(data_reads)); |
| 1017 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1018 | } |
| 1019 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1020 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1021 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1022 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1023 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1024 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1025 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1026 | request.load_flags = 0; |
| 1027 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1028 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1029 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1030 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1031 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1032 | trans->SetBeforeProxyHeadersSentCallback( |
| 1033 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1034 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1035 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1036 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1037 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1038 | "Host: www.example.org\r\n" |
| 1039 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1040 | }; |
| 1041 | MockRead data_reads1[] = { |
| 1042 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1043 | MockRead("Server: Blah\r\n"), |
| 1044 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1045 | |
| 1046 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1047 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1048 | }; |
| 1049 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1050 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1051 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1052 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1054 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1056 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1058 | |
| 1059 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1060 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1061 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1062 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1063 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1064 | |
| 1065 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1066 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1067 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1068 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1069 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1070 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1071 | |
| 1072 | std::string server_header; |
| 1073 | void* iter = NULL; |
| 1074 | bool has_server_header = response->headers->EnumerateHeader( |
| 1075 | &iter, "Server", &server_header); |
| 1076 | EXPECT_TRUE(has_server_header); |
| 1077 | EXPECT_EQ("Blah", server_header); |
| 1078 | |
| 1079 | // Reading should give EOF right away, since there is no message body |
| 1080 | // (despite non-zero content-length). |
| 1081 | std::string response_data; |
| 1082 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1083 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | EXPECT_EQ("", response_data); |
| 1085 | } |
| 1086 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1087 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1088 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1089 | |
| 1090 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1091 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1092 | MockRead("hello"), |
| 1093 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1094 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1095 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1096 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1097 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1099 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1100 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | "hello", "world" |
| 1102 | }; |
| 1103 | |
| 1104 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1105 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1107 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | request.load_flags = 0; |
| 1109 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1110 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1111 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1113 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1115 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1116 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1117 | |
| 1118 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1119 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1120 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1122 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1123 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1124 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1125 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1126 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1127 | |
| 1128 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1129 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1130 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1131 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1135 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1136 | ScopedVector<UploadElementReader> element_readers; |
| 1137 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1138 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1139 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1140 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1141 | request.method = "POST"; |
| 1142 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1143 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | request.load_flags = 0; |
| 1145 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1146 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1147 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1149 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1150 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1151 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1152 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1153 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1154 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1155 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1156 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1157 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1159 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1161 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1162 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1163 | |
| 1164 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1165 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1166 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1167 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1168 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1169 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1170 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1171 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1172 | |
| 1173 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1174 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1175 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1176 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1179 | // This test is almost the same as Ignores100 above, but the response contains |
| 1180 | // 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] | 1181 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1182 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1183 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1184 | request.method = "GET"; |
| 1185 | request.url = GURL("http://www.foo.com/"); |
| 1186 | request.load_flags = 0; |
| 1187 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1188 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1189 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1191 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1192 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1193 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1194 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1195 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1196 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1197 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1198 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1199 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1201 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1203 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1204 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1205 | |
| 1206 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1207 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1208 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1210 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1211 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1212 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1213 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1214 | |
| 1215 | std::string response_data; |
| 1216 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1217 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1218 | EXPECT_EQ("hello world", response_data); |
| 1219 | } |
| 1220 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1221 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1222 | HttpRequestInfo request; |
| 1223 | request.method = "POST"; |
| 1224 | request.url = GURL("http://www.foo.com/"); |
| 1225 | request.load_flags = 0; |
| 1226 | |
| 1227 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1228 | scoped_ptr<HttpTransaction> trans( |
| 1229 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1230 | |
| 1231 | MockRead data_reads[] = { |
| 1232 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1233 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1234 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1235 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1236 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1237 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1238 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1239 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1240 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1242 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1243 | rv = callback.WaitForResult(); |
| 1244 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1245 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1246 | std::string response_data; |
| 1247 | rv = ReadTransaction(trans.get(), &response_data); |
| 1248 | EXPECT_EQ(OK, rv); |
| 1249 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1250 | } |
| 1251 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1252 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1253 | HttpRequestInfo request; |
| 1254 | request.method = "POST"; |
| 1255 | request.url = GURL("http://www.foo.com/"); |
| 1256 | request.load_flags = 0; |
| 1257 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1258 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1259 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1261 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1262 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1263 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1264 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1265 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1266 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1268 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1270 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1272 | |
| 1273 | rv = callback.WaitForResult(); |
| 1274 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1275 | } |
| 1276 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1277 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1278 | const MockWrite* write_failure, |
| 1279 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1280 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1281 | request.method = "GET"; |
| 1282 | request.url = GURL("http://www.foo.com/"); |
| 1283 | request.load_flags = 0; |
| 1284 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1285 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.net_log = &net_log; |
| 1287 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1288 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1289 | // Written data for successfully sending both requests. |
| 1290 | MockWrite data1_writes[] = { |
| 1291 | MockWrite("GET / HTTP/1.1\r\n" |
| 1292 | "Host: www.foo.com\r\n" |
| 1293 | "Connection: keep-alive\r\n\r\n"), |
| 1294 | MockWrite("GET / HTTP/1.1\r\n" |
| 1295 | "Host: www.foo.com\r\n" |
| 1296 | "Connection: keep-alive\r\n\r\n") |
| 1297 | }; |
| 1298 | |
| 1299 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1301 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1302 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1303 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1305 | |
| 1306 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1307 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1308 | data1_writes[1] = *write_failure; |
| 1309 | } else { |
| 1310 | ASSERT_TRUE(read_failure); |
| 1311 | data1_reads[2] = *read_failure; |
| 1312 | } |
| 1313 | |
| 1314 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1315 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
| 1318 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1319 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1320 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1321 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1323 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1324 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1326 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | "hello", "world" |
| 1328 | }; |
| 1329 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1330 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1332 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1334 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1337 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1338 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | |
| 1340 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1341 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1343 | LoadTimingInfo load_timing_info; |
| 1344 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1345 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1346 | if (i == 0) { |
| 1347 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1348 | } else { |
| 1349 | // The second request should be using a new socket. |
| 1350 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1351 | } |
| 1352 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1353 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1354 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1356 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1357 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
| 1359 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1360 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1361 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1362 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | } |
| 1364 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1365 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1366 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1367 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1368 | const MockRead* read_failure, |
| 1369 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1370 | HttpRequestInfo request; |
| 1371 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1372 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1373 | request.load_flags = 0; |
| 1374 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1375 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1376 | session_deps_.net_log = &net_log; |
| 1377 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1378 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1379 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1380 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1381 | if (use_spdy) { |
| 1382 | ssl1.SetNextProto(GetParam()); |
| 1383 | ssl2.SetNextProto(GetParam()); |
| 1384 | } |
| 1385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1387 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1388 | // SPDY versions of the request and response. |
| 1389 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1390 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1391 | scoped_ptr<SpdyFrame> spdy_response( |
| 1392 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1393 | scoped_ptr<SpdyFrame> spdy_data( |
| 1394 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1395 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1396 | // HTTP/1.1 versions of the request and response. |
| 1397 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1398 | "Host: www.foo.com\r\n" |
| 1399 | "Connection: keep-alive\r\n\r\n"; |
| 1400 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1401 | const char kHttpData[] = "hello"; |
| 1402 | |
| 1403 | std::vector<MockRead> data1_reads; |
| 1404 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1405 | if (write_failure) { |
| 1406 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1407 | data1_writes.push_back(*write_failure); |
| 1408 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1409 | } else { |
| 1410 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1411 | if (use_spdy) { |
| 1412 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1413 | } else { |
| 1414 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1415 | } |
| 1416 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1417 | } |
| 1418 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1419 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1420 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1422 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1423 | std::vector<MockRead> data2_reads; |
| 1424 | std::vector<MockWrite> data2_writes; |
| 1425 | |
| 1426 | if (use_spdy) { |
| 1427 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1428 | |
| 1429 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1430 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1431 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1432 | } else { |
| 1433 | data2_writes.push_back( |
| 1434 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1435 | |
| 1436 | data2_reads.push_back( |
| 1437 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1438 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1439 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1440 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1441 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1442 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1443 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1444 | |
| 1445 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1446 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1447 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1448 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1449 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1450 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1451 | // Wait for the preconnect to complete. |
| 1452 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1453 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1454 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1455 | |
| 1456 | // Make the request. |
| 1457 | TestCompletionCallback callback; |
| 1458 | |
| 1459 | scoped_ptr<HttpTransaction> trans( |
| 1460 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1461 | |
| 1462 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1464 | |
| 1465 | rv = callback.WaitForResult(); |
| 1466 | EXPECT_EQ(OK, rv); |
| 1467 | |
| 1468 | LoadTimingInfo load_timing_info; |
| 1469 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1470 | TestLoadTimingNotReused( |
| 1471 | load_timing_info, |
| 1472 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1473 | |
| 1474 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1475 | ASSERT_TRUE(response != NULL); |
| 1476 | |
| 1477 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1478 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1479 | |
| 1480 | std::string response_data; |
| 1481 | rv = ReadTransaction(trans.get(), &response_data); |
| 1482 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1483 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1484 | } |
| 1485 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1486 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1487 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1488 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1489 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1490 | } |
| 1491 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1492 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1493 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1494 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1495 | } |
| 1496 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1497 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1498 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1499 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1500 | } |
| 1501 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1502 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1503 | // if the socket was a reused keep alive socket. |
| 1504 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1505 | MockRead read_failure(SYNCHRONOUS, |
| 1506 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1507 | "Connection: Keep-Alive\r\n" |
| 1508 | "Content-Length: 6\r\n\r\n" |
| 1509 | "Pickle"); |
| 1510 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1511 | } |
| 1512 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1513 | TEST_P(HttpNetworkTransactionTest, |
| 1514 | PreconnectErrorNotConnectedOnWrite) { |
| 1515 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1516 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1520 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1521 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1525 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1526 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1527 | } |
| 1528 | |
| 1529 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1530 | MockRead read_failure(ASYNC, OK); // EOF |
| 1531 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1532 | } |
| 1533 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1534 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1535 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1536 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1537 | MockRead read_failure(SYNCHRONOUS, |
| 1538 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1539 | "Connection: Keep-Alive\r\n" |
| 1540 | "Content-Length: 6\r\n\r\n" |
| 1541 | "Pickle"); |
| 1542 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1543 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1544 | } |
| 1545 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1546 | TEST_P(HttpNetworkTransactionTest, |
| 1547 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1548 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1549 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1550 | } |
| 1551 | |
| 1552 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1553 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1554 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1555 | } |
| 1556 | |
| 1557 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1558 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1559 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1560 | } |
| 1561 | |
| 1562 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1563 | MockRead read_failure(ASYNC, OK); // EOF |
| 1564 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1565 | } |
| 1566 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1567 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1568 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1570 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1571 | request.load_flags = 0; |
| 1572 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1573 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1574 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1575 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1576 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1577 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1578 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1579 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1580 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1582 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1584 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1586 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1588 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1589 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1590 | |
| 1591 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1592 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | // What do various browsers do when the server closes a non-keepalive |
| 1596 | // connection without sending any response header or body? |
| 1597 | // |
| 1598 | // IE7: error page |
| 1599 | // Safari 3.1.2 (Windows): error page |
| 1600 | // Firefox 3.0.1: blank page |
| 1601 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1602 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1603 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1604 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1605 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1606 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1607 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1608 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1609 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1610 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1611 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1612 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1613 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1614 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1615 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1616 | // Test that network access can be deferred and resumed. |
| 1617 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1618 | HttpRequestInfo request; |
| 1619 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1620 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1621 | request.load_flags = 0; |
| 1622 | |
| 1623 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1624 | scoped_ptr<HttpTransaction> trans( |
| 1625 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1626 | |
| 1627 | // Defer on OnBeforeNetworkStart. |
| 1628 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1629 | trans->SetBeforeNetworkStartCallback( |
| 1630 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1631 | base::Unretained(&net_start_handler))); |
| 1632 | |
| 1633 | MockRead data_reads[] = { |
| 1634 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1635 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1636 | MockRead("hello"), |
| 1637 | MockRead(SYNCHRONOUS, 0), |
| 1638 | }; |
| 1639 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1641 | |
| 1642 | TestCompletionCallback callback; |
| 1643 | |
| 1644 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1646 | base::MessageLoop::current()->RunUntilIdle(); |
| 1647 | |
| 1648 | // Should have deferred for network start. |
| 1649 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1650 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1651 | |
| 1652 | trans->ResumeNetworkStart(); |
| 1653 | rv = callback.WaitForResult(); |
| 1654 | EXPECT_EQ(OK, rv); |
| 1655 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1656 | |
| 1657 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1658 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1659 | if (rv == ERR_IO_PENDING) |
| 1660 | rv = callback.WaitForResult(); |
| 1661 | EXPECT_EQ(5, rv); |
| 1662 | trans.reset(); |
| 1663 | } |
| 1664 | |
| 1665 | // Test that network use can be deferred and canceled. |
| 1666 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1667 | HttpRequestInfo request; |
| 1668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1669 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1670 | request.load_flags = 0; |
| 1671 | |
| 1672 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1673 | scoped_ptr<HttpTransaction> trans( |
| 1674 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1675 | |
| 1676 | // Defer on OnBeforeNetworkStart. |
| 1677 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1678 | trans->SetBeforeNetworkStartCallback( |
| 1679 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1680 | base::Unretained(&net_start_handler))); |
| 1681 | |
| 1682 | TestCompletionCallback callback; |
| 1683 | |
| 1684 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1686 | base::MessageLoop::current()->RunUntilIdle(); |
| 1687 | |
| 1688 | // Should have deferred for network start. |
| 1689 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1690 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1691 | } |
| 1692 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1693 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1694 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1695 | // destructor in such situations. |
| 1696 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1697 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1698 | HttpRequestInfo request; |
| 1699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1701 | request.load_flags = 0; |
| 1702 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1703 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1704 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1705 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1706 | |
| 1707 | MockRead data_reads[] = { |
| 1708 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1709 | MockRead("Connection: keep-alive\r\n"), |
| 1710 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1711 | MockRead("hello"), |
| 1712 | MockRead(SYNCHRONOUS, 0), |
| 1713 | }; |
| 1714 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1716 | |
| 1717 | TestCompletionCallback callback; |
| 1718 | |
| 1719 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1720 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1721 | |
| 1722 | rv = callback.WaitForResult(); |
| 1723 | EXPECT_EQ(OK, rv); |
| 1724 | |
| 1725 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1726 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1727 | if (rv == ERR_IO_PENDING) |
| 1728 | rv = callback.WaitForResult(); |
| 1729 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1730 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1731 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1732 | |
| 1733 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1734 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1735 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1736 | } |
| 1737 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1738 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1739 | HttpRequestInfo request; |
| 1740 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1741 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1742 | request.load_flags = 0; |
| 1743 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1744 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1745 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1746 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1747 | |
| 1748 | MockRead data_reads[] = { |
| 1749 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1750 | MockRead("Connection: keep-alive\r\n"), |
| 1751 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1752 | MockRead(SYNCHRONOUS, 0), |
| 1753 | }; |
| 1754 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1756 | |
| 1757 | TestCompletionCallback callback; |
| 1758 | |
| 1759 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1761 | |
| 1762 | rv = callback.WaitForResult(); |
| 1763 | EXPECT_EQ(OK, rv); |
| 1764 | |
| 1765 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1766 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1767 | if (rv == ERR_IO_PENDING) |
| 1768 | rv = callback.WaitForResult(); |
| 1769 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1770 | |
| 1771 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1772 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1773 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1774 | } |
| 1775 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1776 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1777 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1778 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1779 | HttpRequestInfo request; |
| 1780 | request.method = "GET"; |
| 1781 | request.url = GURL("http://www.foo.com/"); |
| 1782 | request.load_flags = 0; |
| 1783 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1784 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1785 | session_deps_.net_log = &net_log; |
| 1786 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1787 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1788 | // Note that because all these reads happen in the same |
| 1789 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1790 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1791 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1792 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1793 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1794 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1795 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1796 | "Content-Length: 0\r\n\r\n"), |
| 1797 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1798 | "Content-Length: 5\r\n\r\n" |
| 1799 | "hello"), |
| 1800 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1801 | "Content-Length: 0\r\n\r\n"), |
| 1802 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1803 | "Content-Length: 5\r\n\r\n" |
| 1804 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1805 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1806 | MockRead("hello"), |
| 1807 | }; |
| 1808 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1810 | |
| 1811 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1812 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1813 | }; |
| 1814 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1816 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1817 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1818 | std::string response_lines[kNumUnreadBodies]; |
| 1819 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1820 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1821 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1822 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1823 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1824 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1825 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1827 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1828 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1829 | |
| 1830 | rv = callback.WaitForResult(); |
| 1831 | EXPECT_EQ(OK, rv); |
| 1832 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1833 | LoadTimingInfo load_timing_info; |
| 1834 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1835 | if (i == 0) { |
| 1836 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1837 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1838 | } else { |
| 1839 | TestLoadTimingReused(load_timing_info); |
| 1840 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1841 | } |
| 1842 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1843 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1844 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1845 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1846 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1847 | response_lines[i] = response->headers->GetStatusLine(); |
| 1848 | |
| 1849 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1850 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1851 | |
| 1852 | const char* const kStatusLines[] = { |
| 1853 | "HTTP/1.1 204 No Content", |
| 1854 | "HTTP/1.1 205 Reset Content", |
| 1855 | "HTTP/1.1 304 Not Modified", |
| 1856 | "HTTP/1.1 302 Found", |
| 1857 | "HTTP/1.1 302 Found", |
| 1858 | "HTTP/1.1 301 Moved Permanently", |
| 1859 | "HTTP/1.1 301 Moved Permanently", |
| 1860 | }; |
| 1861 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1862 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1863 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1864 | |
| 1865 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1866 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1867 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1868 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1869 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1871 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1872 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1873 | rv = callback.WaitForResult(); |
| 1874 | EXPECT_EQ(OK, rv); |
| 1875 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1876 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1877 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1878 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1879 | std::string response_data; |
| 1880 | rv = ReadTransaction(trans.get(), &response_data); |
| 1881 | EXPECT_EQ(OK, rv); |
| 1882 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1883 | } |
| 1884 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1885 | // Test the request-challenge-retry sequence for basic auth. |
| 1886 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1887 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1888 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1890 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1891 | request.load_flags = 0; |
| 1892 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1893 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1894 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1895 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1896 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1898 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1899 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1900 | MockWrite( |
| 1901 | "GET / HTTP/1.1\r\n" |
| 1902 | "Host: www.example.org\r\n" |
| 1903 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1904 | }; |
| 1905 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1906 | MockRead data_reads1[] = { |
| 1907 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1908 | // Give a couple authenticate options (only the middle one is actually |
| 1909 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1910 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1911 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1912 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1914 | // Large content-length -- won't matter, as connection will be reset. |
| 1915 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1916 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1917 | }; |
| 1918 | |
| 1919 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1920 | // be issuing -- the final header line contains the credentials. |
| 1921 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1922 | MockWrite( |
| 1923 | "GET / HTTP/1.1\r\n" |
| 1924 | "Host: www.example.org\r\n" |
| 1925 | "Connection: keep-alive\r\n" |
| 1926 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1927 | }; |
| 1928 | |
| 1929 | // Lastly, the server responds with the actual content. |
| 1930 | MockRead data_reads2[] = { |
| 1931 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1932 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1933 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1934 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1935 | }; |
| 1936 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1937 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1938 | data_writes1, arraysize(data_writes1)); |
| 1939 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1940 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1942 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1943 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1944 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1946 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1947 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1948 | |
| 1949 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1950 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1951 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1952 | LoadTimingInfo load_timing_info1; |
| 1953 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1954 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1955 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1956 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1957 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1958 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1959 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1960 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1961 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1963 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1965 | rv = trans->RestartWithAuth( |
| 1966 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1968 | |
| 1969 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1970 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1971 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1972 | LoadTimingInfo load_timing_info2; |
| 1973 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1974 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1975 | // The load timing after restart should have a new socket ID, and times after |
| 1976 | // those of the first load timing. |
| 1977 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1978 | load_timing_info2.connect_timing.connect_start); |
| 1979 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1980 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1981 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1982 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1983 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1984 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1985 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1986 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1987 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1988 | } |
| 1989 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1990 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1991 | HttpRequestInfo request; |
| 1992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1993 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1994 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1995 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1996 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1997 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1998 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1999 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2000 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2001 | MockWrite( |
| 2002 | "GET / HTTP/1.1\r\n" |
| 2003 | "Host: www.example.org\r\n" |
| 2004 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2005 | }; |
| 2006 | |
| 2007 | MockRead data_reads[] = { |
| 2008 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2009 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2010 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2011 | // Large content-length -- won't matter, as connection will be reset. |
| 2012 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2013 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2014 | }; |
| 2015 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2016 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2017 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2018 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2019 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2021 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2022 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2023 | |
| 2024 | rv = callback.WaitForResult(); |
| 2025 | EXPECT_EQ(0, rv); |
| 2026 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2027 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2028 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2029 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2030 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2031 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2032 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2033 | } |
| 2034 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2035 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2036 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2037 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2038 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2040 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2041 | request.load_flags = 0; |
| 2042 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2043 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2044 | session_deps_.net_log = &log; |
| 2045 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2046 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2047 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2048 | MockWrite( |
| 2049 | "GET / HTTP/1.1\r\n" |
| 2050 | "Host: www.example.org\r\n" |
| 2051 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2052 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2053 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2054 | // be issuing -- the final header line contains the credentials. |
| 2055 | MockWrite( |
| 2056 | "GET / HTTP/1.1\r\n" |
| 2057 | "Host: www.example.org\r\n" |
| 2058 | "Connection: keep-alive\r\n" |
| 2059 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2060 | }; |
| 2061 | |
| 2062 | MockRead data_reads1[] = { |
| 2063 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2064 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2065 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2066 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2067 | MockRead("Unauthorized\r\n"), |
| 2068 | |
| 2069 | // Lastly, the server responds with the actual content. |
| 2070 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2071 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2072 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2073 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2074 | }; |
| 2075 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2076 | // If there is a regression where we disconnect a Keep-Alive |
| 2077 | // connection during an auth roundtrip, we'll end up reading this. |
| 2078 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2079 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2080 | }; |
| 2081 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2082 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2083 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2084 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2085 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2086 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2087 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2089 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2090 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2091 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2092 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2093 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2094 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2095 | |
| 2096 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2097 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2098 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2099 | LoadTimingInfo load_timing_info1; |
| 2100 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2101 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2102 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2103 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2104 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2105 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[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 callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2109 | rv = trans->RestartWithAuth( |
| 2110 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2111 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2112 | |
| 2113 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2114 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2115 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2116 | LoadTimingInfo load_timing_info2; |
| 2117 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2118 | TestLoadTimingReused(load_timing_info2); |
| 2119 | // The load timing after restart should have the same socket ID, and times |
| 2120 | // those of the first load timing. |
| 2121 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2122 | load_timing_info2.send_start); |
| 2123 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2124 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2125 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2126 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2127 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2128 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2129 | |
| 2130 | std::string response_data; |
| 2131 | rv = ReadTransaction(trans.get(), &response_data); |
| 2132 | EXPECT_EQ(OK, rv); |
| 2133 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2134 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2138 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2139 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2140 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2141 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2142 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2143 | request.load_flags = 0; |
| 2144 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2145 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2146 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2147 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2148 | MockWrite( |
| 2149 | "GET / HTTP/1.1\r\n" |
| 2150 | "Host: www.example.org\r\n" |
| 2151 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2152 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2153 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2154 | // be issuing -- the final header line contains the credentials. |
| 2155 | MockWrite( |
| 2156 | "GET / HTTP/1.1\r\n" |
| 2157 | "Host: www.example.org\r\n" |
| 2158 | "Connection: keep-alive\r\n" |
| 2159 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2160 | }; |
| 2161 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2162 | MockRead data_reads1[] = { |
| 2163 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2164 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2165 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2166 | |
| 2167 | // Lastly, the server responds with the actual content. |
| 2168 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2169 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2170 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2171 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2172 | }; |
| 2173 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2174 | // An incorrect reconnect would cause this to be read. |
| 2175 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2176 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2177 | }; |
| 2178 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2179 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2180 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2181 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2182 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2183 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2184 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2186 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2188 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2189 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2190 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2192 | |
| 2193 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2194 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2195 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2196 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2197 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2198 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2200 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2202 | rv = trans->RestartWithAuth( |
| 2203 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2204 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2205 | |
| 2206 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2207 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2208 | |
| 2209 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2210 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2211 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2212 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2216 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2217 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2218 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2219 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2220 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2221 | request.load_flags = 0; |
| 2222 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2223 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2224 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2225 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2226 | MockWrite( |
| 2227 | "GET / HTTP/1.1\r\n" |
| 2228 | "Host: www.example.org\r\n" |
| 2229 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2230 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2231 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2232 | // be issuing -- the final header line contains the credentials. |
| 2233 | MockWrite( |
| 2234 | "GET / HTTP/1.1\r\n" |
| 2235 | "Host: www.example.org\r\n" |
| 2236 | "Connection: keep-alive\r\n" |
| 2237 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2238 | }; |
| 2239 | |
| 2240 | // Respond with 5 kb of response body. |
| 2241 | std::string large_body_string("Unauthorized"); |
| 2242 | large_body_string.append(5 * 1024, ' '); |
| 2243 | large_body_string.append("\r\n"); |
| 2244 | |
| 2245 | MockRead data_reads1[] = { |
| 2246 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2247 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2248 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2249 | // 5134 = 12 + 5 * 1024 + 2 |
| 2250 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2251 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2252 | |
| 2253 | // Lastly, the server responds with the actual content. |
| 2254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2256 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2257 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2258 | }; |
| 2259 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2260 | // An incorrect reconnect would cause this to be read. |
| 2261 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2262 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2263 | }; |
| 2264 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2265 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2266 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2267 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2268 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2270 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2272 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2274 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2276 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2278 | |
| 2279 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2280 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2281 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2283 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2284 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2286 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2288 | rv = trans->RestartWithAuth( |
| 2289 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2291 | |
| 2292 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2293 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2294 | |
| 2295 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2296 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2297 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2298 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2302 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2303 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2304 | HttpRequestInfo request; |
| 2305 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2306 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2307 | request.load_flags = 0; |
| 2308 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2310 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2311 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2312 | MockWrite( |
| 2313 | "GET / HTTP/1.1\r\n" |
| 2314 | "Host: www.example.org\r\n" |
| 2315 | "Connection: keep-alive\r\n\r\n"), |
| 2316 | // This simulates the seemingly successful write to a closed connection |
| 2317 | // if the bug is not fixed. |
| 2318 | MockWrite( |
| 2319 | "GET / HTTP/1.1\r\n" |
| 2320 | "Host: www.example.org\r\n" |
| 2321 | "Connection: keep-alive\r\n" |
| 2322 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2323 | }; |
| 2324 | |
| 2325 | MockRead data_reads1[] = { |
| 2326 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2327 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2328 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2329 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2330 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2331 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2332 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2333 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2334 | }; |
| 2335 | |
| 2336 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2337 | // be issuing -- the final header line contains the credentials. |
| 2338 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 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 | // Lastly, the server responds with the actual content. |
| 2347 | MockRead data_reads2[] = { |
| 2348 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2349 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2350 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2351 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2352 | }; |
| 2353 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2354 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2355 | data_writes1, arraysize(data_writes1)); |
| 2356 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2357 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2358 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2359 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2361 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2362 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2363 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2364 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2365 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2366 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2367 | |
| 2368 | rv = callback1.WaitForResult(); |
| 2369 | EXPECT_EQ(OK, rv); |
| 2370 | |
| 2371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2372 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2373 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2375 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2377 | rv = trans->RestartWithAuth( |
| 2378 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2380 | |
| 2381 | rv = callback2.WaitForResult(); |
| 2382 | EXPECT_EQ(OK, rv); |
| 2383 | |
| 2384 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2385 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2386 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2387 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2388 | } |
| 2389 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2390 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2391 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2392 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2393 | HttpRequestInfo request; |
| 2394 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2395 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2396 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2397 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2398 | |
| 2399 | // Configure against proxy server "myproxy:70". |
| 2400 | session_deps_.proxy_service.reset( |
| 2401 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2402 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2403 | session_deps_.net_log = log.bound().net_log(); |
| 2404 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2405 | |
| 2406 | // Since we have proxy, should try to establish tunnel. |
| 2407 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2408 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2409 | "Host: www.example.org\r\n" |
| 2410 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2411 | }; |
| 2412 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2413 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2414 | // connection. |
| 2415 | MockRead data_reads1[] = { |
| 2416 | // No credentials. |
| 2417 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2418 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2419 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2420 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2421 | // Since the first connection couldn't be reused, need to establish another |
| 2422 | // once given credentials. |
| 2423 | MockWrite data_writes2[] = { |
| 2424 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2425 | // be issuing -- the final header line contains the credentials. |
| 2426 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2427 | "Host: www.example.org\r\n" |
| 2428 | "Proxy-Connection: keep-alive\r\n" |
| 2429 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2430 | |
| 2431 | MockWrite("GET / HTTP/1.1\r\n" |
| 2432 | "Host: www.example.org\r\n" |
| 2433 | "Connection: keep-alive\r\n\r\n"), |
| 2434 | }; |
| 2435 | |
| 2436 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2437 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2438 | |
| 2439 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2440 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2441 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2442 | MockRead(SYNCHRONOUS, "hello"), |
| 2443 | }; |
| 2444 | |
| 2445 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2446 | data_writes1, arraysize(data_writes1)); |
| 2447 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2448 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2449 | data_writes2, arraysize(data_writes2)); |
| 2450 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2451 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2453 | |
| 2454 | TestCompletionCallback callback1; |
| 2455 | |
| 2456 | scoped_ptr<HttpTransaction> trans( |
| 2457 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2458 | |
| 2459 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2460 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2461 | |
| 2462 | rv = callback1.WaitForResult(); |
| 2463 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2464 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2465 | log.GetEntries(&entries); |
| 2466 | size_t pos = ExpectLogContainsSomewhere( |
| 2467 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2468 | NetLog::PHASE_NONE); |
| 2469 | ExpectLogContainsSomewhere( |
| 2470 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2471 | NetLog::PHASE_NONE); |
| 2472 | |
| 2473 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2474 | ASSERT_TRUE(response != NULL); |
| 2475 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2476 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2477 | EXPECT_EQ(407, response->headers->response_code()); |
| 2478 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2479 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2480 | |
| 2481 | LoadTimingInfo load_timing_info; |
| 2482 | // CONNECT requests and responses are handled at the connect job level, so |
| 2483 | // the transaction does not yet have a connection. |
| 2484 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2485 | |
| 2486 | TestCompletionCallback callback2; |
| 2487 | |
| 2488 | rv = |
| 2489 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2490 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2491 | |
| 2492 | rv = callback2.WaitForResult(); |
| 2493 | EXPECT_EQ(OK, rv); |
| 2494 | |
| 2495 | response = trans->GetResponseInfo(); |
| 2496 | ASSERT_TRUE(response != NULL); |
| 2497 | |
| 2498 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2499 | EXPECT_EQ(200, response->headers->response_code()); |
| 2500 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2501 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2502 | |
| 2503 | // The password prompt info should not be set. |
| 2504 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2505 | |
| 2506 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2507 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2508 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2509 | |
| 2510 | trans.reset(); |
| 2511 | session->CloseAllConnections(); |
| 2512 | } |
| 2513 | |
| 2514 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2515 | // that requires a restart when setting up an SSL tunnel. |
| 2516 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2517 | HttpRequestInfo request; |
| 2518 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2519 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2520 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2521 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2522 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2523 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2524 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2525 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2526 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2527 | session_deps_.net_log = log.bound().net_log(); |
| 2528 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2529 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2530 | // Since we have proxy, should try to establish tunnel. |
| 2531 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2532 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2533 | "Host: www.example.org\r\n" |
| 2534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2535 | }; |
| 2536 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2537 | // The proxy responds to the connect with a 407, using a non-persistent |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2538 | // connection. |
| 2539 | MockRead data_reads1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2540 | // No credentials. |
| 2541 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2542 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2543 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2544 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2545 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2546 | MockWrite data_writes2[] = { |
| 2547 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2548 | // be issuing -- the final header line contains the credentials. |
| 2549 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2550 | "Host: www.example.org\r\n" |
| 2551 | "Proxy-Connection: keep-alive\r\n" |
| 2552 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2553 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2554 | MockWrite("GET / HTTP/1.1\r\n" |
| 2555 | "Host: www.example.org\r\n" |
| 2556 | "Connection: keep-alive\r\n\r\n"), |
| 2557 | }; |
| 2558 | |
| 2559 | MockRead data_reads2[] = { |
| 2560 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2561 | |
| 2562 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2563 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2564 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2565 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2566 | }; |
| 2567 | |
| 2568 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2569 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2570 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2571 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2572 | data_writes2, arraysize(data_writes2)); |
| 2573 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2574 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2577 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2578 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2579 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2580 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2582 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2583 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2584 | |
| 2585 | rv = callback1.WaitForResult(); |
| 2586 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2587 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2588 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2589 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2590 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2591 | NetLog::PHASE_NONE); |
| 2592 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2593 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2594 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2595 | NetLog::PHASE_NONE); |
| 2596 | |
| 2597 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2598 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2599 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2600 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2601 | EXPECT_EQ(407, response->headers->response_code()); |
| 2602 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2603 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2604 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2605 | LoadTimingInfo load_timing_info; |
| 2606 | // CONNECT requests and responses are handled at the connect job level, so |
| 2607 | // the transaction does not yet have a connection. |
| 2608 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2610 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2612 | rv = trans->RestartWithAuth( |
| 2613 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2614 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2615 | |
| 2616 | rv = callback2.WaitForResult(); |
| 2617 | EXPECT_EQ(OK, rv); |
| 2618 | |
| 2619 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2620 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2621 | |
| 2622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2623 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2624 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2625 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2626 | |
| 2627 | // The password prompt info should not be set. |
| 2628 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2629 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2630 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2631 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2632 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2633 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2634 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2635 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2636 | } |
| 2637 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2638 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2639 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2640 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2641 | HttpRequestInfo request; |
| 2642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2643 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2644 | // Ensure that proxy authentication is attempted even |
| 2645 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2646 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2647 | |
| 2648 | // Configure against proxy server "myproxy:70". |
| 2649 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2650 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2651 | session_deps_.net_log = log.bound().net_log(); |
| 2652 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2653 | |
| 2654 | scoped_ptr<HttpTransaction> trans( |
| 2655 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2656 | |
| 2657 | // Since we have proxy, should try to establish tunnel. |
| 2658 | MockWrite data_writes1[] = { |
| 2659 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2660 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2661 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2662 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2663 | |
| 2664 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2665 | // be issuing -- the final header line contains the credentials. |
| 2666 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2667 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2668 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2669 | "Proxy-Connection: keep-alive\r\n" |
| 2670 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2671 | }; |
| 2672 | |
| 2673 | // The proxy responds to the connect with a 407, using a persistent |
| 2674 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2675 | MockRead data_reads1[] = { |
| 2676 | // No credentials. |
| 2677 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2678 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2679 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2680 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2681 | MockRead("0123456789"), |
| 2682 | |
| 2683 | // Wrong credentials (wrong password). |
| 2684 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2685 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2686 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2687 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2688 | // No response body because the test stops reading here. |
| 2689 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2690 | }; |
| 2691 | |
| 2692 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2693 | data_writes1, arraysize(data_writes1)); |
| 2694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2695 | |
| 2696 | TestCompletionCallback callback1; |
| 2697 | |
| 2698 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2699 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2700 | |
| 2701 | rv = callback1.WaitForResult(); |
| 2702 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2703 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2704 | log.GetEntries(&entries); |
| 2705 | size_t pos = ExpectLogContainsSomewhere( |
| 2706 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2707 | NetLog::PHASE_NONE); |
| 2708 | ExpectLogContainsSomewhere( |
| 2709 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2710 | NetLog::PHASE_NONE); |
| 2711 | |
| 2712 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2713 | ASSERT_TRUE(response); |
| 2714 | ASSERT_TRUE(response->headers); |
| 2715 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2716 | EXPECT_EQ(407, response->headers->response_code()); |
| 2717 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2718 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2719 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2720 | |
| 2721 | TestCompletionCallback callback2; |
| 2722 | |
| 2723 | // Wrong password (should be "bar"). |
| 2724 | rv = |
| 2725 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2726 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2727 | |
| 2728 | rv = callback2.WaitForResult(); |
| 2729 | EXPECT_EQ(OK, rv); |
| 2730 | |
| 2731 | response = trans->GetResponseInfo(); |
| 2732 | ASSERT_TRUE(response); |
| 2733 | ASSERT_TRUE(response->headers); |
| 2734 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2735 | EXPECT_EQ(407, response->headers->response_code()); |
| 2736 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2737 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2738 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2739 | |
| 2740 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2741 | // out of scope. |
| 2742 | session->CloseAllConnections(); |
| 2743 | } |
| 2744 | |
| 2745 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2746 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2747 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2748 | HttpRequestInfo request; |
| 2749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2750 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2751 | // Ensure that proxy authentication is attempted even |
| 2752 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2753 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2754 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2755 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2756 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2757 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2758 | session_deps_.net_log = log.bound().net_log(); |
| 2759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2763 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2764 | // Since we have proxy, should try to establish tunnel. |
| 2765 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2766 | MockWrite( |
| 2767 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2768 | "Host: www.example.org\r\n" |
| 2769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2770 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2771 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2772 | // be issuing -- the final header line contains the credentials. |
| 2773 | MockWrite( |
| 2774 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2775 | "Host: www.example.org\r\n" |
| 2776 | "Proxy-Connection: keep-alive\r\n" |
| 2777 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2778 | }; |
| 2779 | |
| 2780 | // The proxy responds to the connect with a 407, using a persistent |
| 2781 | // connection. |
| 2782 | MockRead data_reads1[] = { |
| 2783 | // No credentials. |
| 2784 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2785 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2786 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2787 | MockRead("0123456789"), |
| 2788 | |
| 2789 | // Wrong credentials (wrong password). |
| 2790 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2791 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2792 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2793 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2794 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | }; |
| 2796 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2797 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2798 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2801 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2803 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2804 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | |
| 2806 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2807 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2808 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2809 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2810 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2811 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2812 | NetLog::PHASE_NONE); |
| 2813 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2814 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2815 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2816 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2817 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2819 | ASSERT_TRUE(response); |
| 2820 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2821 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2822 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2823 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2824 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2825 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2827 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2828 | |
| 2829 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2830 | rv = trans->RestartWithAuth( |
| 2831 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2833 | |
| 2834 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2835 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2836 | |
| 2837 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2838 | ASSERT_TRUE(response); |
| 2839 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2841 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2842 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2843 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2844 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2845 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2846 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2847 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2848 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2849 | } |
| 2850 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 2851 | // Test the case a proxy closes a socket while the challenge body is being |
| 2852 | // drained. |
| 2853 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 2854 | HttpRequestInfo request; |
| 2855 | request.method = "GET"; |
| 2856 | request.url = GURL("https://www.example.org/"); |
| 2857 | // Ensure that proxy authentication is attempted even |
| 2858 | // when the no authentication data flag is set. |
| 2859 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2860 | |
| 2861 | // Configure against proxy server "myproxy:70". |
| 2862 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2863 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2864 | |
| 2865 | scoped_ptr<HttpTransaction> trans( |
| 2866 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2867 | |
| 2868 | // Since we have proxy, should try to establish tunnel. |
| 2869 | MockWrite data_writes1[] = { |
| 2870 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2871 | "Host: www.example.org\r\n" |
| 2872 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2873 | }; |
| 2874 | |
| 2875 | // The proxy responds to the connect with a 407, using a persistent |
| 2876 | // connection. |
| 2877 | MockRead data_reads1[] = { |
| 2878 | // No credentials. |
| 2879 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2880 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2881 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 2882 | // Server hands up in the middle of the body. |
| 2883 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 2884 | }; |
| 2885 | |
| 2886 | MockWrite data_writes2[] = { |
| 2887 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2888 | // be issuing -- the final header line contains the credentials. |
| 2889 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2890 | "Host: www.example.org\r\n" |
| 2891 | "Proxy-Connection: keep-alive\r\n" |
| 2892 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2893 | |
| 2894 | MockWrite("GET / HTTP/1.1\r\n" |
| 2895 | "Host: www.example.org\r\n" |
| 2896 | "Connection: keep-alive\r\n\r\n"), |
| 2897 | }; |
| 2898 | |
| 2899 | MockRead data_reads2[] = { |
| 2900 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2901 | |
| 2902 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2903 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2904 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2905 | MockRead(SYNCHRONOUS, "hello"), |
| 2906 | }; |
| 2907 | |
| 2908 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2909 | data_writes1, arraysize(data_writes1)); |
| 2910 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2911 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2912 | data_writes2, arraysize(data_writes2)); |
| 2913 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2914 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2916 | |
| 2917 | TestCompletionCallback callback; |
| 2918 | |
| 2919 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2920 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2921 | |
| 2922 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2923 | ASSERT_TRUE(response); |
| 2924 | ASSERT_TRUE(response->headers); |
| 2925 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2926 | EXPECT_EQ(407, response->headers->response_code()); |
| 2927 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2928 | |
| 2929 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 2930 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2931 | |
| 2932 | response = trans->GetResponseInfo(); |
| 2933 | ASSERT_TRUE(response); |
| 2934 | ASSERT_TRUE(response->headers); |
| 2935 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2936 | EXPECT_EQ(200, response->headers->response_code()); |
| 2937 | std::string body; |
| 2938 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 2939 | EXPECT_EQ("hello", body); |
| 2940 | } |
| 2941 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2942 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2943 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2944 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2945 | HttpRequestInfo request; |
| 2946 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2947 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2948 | request.load_flags = 0; |
| 2949 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2950 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2951 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2952 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2953 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2954 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2955 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2956 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2957 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2958 | // Since we have proxy, should try to establish tunnel. |
| 2959 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2960 | MockWrite( |
| 2961 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2962 | "Host: www.example.org\r\n" |
| 2963 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2964 | }; |
| 2965 | |
| 2966 | // The proxy responds to the connect with a 407. |
| 2967 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2968 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2969 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2970 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2971 | MockRead("0123456789"), // Should not be reached. |
| 2972 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2973 | }; |
| 2974 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2975 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2976 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2977 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2979 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2981 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2983 | |
| 2984 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2985 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2986 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2988 | ASSERT_TRUE(response); |
| 2989 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2990 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2991 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2992 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2993 | |
| 2994 | std::string response_data; |
| 2995 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2996 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2997 | |
| 2998 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2999 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3000 | } |
| 3001 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3002 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3003 | // caller when the proxy responds to CONNECT with 407. |
| 3004 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3005 | HttpRequestInfo request; |
| 3006 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3007 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3008 | request.load_flags = 0; |
| 3009 | |
| 3010 | // Configure against proxy server "myproxy:70". |
| 3011 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 3012 | |
| 3013 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3014 | |
| 3015 | scoped_ptr<HttpTransaction> trans( |
| 3016 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3017 | |
| 3018 | // Since we have proxy, should try to establish tunnel. |
| 3019 | MockWrite data_writes[] = { |
| 3020 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3021 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3022 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3023 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3024 | }; |
| 3025 | |
| 3026 | // The proxy responds to the connect with a 407. |
| 3027 | MockRead data_reads[] = { |
| 3028 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3029 | MockRead("X-Foo: bar\r\n"), |
| 3030 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3031 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3032 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3033 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3034 | }; |
| 3035 | |
| 3036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3037 | arraysize(data_writes)); |
| 3038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3039 | |
| 3040 | TestCompletionCallback callback; |
| 3041 | |
| 3042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3044 | |
| 3045 | rv = callback.WaitForResult(); |
| 3046 | EXPECT_EQ(OK, rv); |
| 3047 | |
| 3048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3049 | ASSERT_TRUE(response); |
| 3050 | ASSERT_TRUE(response->headers); |
| 3051 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3052 | EXPECT_EQ(407, response->headers->response_code()); |
| 3053 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3054 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3055 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3056 | |
| 3057 | std::string response_data; |
| 3058 | rv = ReadTransaction(trans.get(), &response_data); |
| 3059 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3060 | |
| 3061 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3062 | session->CloseAllConnections(); |
| 3063 | } |
| 3064 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3065 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3066 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3067 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3068 | HttpRequestInfo request; |
| 3069 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3070 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3071 | request.load_flags = 0; |
| 3072 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3073 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 3074 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3075 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3077 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3078 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3079 | MockWrite( |
| 3080 | "GET / HTTP/1.1\r\n" |
| 3081 | "Host: www.example.org\r\n" |
| 3082 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3083 | }; |
| 3084 | |
| 3085 | MockRead data_reads1[] = { |
| 3086 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3087 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3088 | // Large content-length -- won't matter, as connection will be reset. |
| 3089 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3090 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3091 | }; |
| 3092 | |
| 3093 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3094 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3095 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3097 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3099 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3100 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3101 | |
| 3102 | rv = callback.WaitForResult(); |
| 3103 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3104 | } |
| 3105 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3106 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3107 | // through a non-authenticating proxy. The request should fail with |
| 3108 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3109 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3110 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3111 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3112 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3113 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3114 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3115 | HttpRequestInfo request; |
| 3116 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3117 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3118 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3119 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3120 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3121 | session_deps_.net_log = log.bound().net_log(); |
| 3122 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3123 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3124 | // Since we have proxy, should try to establish tunnel. |
| 3125 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3126 | MockWrite( |
| 3127 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3128 | "Host: www.example.org\r\n" |
| 3129 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3130 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3131 | MockWrite( |
| 3132 | "GET / HTTP/1.1\r\n" |
| 3133 | "Host: www.example.org\r\n" |
| 3134 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3135 | }; |
| 3136 | |
| 3137 | MockRead data_reads1[] = { |
| 3138 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3139 | |
| 3140 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3141 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3142 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3143 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3144 | }; |
| 3145 | |
| 3146 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3147 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3148 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3149 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3152 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3153 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3154 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3157 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3159 | |
| 3160 | rv = callback1.WaitForResult(); |
| 3161 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3162 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3163 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3164 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3165 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3166 | NetLog::PHASE_NONE); |
| 3167 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3168 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3169 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3170 | NetLog::PHASE_NONE); |
| 3171 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3172 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3173 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3174 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3175 | HttpRequestInfo request1; |
| 3176 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3177 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3178 | |
| 3179 | HttpRequestInfo request2; |
| 3180 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3181 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3182 | |
| 3183 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3184 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3185 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3186 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3187 | session_deps_.net_log = log.bound().net_log(); |
| 3188 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3189 | |
| 3190 | // Since we have proxy, should try to establish tunnel. |
| 3191 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3192 | MockWrite( |
| 3193 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3194 | "Host: www.example.org\r\n" |
| 3195 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3196 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3197 | MockWrite( |
| 3198 | "GET /1 HTTP/1.1\r\n" |
| 3199 | "Host: www.example.org\r\n" |
| 3200 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3201 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3202 | MockWrite( |
| 3203 | "GET /2 HTTP/1.1\r\n" |
| 3204 | "Host: www.example.org\r\n" |
| 3205 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3206 | }; |
| 3207 | |
| 3208 | // The proxy responds to the connect with a 407, using a persistent |
| 3209 | // connection. |
| 3210 | MockRead data_reads1[] = { |
| 3211 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3212 | |
| 3213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3214 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3215 | MockRead(SYNCHRONOUS, "1"), |
| 3216 | |
| 3217 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3218 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3219 | MockRead(SYNCHRONOUS, "22"), |
| 3220 | }; |
| 3221 | |
| 3222 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3223 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3224 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3225 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3227 | |
| 3228 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3229 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3231 | |
| 3232 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3233 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3234 | |
| 3235 | rv = callback1.WaitForResult(); |
| 3236 | EXPECT_EQ(OK, rv); |
| 3237 | |
| 3238 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3239 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3240 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3241 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3242 | |
| 3243 | LoadTimingInfo load_timing_info1; |
| 3244 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3245 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3246 | |
| 3247 | trans1.reset(); |
| 3248 | |
| 3249 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3250 | scoped_ptr<HttpTransaction> trans2( |
[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 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3255 | |
| 3256 | rv = callback2.WaitForResult(); |
| 3257 | EXPECT_EQ(OK, rv); |
| 3258 | |
| 3259 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3260 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3261 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3262 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3263 | |
| 3264 | LoadTimingInfo load_timing_info2; |
| 3265 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3266 | TestLoadTimingReused(load_timing_info2); |
| 3267 | |
| 3268 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3269 | |
| 3270 | trans2.reset(); |
| 3271 | session->CloseAllConnections(); |
| 3272 | } |
| 3273 | |
| 3274 | // 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] | 3275 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3276 | HttpRequestInfo request1; |
| 3277 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3278 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3279 | |
| 3280 | HttpRequestInfo request2; |
| 3281 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3282 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3283 | |
| 3284 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3285 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3286 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3287 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3288 | session_deps_.net_log = log.bound().net_log(); |
| 3289 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3290 | |
| 3291 | // Since we have proxy, should try to establish tunnel. |
| 3292 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3293 | MockWrite( |
| 3294 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3295 | "Host: www.example.org\r\n" |
| 3296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3297 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3298 | MockWrite( |
| 3299 | "GET /1 HTTP/1.1\r\n" |
| 3300 | "Host: www.example.org\r\n" |
| 3301 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3302 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3303 | MockWrite( |
| 3304 | "GET /2 HTTP/1.1\r\n" |
| 3305 | "Host: www.example.org\r\n" |
| 3306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3307 | }; |
| 3308 | |
| 3309 | // The proxy responds to the connect with a 407, using a persistent |
| 3310 | // connection. |
| 3311 | MockRead data_reads1[] = { |
| 3312 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3313 | |
| 3314 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3315 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3316 | MockRead(SYNCHRONOUS, "1"), |
| 3317 | |
| 3318 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3319 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3320 | MockRead(SYNCHRONOUS, "22"), |
| 3321 | }; |
| 3322 | |
| 3323 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3324 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3326 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3328 | |
| 3329 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3330 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3332 | |
| 3333 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3335 | |
| 3336 | rv = callback1.WaitForResult(); |
| 3337 | EXPECT_EQ(OK, rv); |
| 3338 | |
| 3339 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3340 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3341 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3342 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3343 | |
| 3344 | LoadTimingInfo load_timing_info1; |
| 3345 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3346 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3347 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3348 | |
| 3349 | trans1.reset(); |
| 3350 | |
| 3351 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3352 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3354 | |
| 3355 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3357 | |
| 3358 | rv = callback2.WaitForResult(); |
| 3359 | EXPECT_EQ(OK, rv); |
| 3360 | |
| 3361 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3362 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3363 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3364 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3365 | |
| 3366 | LoadTimingInfo load_timing_info2; |
| 3367 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3368 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3369 | |
| 3370 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3371 | |
| 3372 | trans2.reset(); |
| 3373 | session->CloseAllConnections(); |
| 3374 | } |
| 3375 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3376 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3377 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3378 | HttpRequestInfo request; |
| 3379 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3380 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3381 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3382 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3383 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3384 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3385 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3386 | session_deps_.net_log = log.bound().net_log(); |
| 3387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3388 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3389 | // Since we have proxy, should use full url |
| 3390 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3391 | MockWrite( |
| 3392 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3393 | "Host: www.example.org\r\n" |
| 3394 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3395 | }; |
| 3396 | |
| 3397 | MockRead data_reads1[] = { |
| 3398 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3399 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3400 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3402 | }; |
| 3403 | |
| 3404 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3405 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3406 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3407 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3410 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3411 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3412 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3413 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3415 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3416 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3417 | |
| 3418 | rv = callback1.WaitForResult(); |
| 3419 | EXPECT_EQ(OK, rv); |
| 3420 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3421 | LoadTimingInfo load_timing_info; |
| 3422 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3423 | TestLoadTimingNotReused(load_timing_info, |
| 3424 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3425 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3426 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3427 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3428 | |
| 3429 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3430 | EXPECT_EQ(200, response->headers->response_code()); |
| 3431 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3432 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3433 | |
| 3434 | // The password prompt info should not be set. |
| 3435 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3436 | } |
| 3437 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3438 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3439 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3440 | HttpRequestInfo request; |
| 3441 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3442 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3443 | request.load_flags = 0; |
| 3444 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3445 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3446 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3447 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3448 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3449 | session_deps_.net_log = log.bound().net_log(); |
| 3450 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3451 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3452 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3453 | scoped_ptr<SpdyFrame> req( |
| 3454 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3455 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3457 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3458 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3459 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3460 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3461 | }; |
| 3462 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3463 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3464 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3465 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3466 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3467 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3468 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3471 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3472 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3473 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3474 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3476 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3477 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3478 | |
| 3479 | rv = callback1.WaitForResult(); |
| 3480 | EXPECT_EQ(OK, rv); |
| 3481 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3482 | LoadTimingInfo load_timing_info; |
| 3483 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3484 | TestLoadTimingNotReused(load_timing_info, |
| 3485 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3486 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3487 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3488 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3489 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3490 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3491 | |
| 3492 | std::string response_data; |
| 3493 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3494 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3495 | } |
| 3496 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3497 | // Verifies that a session which races and wins against the owning transaction |
| 3498 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3499 | // Regression test for crbug.com/334413. |
| 3500 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3501 | HttpRequestInfo request; |
| 3502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3503 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3504 | request.load_flags = 0; |
| 3505 | |
| 3506 | // Configure SPDY proxy server "proxy:70". |
| 3507 | session_deps_.proxy_service.reset( |
| 3508 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3509 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3510 | session_deps_.net_log = log.bound().net_log(); |
| 3511 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3512 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3513 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3514 | scoped_ptr<SpdyFrame> req( |
| 3515 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3516 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3517 | |
| 3518 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3519 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3520 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3521 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3522 | }; |
| 3523 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3524 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3525 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3526 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3527 | |
| 3528 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3529 | ssl.SetNextProto(GetParam()); |
| 3530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3531 | |
| 3532 | TestCompletionCallback callback1; |
| 3533 | |
| 3534 | scoped_ptr<HttpTransaction> trans( |
| 3535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3536 | |
| 3537 | // Stall the hostname resolution begun by the transaction. |
| 3538 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3539 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3540 | |
| 3541 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3543 | |
| 3544 | // Race a session to the proxy, which completes first. |
| 3545 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3546 | SpdySessionKey key( |
| 3547 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3548 | base::WeakPtr<SpdySession> spdy_session = |
| 3549 | CreateSecureSpdySession(session, key, log.bound()); |
| 3550 | |
| 3551 | // Unstall the resolution begun by the transaction. |
| 3552 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3553 | session_deps_.host_resolver->ResolveAllPending(); |
| 3554 | |
| 3555 | EXPECT_FALSE(callback1.have_result()); |
| 3556 | rv = callback1.WaitForResult(); |
| 3557 | EXPECT_EQ(OK, rv); |
| 3558 | |
| 3559 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3560 | ASSERT_TRUE(response != NULL); |
| 3561 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3562 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3563 | |
| 3564 | std::string response_data; |
| 3565 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3566 | EXPECT_EQ(kUploadData, response_data); |
| 3567 | } |
| 3568 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3569 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3570 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3571 | HttpRequestInfo request; |
| 3572 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3573 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3574 | request.load_flags = 0; |
| 3575 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3576 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3577 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3578 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3579 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3580 | session_deps_.net_log = log.bound().net_log(); |
| 3581 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3582 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3583 | // The first request will be a bare GET, the second request will be a |
| 3584 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3585 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3586 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3587 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3588 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3589 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3590 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3591 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3592 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3593 | false, |
| 3594 | 3, |
| 3595 | LOWEST, |
| 3596 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3597 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3598 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3599 | }; |
| 3600 | |
| 3601 | // The first response is a 407 proxy authentication challenge, and the second |
| 3602 | // response will be a 200 response since the second request includes a valid |
| 3603 | // Authorization header. |
| 3604 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3605 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3606 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3607 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3608 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3609 | "407 Proxy Authentication Required", |
| 3610 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3611 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3612 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3613 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3614 | scoped_ptr<SpdyFrame> resp_data( |
| 3615 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3616 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3617 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3618 | CreateMockRead(*resp_authentication, 1), |
| 3619 | CreateMockRead(*body_authentication, 2), |
| 3620 | CreateMockRead(*resp_data, 4), |
| 3621 | CreateMockRead(*body_data, 5), |
| 3622 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3623 | }; |
| 3624 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3625 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3626 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3628 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3629 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3630 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3633 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3634 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3635 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3638 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3640 | |
| 3641 | rv = callback1.WaitForResult(); |
| 3642 | EXPECT_EQ(OK, rv); |
| 3643 | |
| 3644 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3645 | |
| 3646 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3647 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3648 | EXPECT_EQ(407, response->headers->response_code()); |
| 3649 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3650 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3652 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3654 | rv = trans->RestartWithAuth( |
| 3655 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3656 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3657 | |
| 3658 | rv = callback2.WaitForResult(); |
| 3659 | EXPECT_EQ(OK, rv); |
| 3660 | |
| 3661 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3662 | |
| 3663 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3664 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3665 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3666 | // The password prompt info should not be set. |
| 3667 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3668 | } |
| 3669 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3670 | // 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] | 3671 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3672 | HttpRequestInfo request; |
| 3673 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3674 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3675 | request.load_flags = 0; |
| 3676 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3677 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3678 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3679 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3680 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3681 | session_deps_.net_log = log.bound().net_log(); |
| 3682 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3683 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3684 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3686 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3687 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3688 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3689 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3690 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3691 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3692 | const char get[] = |
| 3693 | "GET / HTTP/1.1\r\n" |
| 3694 | "Host: www.example.org\r\n" |
| 3695 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3696 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3697 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3698 | scoped_ptr<SpdyFrame> conn_resp( |
| 3699 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3700 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3701 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3702 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3703 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3704 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3705 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3706 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3707 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3708 | |
| 3709 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3710 | CreateMockWrite(*connect, 0), |
| 3711 | CreateMockWrite(*wrapped_get, 2), |
| 3712 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3713 | }; |
| 3714 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3715 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3716 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3717 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3718 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3719 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3720 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3721 | }; |
| 3722 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3723 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3724 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3725 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3726 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3727 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3728 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3729 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3730 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3733 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3735 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3736 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3737 | |
| 3738 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3739 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3740 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3741 | LoadTimingInfo load_timing_info; |
| 3742 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3743 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3744 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3745 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3746 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3747 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3748 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3749 | |
| 3750 | std::string response_data; |
| 3751 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3752 | EXPECT_EQ("1234567890", response_data); |
| 3753 | } |
| 3754 | |
| 3755 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3756 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3757 | HttpRequestInfo request; |
| 3758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3759 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3760 | request.load_flags = 0; |
| 3761 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3762 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3763 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3764 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3765 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3766 | session_deps_.net_log = log.bound().net_log(); |
| 3767 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3768 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3769 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3771 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3772 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3773 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3774 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3775 | // fetch https://www.example.org/ via SPDY |
| 3776 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3777 | scoped_ptr<SpdyFrame> get( |
| 3778 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3779 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3780 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3781 | scoped_ptr<SpdyFrame> conn_resp( |
| 3782 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3783 | scoped_ptr<SpdyFrame> get_resp( |
| 3784 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3785 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3786 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3787 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3788 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3789 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3790 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3791 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3792 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3793 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3794 | |
| 3795 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3796 | CreateMockWrite(*connect, 0), |
| 3797 | CreateMockWrite(*wrapped_get, 2), |
| 3798 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3799 | CreateMockWrite(*window_update_body, 7), |
| 3800 | }; |
| 3801 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3802 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3803 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3804 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3805 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3806 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3807 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3808 | }; |
| 3809 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3810 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3811 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3812 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3813 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3814 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3815 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3816 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3817 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3818 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3819 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3821 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3823 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3825 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3826 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3827 | base::MessageLoop::current()->RunUntilIdle(); |
| 3828 | // Now allow the read of the response to complete. |
| 3829 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3830 | rv = callback1.WaitForResult(); |
| 3831 | EXPECT_EQ(OK, rv); |
| 3832 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3833 | LoadTimingInfo load_timing_info; |
| 3834 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3835 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3836 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3837 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3838 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3839 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3840 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3841 | |
| 3842 | std::string response_data; |
| 3843 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3844 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3848 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3849 | HttpRequestInfo request; |
| 3850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3851 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3852 | request.load_flags = 0; |
| 3853 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3854 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3855 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3856 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3857 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3858 | session_deps_.net_log = log.bound().net_log(); |
| 3859 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3860 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3861 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3863 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3864 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3865 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3866 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3867 | scoped_ptr<SpdyFrame> get( |
| 3868 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3869 | |
| 3870 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3871 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3872 | }; |
| 3873 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3874 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3875 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3876 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3877 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3878 | }; |
| 3879 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3880 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3881 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3882 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3883 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3884 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3885 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3887 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3888 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3891 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3893 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3895 | |
| 3896 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3897 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3898 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3899 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3900 | } |
| 3901 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3902 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3903 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3904 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3905 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3906 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3907 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3908 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3909 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3910 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3911 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3912 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3913 | |
| 3914 | HttpRequestInfo request1; |
| 3915 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3916 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3917 | request1.load_flags = 0; |
| 3918 | |
| 3919 | HttpRequestInfo request2; |
| 3920 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3921 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3922 | request2.load_flags = 0; |
| 3923 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3924 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3925 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3926 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3927 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3928 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3929 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3930 | // Fetch https://www.example.org/ via HTTP. |
| 3931 | const char get1[] = |
| 3932 | "GET / HTTP/1.1\r\n" |
| 3933 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3934 | "Connection: keep-alive\r\n\r\n"; |
| 3935 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3936 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3937 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3938 | "Content-Length: 1\r\n\r\n"; |
| 3939 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3940 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3941 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3942 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3943 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3944 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3945 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3946 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3947 | SpdyHeaderBlock connect2_block; |
| 3948 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3949 | if (GetParam() >= kProtoHTTP2MinimumVersion) { |
| 3950 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 3951 | } else { |
| 3952 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
| 3953 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
| 3954 | } |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3955 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3956 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3957 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3958 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3959 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3960 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3961 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3962 | // Fetch https://mail.example.org/ via HTTP. |
| 3963 | const char get2[] = |
| 3964 | "GET / HTTP/1.1\r\n" |
| 3965 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3966 | "Connection: keep-alive\r\n\r\n"; |
| 3967 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3968 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3969 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3970 | "Content-Length: 2\r\n\r\n"; |
| 3971 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3972 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3973 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3974 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3975 | |
| 3976 | MockWrite spdy_writes[] = { |
| 3977 | CreateMockWrite(*connect1, 0), |
| 3978 | CreateMockWrite(*wrapped_get1, 2), |
| 3979 | CreateMockWrite(*connect2, 5), |
| 3980 | CreateMockWrite(*wrapped_get2, 7), |
| 3981 | }; |
| 3982 | |
| 3983 | MockRead spdy_reads[] = { |
| 3984 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3985 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3986 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3987 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3988 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3989 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3990 | MockRead(ASYNC, 0, 10), |
| 3991 | }; |
| 3992 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3993 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3994 | arraysize(spdy_writes)); |
| 3995 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3996 | |
| 3997 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3998 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3999 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4000 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4002 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4003 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4004 | |
| 4005 | TestCompletionCallback callback; |
| 4006 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4007 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4008 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4009 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4010 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4011 | |
| 4012 | LoadTimingInfo load_timing_info; |
| 4013 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4014 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4015 | |
| 4016 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4017 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4018 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4019 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4020 | |
| 4021 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4022 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4023 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4024 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4025 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4026 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4027 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4028 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4029 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4030 | |
| 4031 | LoadTimingInfo load_timing_info2; |
| 4032 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4033 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4034 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4035 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4036 | |
| 4037 | // The requests should have different IDs, since they each are using their own |
| 4038 | // separate stream. |
| 4039 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4040 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4041 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4042 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4046 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4047 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4048 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4049 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4050 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4051 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4052 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4053 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4054 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4055 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4056 | |
| 4057 | HttpRequestInfo request1; |
| 4058 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4059 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4060 | request1.load_flags = 0; |
| 4061 | |
| 4062 | HttpRequestInfo request2; |
| 4063 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4064 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4065 | request2.load_flags = 0; |
| 4066 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4067 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4068 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4069 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4070 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4071 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4072 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4073 | // Fetch https://www.example.org/ via HTTP. |
| 4074 | const char get1[] = |
| 4075 | "GET / HTTP/1.1\r\n" |
| 4076 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4077 | "Connection: keep-alive\r\n\r\n"; |
| 4078 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4079 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4080 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4081 | "Content-Length: 1\r\n\r\n"; |
| 4082 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4083 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4084 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4085 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4086 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4087 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4088 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4089 | // Fetch https://www.example.org/2 via HTTP. |
| 4090 | const char get2[] = |
| 4091 | "GET /2 HTTP/1.1\r\n" |
| 4092 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4093 | "Connection: keep-alive\r\n\r\n"; |
| 4094 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4095 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4096 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4097 | "Content-Length: 2\r\n\r\n"; |
| 4098 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4099 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4100 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4101 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4102 | |
| 4103 | MockWrite spdy_writes[] = { |
| 4104 | CreateMockWrite(*connect1, 0), |
| 4105 | CreateMockWrite(*wrapped_get1, 2), |
| 4106 | CreateMockWrite(*wrapped_get2, 5), |
| 4107 | }; |
| 4108 | |
| 4109 | MockRead spdy_reads[] = { |
| 4110 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4111 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4112 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4113 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4114 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4115 | MockRead(ASYNC, 0, 8), |
| 4116 | }; |
| 4117 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4118 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4119 | arraysize(spdy_writes)); |
| 4120 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4121 | |
| 4122 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4123 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4125 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4127 | |
| 4128 | TestCompletionCallback callback; |
| 4129 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4130 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4132 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4134 | |
| 4135 | rv = callback.WaitForResult(); |
| 4136 | EXPECT_EQ(OK, rv); |
| 4137 | |
| 4138 | LoadTimingInfo load_timing_info; |
| 4139 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4140 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4141 | |
| 4142 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4143 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4144 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4146 | |
| 4147 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4148 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4149 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4150 | trans.reset(); |
| 4151 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4152 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4153 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4154 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4155 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4156 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4157 | rv = callback.WaitForResult(); |
| 4158 | EXPECT_EQ(OK, rv); |
| 4159 | |
| 4160 | LoadTimingInfo load_timing_info2; |
| 4161 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4162 | TestLoadTimingReused(load_timing_info2); |
| 4163 | |
| 4164 | // The requests should have the same ID. |
| 4165 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4166 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4167 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4171 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4172 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4173 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4174 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4175 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4176 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4177 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4178 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4179 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4180 | |
| 4181 | HttpRequestInfo request1; |
| 4182 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4183 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4184 | request1.load_flags = 0; |
| 4185 | |
| 4186 | HttpRequestInfo request2; |
| 4187 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4188 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4189 | request2.load_flags = 0; |
| 4190 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4191 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4192 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4193 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4194 | scoped_ptr<SpdyFrame> get1( |
| 4195 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4196 | scoped_ptr<SpdyFrame> get_resp1( |
| 4197 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4198 | scoped_ptr<SpdyFrame> body1( |
| 4199 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4200 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4201 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4202 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4203 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4204 | scoped_ptr<SpdyFrame> get2( |
| 4205 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4206 | scoped_ptr<SpdyFrame> get_resp2( |
| 4207 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4208 | scoped_ptr<SpdyFrame> body2( |
| 4209 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4210 | |
| 4211 | MockWrite spdy_writes[] = { |
| 4212 | CreateMockWrite(*get1, 0), |
| 4213 | CreateMockWrite(*get2, 3), |
| 4214 | }; |
| 4215 | |
| 4216 | MockRead spdy_reads[] = { |
| 4217 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4218 | CreateMockRead(*body1, 2, ASYNC), |
| 4219 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4220 | CreateMockRead(*body2, 5, ASYNC), |
| 4221 | MockRead(ASYNC, 0, 6), |
| 4222 | }; |
| 4223 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4224 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4225 | arraysize(spdy_writes)); |
| 4226 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4227 | |
| 4228 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4229 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4230 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4231 | |
| 4232 | TestCompletionCallback callback; |
| 4233 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4234 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4236 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4237 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4238 | |
| 4239 | LoadTimingInfo load_timing_info; |
| 4240 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4241 | TestLoadTimingNotReused(load_timing_info, |
| 4242 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4243 | |
| 4244 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4245 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4246 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4247 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4248 | |
| 4249 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4250 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4251 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4252 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4253 | // Delete the first request, so the second one can reuse the socket. |
| 4254 | trans.reset(); |
| 4255 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4256 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4258 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4259 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4260 | |
| 4261 | LoadTimingInfo load_timing_info2; |
| 4262 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4263 | TestLoadTimingReused(load_timing_info2); |
| 4264 | |
| 4265 | // The requests should have the same ID. |
| 4266 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4267 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4268 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4269 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4270 | } |
| 4271 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4272 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4273 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4274 | HttpRequestInfo request; |
| 4275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4276 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4277 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4278 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4279 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4280 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4281 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4282 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4283 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4284 | session_deps_.net_log = log.bound().net_log(); |
| 4285 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4286 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4287 | // Since we have proxy, should use full url |
| 4288 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4289 | MockWrite( |
| 4290 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4291 | "Host: www.example.org\r\n" |
| 4292 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4293 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4294 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4295 | // be issuing -- the final header line contains the credentials. |
| 4296 | MockWrite( |
| 4297 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4298 | "Host: www.example.org\r\n" |
| 4299 | "Proxy-Connection: keep-alive\r\n" |
| 4300 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4301 | }; |
| 4302 | |
| 4303 | // The proxy responds to the GET with a 407, using a persistent |
| 4304 | // connection. |
| 4305 | MockRead data_reads1[] = { |
| 4306 | // No credentials. |
| 4307 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4308 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4309 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4310 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4311 | |
| 4312 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4313 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4314 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4315 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4316 | }; |
| 4317 | |
| 4318 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4319 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4320 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4321 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4323 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4324 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4325 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4326 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4329 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4330 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4331 | |
| 4332 | rv = callback1.WaitForResult(); |
| 4333 | EXPECT_EQ(OK, rv); |
| 4334 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4335 | LoadTimingInfo load_timing_info; |
| 4336 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4337 | TestLoadTimingNotReused(load_timing_info, |
| 4338 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4339 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4340 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4341 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4342 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4343 | EXPECT_EQ(407, response->headers->response_code()); |
| 4344 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4345 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4347 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4349 | rv = trans->RestartWithAuth( |
| 4350 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4352 | |
| 4353 | rv = callback2.WaitForResult(); |
| 4354 | EXPECT_EQ(OK, rv); |
| 4355 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4356 | load_timing_info = LoadTimingInfo(); |
| 4357 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4358 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4359 | TestLoadTimingReused(load_timing_info); |
| 4360 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4361 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4362 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4363 | |
| 4364 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4365 | EXPECT_EQ(200, response->headers->response_code()); |
| 4366 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4367 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4368 | |
| 4369 | // The password prompt info should not be set. |
| 4370 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4371 | } |
| 4372 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4373 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4374 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4375 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4376 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4377 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4378 | request.load_flags = 0; |
| 4379 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4380 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4381 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4382 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4383 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4384 | // Since we have proxy, should try to establish tunnel. |
| 4385 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4386 | MockWrite( |
| 4387 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4388 | "Host: www.example.org\r\n" |
| 4389 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4390 | }; |
| 4391 | |
| 4392 | MockRead data_reads[] = { |
| 4393 | status, |
| 4394 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4395 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4396 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4397 | }; |
| 4398 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4399 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4400 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4403 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4404 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4405 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4406 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4408 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4410 | |
| 4411 | rv = callback.WaitForResult(); |
| 4412 | EXPECT_EQ(expected_status, rv); |
| 4413 | } |
| 4414 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4415 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4416 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4417 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4418 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4419 | } |
| 4420 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4421 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4422 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4423 | } |
| 4424 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4425 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4426 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4427 | } |
| 4428 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4429 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4430 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4431 | } |
| 4432 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4433 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4434 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4435 | } |
| 4436 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4437 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4438 | ConnectStatusHelper( |
| 4439 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4440 | } |
| 4441 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4442 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4443 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4444 | } |
| 4445 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4446 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4447 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4448 | } |
| 4449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4450 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4451 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4452 | } |
| 4453 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4454 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4455 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4456 | } |
| 4457 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4458 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4459 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4460 | } |
| 4461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4462 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4463 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4464 | } |
| 4465 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4466 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4467 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4468 | } |
| 4469 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4470 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4471 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4472 | } |
| 4473 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4474 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4475 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4476 | } |
| 4477 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4478 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4479 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4480 | } |
| 4481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4482 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4483 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4484 | } |
| 4485 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4486 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4487 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4488 | } |
| 4489 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4490 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4491 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4492 | } |
| 4493 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4494 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4495 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4496 | } |
| 4497 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4498 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4499 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4500 | } |
| 4501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4502 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4503 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4504 | } |
| 4505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4506 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4507 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4508 | } |
| 4509 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4510 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4511 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4512 | } |
| 4513 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4514 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4515 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4516 | } |
| 4517 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4518 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4519 | ConnectStatusHelperWithExpectedStatus( |
| 4520 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4521 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4522 | } |
| 4523 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4524 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4525 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4526 | } |
| 4527 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4528 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4529 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4530 | } |
| 4531 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4532 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4533 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4534 | } |
| 4535 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4536 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4537 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4538 | } |
| 4539 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4540 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4541 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4542 | } |
| 4543 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4544 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4545 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4546 | } |
| 4547 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4548 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4549 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4550 | } |
| 4551 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4552 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4553 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4554 | } |
| 4555 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4556 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4557 | ConnectStatusHelper( |
| 4558 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4559 | } |
| 4560 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4561 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4562 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4563 | } |
| 4564 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4565 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4566 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4567 | } |
| 4568 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4569 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4570 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4571 | } |
| 4572 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4573 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4574 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4575 | } |
| 4576 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4577 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4578 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4579 | } |
| 4580 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4581 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4582 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4583 | } |
| 4584 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4585 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4586 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4587 | } |
| 4588 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4589 | // Test the flow when both the proxy server AND origin server require |
| 4590 | // authentication. Again, this uses basic auth for both since that is |
| 4591 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4592 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4593 | HttpRequestInfo request; |
| 4594 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4595 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4596 | request.load_flags = 0; |
| 4597 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4598 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4599 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4600 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4601 | |
| 4602 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4603 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4604 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4605 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4606 | MockWrite( |
| 4607 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4608 | "Host: www.example.org\r\n" |
| 4609 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4610 | }; |
| 4611 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4612 | MockRead data_reads1[] = { |
| 4613 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4614 | // Give a couple authenticate options (only the middle one is actually |
| 4615 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4616 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4617 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4618 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4619 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4620 | // Large content-length -- won't matter, as connection will be reset. |
| 4621 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4622 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4623 | }; |
| 4624 | |
| 4625 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4626 | // request we should be issuing -- the final header line contains the |
| 4627 | // proxy's credentials. |
| 4628 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4629 | MockWrite( |
| 4630 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4631 | "Host: www.example.org\r\n" |
| 4632 | "Proxy-Connection: keep-alive\r\n" |
| 4633 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4634 | }; |
| 4635 | |
| 4636 | // Now the proxy server lets the request pass through to origin server. |
| 4637 | // The origin server responds with a 401. |
| 4638 | MockRead data_reads2[] = { |
| 4639 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4640 | // Note: We are using the same realm-name as the proxy server. This is |
| 4641 | // completely valid, as realms are unique across hosts. |
| 4642 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4644 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4645 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4646 | }; |
| 4647 | |
| 4648 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4649 | // the credentials for both the proxy and origin server. |
| 4650 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4651 | MockWrite( |
| 4652 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4653 | "Host: www.example.org\r\n" |
| 4654 | "Proxy-Connection: keep-alive\r\n" |
| 4655 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4656 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4657 | }; |
| 4658 | |
| 4659 | // Lastly we get the desired content. |
| 4660 | MockRead data_reads3[] = { |
| 4661 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4662 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4663 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4665 | }; |
| 4666 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4667 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4668 | data_writes1, arraysize(data_writes1)); |
| 4669 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4670 | data_writes2, arraysize(data_writes2)); |
| 4671 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4672 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4673 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4674 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4675 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4677 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4679 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4681 | |
| 4682 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4683 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4684 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4685 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4686 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4687 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4689 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4691 | rv = trans->RestartWithAuth( |
| 4692 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4693 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4694 | |
| 4695 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4696 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4697 | |
| 4698 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4699 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4700 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4702 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4704 | rv = trans->RestartWithAuth( |
| 4705 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4706 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4707 | |
| 4708 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4709 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4710 | |
| 4711 | response = trans->GetResponseInfo(); |
| 4712 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4713 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4714 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4715 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4716 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4717 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4718 | // authorization headers. |
| 4719 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4720 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4721 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4722 | // bytes in the debugger. |
| 4723 | |
| 4724 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4725 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4726 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4727 | request.method = "GET"; |
| 4728 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4729 | |
| 4730 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4731 | // to other auth schemes. |
| 4732 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4733 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4734 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4735 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4736 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4737 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4738 | MockWrite data_writes1[] = { |
| 4739 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4740 | "Host: 172.22.68.17\r\n" |
| 4741 | "Connection: keep-alive\r\n\r\n"), |
| 4742 | }; |
| 4743 | |
| 4744 | MockRead data_reads1[] = { |
| 4745 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4746 | // Negotiate and NTLM are often requested together. However, we only want |
| 4747 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4748 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4749 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4750 | MockRead("Connection: close\r\n"), |
| 4751 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4752 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4753 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4754 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4755 | }; |
| 4756 | |
| 4757 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4758 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4759 | // request we should be issuing -- the final header line contains a Type |
| 4760 | // 1 message. |
| 4761 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4762 | "Host: 172.22.68.17\r\n" |
| 4763 | "Connection: keep-alive\r\n" |
| 4764 | "Authorization: NTLM " |
| 4765 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4766 | |
| 4767 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4768 | // (the credentials for the origin server). The second request continues |
| 4769 | // on the same connection. |
| 4770 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4771 | "Host: 172.22.68.17\r\n" |
| 4772 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4773 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4774 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4775 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4776 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4777 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4778 | }; |
| 4779 | |
| 4780 | MockRead data_reads2[] = { |
| 4781 | // The origin server responds with a Type 2 message. |
| 4782 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4783 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4784 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4785 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4786 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4787 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4788 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4789 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4790 | "BtAAAAAAA=\r\n"), |
| 4791 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4792 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4793 | MockRead("You are not authorized to view this page\r\n"), |
| 4794 | |
| 4795 | // Lastly we get the desired content. |
| 4796 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4797 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4798 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4799 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4801 | }; |
| 4802 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4803 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4804 | data_writes1, arraysize(data_writes1)); |
| 4805 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4806 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4807 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4808 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4810 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4811 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4812 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4813 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4815 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4816 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4817 | |
| 4818 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4819 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4820 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4821 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4822 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4824 | ASSERT_FALSE(response == NULL); |
| 4825 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4827 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4828 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4829 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4830 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4832 | |
| 4833 | rv = callback2.WaitForResult(); |
| 4834 | EXPECT_EQ(OK, rv); |
| 4835 | |
| 4836 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4837 | |
| 4838 | response = trans->GetResponseInfo(); |
| 4839 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4840 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4842 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4844 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4846 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4847 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4848 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4849 | |
| 4850 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4851 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4852 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4853 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4854 | } |
| 4855 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4856 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4857 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4858 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4859 | request.method = "GET"; |
| 4860 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4861 | request.load_flags = 0; |
| 4862 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4863 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4864 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4865 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4866 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4867 | MockWrite data_writes1[] = { |
| 4868 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4869 | "Host: 172.22.68.17\r\n" |
| 4870 | "Connection: keep-alive\r\n\r\n"), |
| 4871 | }; |
| 4872 | |
| 4873 | MockRead data_reads1[] = { |
| 4874 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4875 | // Negotiate and NTLM are often requested together. However, we only want |
| 4876 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4877 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4878 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4879 | MockRead("Connection: close\r\n"), |
| 4880 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4881 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4882 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4883 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4884 | }; |
| 4885 | |
| 4886 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4887 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4888 | // request we should be issuing -- the final header line contains a Type |
| 4889 | // 1 message. |
| 4890 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4891 | "Host: 172.22.68.17\r\n" |
| 4892 | "Connection: keep-alive\r\n" |
| 4893 | "Authorization: NTLM " |
| 4894 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4895 | |
| 4896 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4897 | // (the credentials for the origin server). The second request continues |
| 4898 | // on the same connection. |
| 4899 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4900 | "Host: 172.22.68.17\r\n" |
| 4901 | "Connection: keep-alive\r\n" |
| 4902 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4903 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4904 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4905 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4906 | "4Ww7b7E=\r\n\r\n"), |
| 4907 | }; |
| 4908 | |
| 4909 | MockRead data_reads2[] = { |
| 4910 | // The origin server responds with a Type 2 message. |
| 4911 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4912 | MockRead("WWW-Authenticate: NTLM " |
| 4913 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4914 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4915 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4916 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4917 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4918 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4919 | "BtAAAAAAA=\r\n"), |
| 4920 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4921 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4922 | MockRead("You are not authorized to view this page\r\n"), |
| 4923 | |
| 4924 | // Wrong password. |
| 4925 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4926 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4927 | MockRead("Connection: close\r\n"), |
| 4928 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4929 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4930 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4931 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4932 | }; |
| 4933 | |
| 4934 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4935 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4936 | // request we should be issuing -- the final header line contains a Type |
| 4937 | // 1 message. |
| 4938 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4939 | "Host: 172.22.68.17\r\n" |
| 4940 | "Connection: keep-alive\r\n" |
| 4941 | "Authorization: NTLM " |
| 4942 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4943 | |
| 4944 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4945 | // (the credentials for the origin server). The second request continues |
| 4946 | // on the same connection. |
| 4947 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4948 | "Host: 172.22.68.17\r\n" |
| 4949 | "Connection: keep-alive\r\n" |
| 4950 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4951 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4952 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4953 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4954 | "+4MUm7c=\r\n\r\n"), |
| 4955 | }; |
| 4956 | |
| 4957 | MockRead data_reads3[] = { |
| 4958 | // The origin server responds with a Type 2 message. |
| 4959 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4960 | MockRead("WWW-Authenticate: NTLM " |
| 4961 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4962 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4963 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4964 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4965 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4966 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4967 | "BtAAAAAAA=\r\n"), |
| 4968 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4969 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4970 | MockRead("You are not authorized to view this page\r\n"), |
| 4971 | |
| 4972 | // Lastly we get the desired content. |
| 4973 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4974 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4975 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4976 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4978 | }; |
| 4979 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4980 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4981 | data_writes1, arraysize(data_writes1)); |
| 4982 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4983 | data_writes2, arraysize(data_writes2)); |
| 4984 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4985 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4986 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4987 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4988 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4990 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4991 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4995 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4996 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4997 | |
| 4998 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4999 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5000 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5001 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5002 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5003 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5004 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5005 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5007 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5008 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5009 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5010 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5011 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5012 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5013 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5014 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5015 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5016 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5017 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5018 | TestCompletionCallback callback3; |
| 5019 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5020 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5021 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5022 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5023 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5024 | |
| 5025 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5026 | ASSERT_FALSE(response == NULL); |
| 5027 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5029 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5030 | |
| 5031 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5032 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5033 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5034 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5035 | |
| 5036 | rv = callback4.WaitForResult(); |
| 5037 | EXPECT_EQ(OK, rv); |
| 5038 | |
| 5039 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5041 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5042 | |
| 5043 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5044 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5046 | |
| 5047 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5048 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5049 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5050 | response = trans->GetResponseInfo(); |
| 5051 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5052 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5053 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5054 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5055 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5056 | // Test reading a server response which has only headers, and no body. |
| 5057 | // After some maximum number of bytes is consumed, the transaction should |
| 5058 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5059 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5060 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5061 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5062 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5063 | request.load_flags = 0; |
| 5064 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5065 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5066 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5068 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5069 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5070 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5071 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5072 | |
| 5073 | MockRead data_reads[] = { |
| 5074 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5075 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5076 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5077 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5078 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5079 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5080 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5082 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5084 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5085 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5086 | |
| 5087 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5088 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5089 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5090 | |
| 5091 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5092 | // establish tunnel. |
| 5093 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5094 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5095 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5096 | HttpRequestInfo request; |
| 5097 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5098 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5099 | request.load_flags = 0; |
| 5100 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5101 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5102 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5103 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5104 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5105 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5106 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5107 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5108 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5109 | // Since we have proxy, should try to establish tunnel. |
| 5110 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5111 | MockWrite( |
| 5112 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5113 | "Host: www.example.org\r\n" |
| 5114 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5115 | }; |
| 5116 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5117 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5118 | // connection. Usually a proxy would return 501 (not implemented), |
| 5119 | // or 200 (tunnel established). |
| 5120 | MockRead data_reads1[] = { |
| 5121 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5122 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5123 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5124 | }; |
| 5125 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5126 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5127 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5128 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5130 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5132 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5134 | |
| 5135 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5136 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5137 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5138 | // Empty the current queue. This is necessary because idle sockets are |
| 5139 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5140 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5141 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5142 | // We now check to make sure the TCPClientSocket was not added back to |
| 5143 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5144 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5145 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5146 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5147 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5148 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5149 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5150 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5151 | // 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] | 5152 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5153 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5154 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5155 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5156 | request.load_flags = 0; |
| 5157 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5158 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5159 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5160 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5161 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5162 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5163 | MockRead data_reads[] = { |
| 5164 | // A part of the response body is received with the response headers. |
| 5165 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5166 | // The rest of the response body is received in two parts. |
| 5167 | MockRead("lo"), |
| 5168 | MockRead(" world"), |
| 5169 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5170 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5171 | }; |
| 5172 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5176 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5178 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5180 | |
| 5181 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5182 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5183 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5184 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5185 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5186 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5187 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5188 | std::string status_line = response->headers->GetStatusLine(); |
| 5189 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5190 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5191 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5192 | |
| 5193 | std::string response_data; |
| 5194 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5195 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5196 | EXPECT_EQ("hello world", response_data); |
| 5197 | |
| 5198 | // Empty the current queue. This is necessary because idle sockets are |
| 5199 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5200 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5201 | |
| 5202 | // 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] | 5203 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5204 | } |
| 5205 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5206 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5207 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5208 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5209 | HttpRequestInfo request; |
| 5210 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5211 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5212 | request.load_flags = 0; |
| 5213 | |
| 5214 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5215 | MockWrite( |
| 5216 | "GET / HTTP/1.1\r\n" |
| 5217 | "Host: www.example.org\r\n" |
| 5218 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5219 | }; |
| 5220 | |
| 5221 | MockRead data_reads[] = { |
| 5222 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5223 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5224 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5226 | }; |
| 5227 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5228 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5230 | |
| 5231 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5232 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5235 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5236 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5237 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5238 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5241 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5242 | |
| 5243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5244 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5245 | |
| 5246 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5247 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5248 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5249 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5250 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5251 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5252 | |
| 5253 | std::string response_data; |
| 5254 | rv = ReadTransaction(trans.get(), &response_data); |
| 5255 | EXPECT_EQ(OK, rv); |
| 5256 | EXPECT_EQ("hello world", response_data); |
| 5257 | |
| 5258 | // Empty the current queue. This is necessary because idle sockets are |
| 5259 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5260 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5261 | |
| 5262 | // 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] | 5263 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5264 | } |
| 5265 | |
| 5266 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5267 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5268 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5269 | HttpRequestInfo request; |
| 5270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5271 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5272 | request.load_flags = 0; |
| 5273 | |
| 5274 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5275 | MockWrite( |
| 5276 | "GET / HTTP/1.1\r\n" |
| 5277 | "Host: www.example.org\r\n" |
| 5278 | "Connection: keep-alive\r\n\r\n"), |
| 5279 | MockWrite( |
| 5280 | "GET / HTTP/1.1\r\n" |
| 5281 | "Host: www.example.org\r\n" |
| 5282 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5283 | }; |
| 5284 | |
| 5285 | MockRead data_reads[] = { |
| 5286 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5287 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5288 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5289 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5290 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5291 | }; |
| 5292 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5293 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5294 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5297 | |
| 5298 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5299 | data_writes, arraysize(data_writes)); |
| 5300 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5301 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5302 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5303 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5305 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5306 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5307 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5308 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5309 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5311 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5312 | |
| 5313 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5314 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5315 | |
| 5316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5317 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5318 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5319 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5320 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5321 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5322 | |
| 5323 | std::string response_data; |
| 5324 | rv = ReadTransaction(trans.get(), &response_data); |
| 5325 | EXPECT_EQ(OK, rv); |
| 5326 | EXPECT_EQ("hello world", response_data); |
| 5327 | |
| 5328 | // Empty the current queue. This is necessary because idle sockets are |
| 5329 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5330 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5331 | |
| 5332 | // 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] | 5333 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5334 | |
| 5335 | // Now start the second transaction, which should reuse the previous socket. |
| 5336 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5337 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5339 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5340 | |
| 5341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5342 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5343 | |
| 5344 | response = trans->GetResponseInfo(); |
| 5345 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5346 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5347 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5348 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5349 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5350 | |
| 5351 | rv = ReadTransaction(trans.get(), &response_data); |
| 5352 | EXPECT_EQ(OK, rv); |
| 5353 | EXPECT_EQ("hello world", response_data); |
| 5354 | |
| 5355 | // Empty the current queue. This is necessary because idle sockets are |
| 5356 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5357 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5358 | |
| 5359 | // 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] | 5360 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5361 | } |
| 5362 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5363 | // Make sure that we recycle a socket after a zero-length response. |
| 5364 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5365 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5366 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5367 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5368 | request.url = GURL( |
| 5369 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5370 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5371 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5372 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5373 | request.load_flags = 0; |
| 5374 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5375 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5376 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5377 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5379 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5380 | MockRead data_reads[] = { |
| 5381 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5382 | "Content-Length: 0\r\n" |
| 5383 | "Content-Type: text/html\r\n\r\n"), |
| 5384 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5386 | }; |
| 5387 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5388 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5391 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5393 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5395 | |
| 5396 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5397 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5398 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5399 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5400 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5401 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5402 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5403 | std::string status_line = response->headers->GetStatusLine(); |
| 5404 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5405 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5406 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5407 | |
| 5408 | std::string response_data; |
| 5409 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5410 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5411 | EXPECT_EQ("", response_data); |
| 5412 | |
| 5413 | // Empty the current queue. This is necessary because idle sockets are |
| 5414 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5415 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5416 | |
| 5417 | // 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] | 5418 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5419 | } |
| 5420 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5421 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5422 | ScopedVector<UploadElementReader> element_readers; |
| 5423 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5424 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5425 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5426 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5427 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5428 | // after use. |
| 5429 | request[0].method = "GET"; |
| 5430 | request[0].url = GURL("http://www.google.com/"); |
| 5431 | request[0].load_flags = 0; |
| 5432 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5433 | // transaction 1. The first attempts fails when writing the POST data. |
| 5434 | // This causes the transaction to retry with a new socket. The second |
| 5435 | // attempt succeeds. |
| 5436 | request[1].method = "POST"; |
| 5437 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5438 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5439 | request[1].load_flags = 0; |
| 5440 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5441 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5442 | |
| 5443 | // The first socket is used for transaction 1 and the first attempt of |
| 5444 | // transaction 2. |
| 5445 | |
| 5446 | // The response of transaction 1. |
| 5447 | MockRead data_reads1[] = { |
| 5448 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5449 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5451 | }; |
| 5452 | // The mock write results of transaction 1 and the first attempt of |
| 5453 | // transaction 2. |
| 5454 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5455 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5456 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5457 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5458 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5459 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5460 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5461 | |
| 5462 | // The second socket is used for the second attempt of transaction 2. |
| 5463 | |
| 5464 | // The response of transaction 2. |
| 5465 | MockRead data_reads2[] = { |
| 5466 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5467 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5468 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5469 | }; |
| 5470 | // The mock write results of the second attempt of transaction 2. |
| 5471 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5472 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5473 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5474 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5475 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5476 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5477 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5478 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5479 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5480 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5481 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5482 | "hello world", "welcome" |
| 5483 | }; |
| 5484 | |
| 5485 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5486 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5487 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5489 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5491 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5493 | |
| 5494 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5495 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5496 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5498 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5499 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5500 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5501 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5502 | |
| 5503 | std::string response_data; |
| 5504 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5505 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5506 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5507 | } |
| 5508 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5509 | |
| 5510 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5511 | // 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] | 5512 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5513 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5514 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5515 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5516 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5517 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5518 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5519 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5520 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5521 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5522 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5523 | // The password contains an escaped character -- for this test to pass it |
| 5524 | // will need to be unescaped by HttpNetworkTransaction. |
| 5525 | EXPECT_EQ("b%40r", request.url.password()); |
| 5526 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5527 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5528 | MockWrite( |
| 5529 | "GET / HTTP/1.1\r\n" |
| 5530 | "Host: www.example.org\r\n" |
| 5531 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5532 | }; |
| 5533 | |
| 5534 | MockRead data_reads1[] = { |
| 5535 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5536 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5537 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5538 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5539 | }; |
| 5540 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5541 | // After the challenge above, the transaction will be restarted using the |
| 5542 | // identity from the url (foo, b@r) to answer the challenge. |
| 5543 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5544 | MockWrite( |
| 5545 | "GET / HTTP/1.1\r\n" |
| 5546 | "Host: www.example.org\r\n" |
| 5547 | "Connection: keep-alive\r\n" |
| 5548 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5549 | }; |
| 5550 | |
| 5551 | MockRead data_reads2[] = { |
| 5552 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5553 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5554 | MockRead(SYNCHRONOUS, OK), |
| 5555 | }; |
| 5556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5558 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5559 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5560 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5561 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5562 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5564 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5565 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5566 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5567 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5568 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5569 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5570 | |
| 5571 | TestCompletionCallback callback2; |
| 5572 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5574 | rv = callback2.WaitForResult(); |
| 5575 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5576 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5577 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5578 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5579 | ASSERT_TRUE(response != NULL); |
| 5580 | |
| 5581 | // There is no challenge info, since the identity in URL worked. |
| 5582 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5583 | |
| 5584 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5585 | |
| 5586 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5587 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5591 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5592 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5593 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5594 | HttpRequestInfo request; |
| 5595 | request.method = "GET"; |
| 5596 | // Note: the URL has a username:password in it. The password "baz" is |
| 5597 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5598 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5599 | |
| 5600 | request.load_flags = LOAD_NORMAL; |
| 5601 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5602 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5603 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5604 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5605 | |
| 5606 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5607 | MockWrite( |
| 5608 | "GET / HTTP/1.1\r\n" |
| 5609 | "Host: www.example.org\r\n" |
| 5610 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5611 | }; |
| 5612 | |
| 5613 | MockRead data_reads1[] = { |
| 5614 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5615 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5616 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5617 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5618 | }; |
| 5619 | |
| 5620 | // After the challenge above, the transaction will be restarted using the |
| 5621 | // identity from the url (foo, baz) to answer the challenge. |
| 5622 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5623 | MockWrite( |
| 5624 | "GET / HTTP/1.1\r\n" |
| 5625 | "Host: www.example.org\r\n" |
| 5626 | "Connection: keep-alive\r\n" |
| 5627 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5628 | }; |
| 5629 | |
| 5630 | MockRead data_reads2[] = { |
| 5631 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5632 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5633 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5634 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5635 | }; |
| 5636 | |
| 5637 | // After the challenge above, the transaction will be restarted using the |
| 5638 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5639 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5640 | MockWrite( |
| 5641 | "GET / HTTP/1.1\r\n" |
| 5642 | "Host: www.example.org\r\n" |
| 5643 | "Connection: keep-alive\r\n" |
| 5644 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5645 | }; |
| 5646 | |
| 5647 | MockRead data_reads3[] = { |
| 5648 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5649 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5650 | MockRead(SYNCHRONOUS, OK), |
| 5651 | }; |
| 5652 | |
| 5653 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5654 | data_writes1, arraysize(data_writes1)); |
| 5655 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5656 | data_writes2, arraysize(data_writes2)); |
| 5657 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5658 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5659 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5660 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5661 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5662 | |
| 5663 | TestCompletionCallback callback1; |
| 5664 | |
| 5665 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5666 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5667 | |
| 5668 | rv = callback1.WaitForResult(); |
| 5669 | EXPECT_EQ(OK, rv); |
| 5670 | |
| 5671 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5672 | TestCompletionCallback callback2; |
| 5673 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5675 | rv = callback2.WaitForResult(); |
| 5676 | EXPECT_EQ(OK, rv); |
| 5677 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5678 | |
| 5679 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5680 | ASSERT_TRUE(response != NULL); |
| 5681 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5682 | |
| 5683 | TestCompletionCallback callback3; |
| 5684 | rv = trans->RestartWithAuth( |
| 5685 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5687 | rv = callback3.WaitForResult(); |
| 5688 | EXPECT_EQ(OK, rv); |
| 5689 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5690 | |
| 5691 | response = trans->GetResponseInfo(); |
| 5692 | ASSERT_TRUE(response != NULL); |
| 5693 | |
| 5694 | // There is no challenge info, since the identity worked. |
| 5695 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5696 | |
| 5697 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5698 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5699 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5700 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5701 | } |
| 5702 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5703 | |
| 5704 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5705 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5706 | // from the URL should never be used. |
| 5707 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5708 | HttpRequestInfo request; |
| 5709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5710 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5711 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5712 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5713 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5714 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5715 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5716 | |
| 5717 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5718 | MockWrite( |
| 5719 | "GET / HTTP/1.1\r\n" |
| 5720 | "Host: www.example.org\r\n" |
| 5721 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5722 | }; |
| 5723 | |
| 5724 | MockRead data_reads1[] = { |
| 5725 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5726 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5727 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5728 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5729 | }; |
| 5730 | |
| 5731 | // After the challenge above, the transaction will be restarted using the |
| 5732 | // identity supplied by the user, not the one in the URL, to answer the |
| 5733 | // challenge. |
| 5734 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5735 | MockWrite( |
| 5736 | "GET / HTTP/1.1\r\n" |
| 5737 | "Host: www.example.org\r\n" |
| 5738 | "Connection: keep-alive\r\n" |
| 5739 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5740 | }; |
| 5741 | |
| 5742 | MockRead data_reads3[] = { |
| 5743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5744 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5745 | MockRead(SYNCHRONOUS, OK), |
| 5746 | }; |
| 5747 | |
| 5748 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5749 | data_writes1, arraysize(data_writes1)); |
| 5750 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5751 | data_writes3, arraysize(data_writes3)); |
| 5752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5753 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5754 | |
| 5755 | TestCompletionCallback callback1; |
| 5756 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5757 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5758 | rv = callback1.WaitForResult(); |
| 5759 | EXPECT_EQ(OK, rv); |
| 5760 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5761 | |
| 5762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5763 | ASSERT_TRUE(response != NULL); |
| 5764 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5765 | |
| 5766 | TestCompletionCallback callback3; |
| 5767 | rv = trans->RestartWithAuth( |
| 5768 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5770 | rv = callback3.WaitForResult(); |
| 5771 | EXPECT_EQ(OK, rv); |
| 5772 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5773 | |
| 5774 | response = trans->GetResponseInfo(); |
| 5775 | ASSERT_TRUE(response != NULL); |
| 5776 | |
| 5777 | // There is no challenge info, since the identity worked. |
| 5778 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5779 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5780 | |
| 5781 | // Empty the current queue. |
| 5782 | base::MessageLoop::current()->RunUntilIdle(); |
| 5783 | } |
| 5784 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5785 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5786 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5787 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5788 | |
| 5789 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5790 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5791 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5793 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5794 | request.load_flags = 0; |
| 5795 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5796 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5797 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5798 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5799 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5800 | MockWrite( |
| 5801 | "GET /x/y/z HTTP/1.1\r\n" |
| 5802 | "Host: www.example.org\r\n" |
| 5803 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5804 | }; |
| 5805 | |
| 5806 | MockRead data_reads1[] = { |
| 5807 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5808 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5809 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5810 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5811 | }; |
| 5812 | |
| 5813 | // Resend with authorization (username=foo, password=bar) |
| 5814 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5815 | MockWrite( |
| 5816 | "GET /x/y/z HTTP/1.1\r\n" |
| 5817 | "Host: www.example.org\r\n" |
| 5818 | "Connection: keep-alive\r\n" |
| 5819 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5820 | }; |
| 5821 | |
| 5822 | // Sever accepts the authorization. |
| 5823 | MockRead data_reads2[] = { |
| 5824 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5825 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5826 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5827 | }; |
| 5828 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5829 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5830 | data_writes1, arraysize(data_writes1)); |
| 5831 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5832 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5834 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5836 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5838 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5839 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5840 | |
| 5841 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5843 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5844 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5845 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5846 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5848 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5850 | rv = trans->RestartWithAuth( |
| 5851 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5853 | |
| 5854 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5855 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5856 | |
| 5857 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5858 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5859 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5860 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5861 | } |
| 5862 | |
| 5863 | // ------------------------------------------------------------------------ |
| 5864 | |
| 5865 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5866 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5867 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5868 | request.method = "GET"; |
| 5869 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5870 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5871 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5872 | request.load_flags = 0; |
| 5873 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5874 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5875 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5876 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5877 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5878 | MockWrite( |
| 5879 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5880 | "Host: www.example.org\r\n" |
| 5881 | "Connection: keep-alive\r\n" |
| 5882 | // Send preemptive authorization for MyRealm1 |
| 5883 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5884 | }; |
| 5885 | |
| 5886 | // The server didn't like the preemptive authorization, and |
| 5887 | // challenges us for a different realm (MyRealm2). |
| 5888 | MockRead data_reads1[] = { |
| 5889 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5890 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5891 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5892 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5893 | }; |
| 5894 | |
| 5895 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5896 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5897 | MockWrite( |
| 5898 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5899 | "Host: www.example.org\r\n" |
| 5900 | "Connection: keep-alive\r\n" |
| 5901 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5902 | }; |
| 5903 | |
| 5904 | // Sever accepts the authorization. |
| 5905 | MockRead data_reads2[] = { |
| 5906 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5907 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5908 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5909 | }; |
| 5910 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5911 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5912 | data_writes1, arraysize(data_writes1)); |
| 5913 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5914 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5915 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5916 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5918 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5920 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5922 | |
| 5923 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5924 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5925 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5926 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5927 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5928 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5929 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5930 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5931 | response->auth_challenge->challenger.ToString()); |
| 5932 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5933 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5935 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5937 | rv = trans->RestartWithAuth( |
| 5938 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5939 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5940 | |
| 5941 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5942 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5943 | |
| 5944 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5945 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5946 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5947 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5948 | } |
| 5949 | |
| 5950 | // ------------------------------------------------------------------------ |
| 5951 | |
| 5952 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5953 | // succeed with preemptive authorization. |
| 5954 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5955 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5956 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5957 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5958 | request.load_flags = 0; |
| 5959 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5960 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5962 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5963 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5964 | MockWrite( |
| 5965 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 5966 | "Host: www.example.org\r\n" |
| 5967 | "Connection: keep-alive\r\n" |
| 5968 | // The authorization for MyRealm1 gets sent preemptively |
| 5969 | // (since the url is in the same protection space) |
| 5970 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5971 | }; |
| 5972 | |
| 5973 | // Sever accepts the preemptive authorization |
| 5974 | MockRead data_reads1[] = { |
| 5975 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5976 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5978 | }; |
| 5979 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5980 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5981 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5982 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5984 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5986 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5987 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5988 | |
| 5989 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5990 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5991 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5992 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5993 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5994 | |
| 5995 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5996 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5997 | } |
| 5998 | |
| 5999 | // ------------------------------------------------------------------------ |
| 6000 | |
| 6001 | // Transaction 4: request another URL in MyRealm (however the |
| 6002 | // url is not known to belong to the protection space, so no pre-auth). |
| 6003 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6004 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6005 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6006 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6007 | request.load_flags = 0; |
| 6008 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6009 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6010 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6011 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6012 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6013 | MockWrite( |
| 6014 | "GET /x/1 HTTP/1.1\r\n" |
| 6015 | "Host: www.example.org\r\n" |
| 6016 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6017 | }; |
| 6018 | |
| 6019 | MockRead data_reads1[] = { |
| 6020 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6021 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6022 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6023 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6024 | }; |
| 6025 | |
| 6026 | // Resend with authorization from MyRealm's cache. |
| 6027 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6028 | MockWrite( |
| 6029 | "GET /x/1 HTTP/1.1\r\n" |
| 6030 | "Host: www.example.org\r\n" |
| 6031 | "Connection: keep-alive\r\n" |
| 6032 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6033 | }; |
| 6034 | |
| 6035 | // Sever accepts the authorization. |
| 6036 | MockRead data_reads2[] = { |
| 6037 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6038 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6039 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6040 | }; |
| 6041 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6042 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6043 | data_writes1, arraysize(data_writes1)); |
| 6044 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6045 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6046 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6047 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6049 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6053 | |
| 6054 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6055 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6056 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6057 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6058 | TestCompletionCallback callback2; |
| 6059 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6061 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6062 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6063 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6064 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6065 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6066 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6067 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6068 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6069 | } |
| 6070 | |
| 6071 | // ------------------------------------------------------------------------ |
| 6072 | |
| 6073 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6074 | // cached identity. Should invalidate and re-prompt. |
| 6075 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6076 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6077 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6078 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6079 | request.load_flags = 0; |
| 6080 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6081 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6082 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6083 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6084 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6085 | MockWrite( |
| 6086 | "GET /p/q/t HTTP/1.1\r\n" |
| 6087 | "Host: www.example.org\r\n" |
| 6088 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6089 | }; |
| 6090 | |
| 6091 | MockRead data_reads1[] = { |
| 6092 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6093 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6094 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6095 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6096 | }; |
| 6097 | |
| 6098 | // Resend with authorization from cache for MyRealm. |
| 6099 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6100 | MockWrite( |
| 6101 | "GET /p/q/t HTTP/1.1\r\n" |
| 6102 | "Host: www.example.org\r\n" |
| 6103 | "Connection: keep-alive\r\n" |
| 6104 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6105 | }; |
| 6106 | |
| 6107 | // Sever rejects the authorization. |
| 6108 | MockRead data_reads2[] = { |
| 6109 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6110 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6111 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6112 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6113 | }; |
| 6114 | |
| 6115 | // At this point we should prompt for new credentials for MyRealm. |
| 6116 | // Restart with username=foo3, password=foo4. |
| 6117 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6118 | MockWrite( |
| 6119 | "GET /p/q/t HTTP/1.1\r\n" |
| 6120 | "Host: www.example.org\r\n" |
| 6121 | "Connection: keep-alive\r\n" |
| 6122 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6123 | }; |
| 6124 | |
| 6125 | // Sever accepts the authorization. |
| 6126 | MockRead data_reads3[] = { |
| 6127 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6128 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6129 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6130 | }; |
| 6131 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6132 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6133 | data_writes1, arraysize(data_writes1)); |
| 6134 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6135 | data_writes2, arraysize(data_writes2)); |
| 6136 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6137 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6139 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6140 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6142 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6144 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6145 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6146 | |
| 6147 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6148 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6149 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6150 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6151 | TestCompletionCallback callback2; |
| 6152 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6154 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6155 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6156 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6157 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6158 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6159 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6160 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6162 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6164 | rv = trans->RestartWithAuth( |
| 6165 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[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 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6168 | rv = callback3.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 | |
| 6171 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6172 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6173 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6174 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6175 | } |
| 6176 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6177 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6178 | // Tests that nonce count increments when multiple auth attempts |
| 6179 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6180 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6181 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6182 | new HttpAuthHandlerDigest::Factory(); |
| 6183 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6184 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6185 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6186 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6187 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6188 | |
| 6189 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6190 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6191 | HttpRequestInfo request; |
| 6192 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6193 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6194 | request.load_flags = 0; |
| 6195 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6196 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6197 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6198 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6199 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | MockWrite( |
| 6201 | "GET /x/y/z HTTP/1.1\r\n" |
| 6202 | "Host: www.example.org\r\n" |
| 6203 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6204 | }; |
| 6205 | |
| 6206 | MockRead data_reads1[] = { |
| 6207 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6208 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6209 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6210 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6211 | }; |
| 6212 | |
| 6213 | // Resend with authorization (username=foo, password=bar) |
| 6214 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6215 | MockWrite( |
| 6216 | "GET /x/y/z HTTP/1.1\r\n" |
| 6217 | "Host: www.example.org\r\n" |
| 6218 | "Connection: keep-alive\r\n" |
| 6219 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6220 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6221 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6222 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6223 | }; |
| 6224 | |
| 6225 | // Sever accepts the authorization. |
| 6226 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6227 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6228 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6229 | }; |
| 6230 | |
| 6231 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6232 | data_writes1, arraysize(data_writes1)); |
| 6233 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6234 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6235 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6236 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6238 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6240 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6242 | |
| 6243 | rv = callback1.WaitForResult(); |
| 6244 | EXPECT_EQ(OK, rv); |
| 6245 | |
| 6246 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6247 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6248 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6250 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | rv = trans->RestartWithAuth( |
| 6253 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6255 | |
| 6256 | rv = callback2.WaitForResult(); |
| 6257 | EXPECT_EQ(OK, rv); |
| 6258 | |
| 6259 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6260 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6261 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6262 | } |
| 6263 | |
| 6264 | // ------------------------------------------------------------------------ |
| 6265 | |
| 6266 | // Transaction 2: Request another resource in digestive's protection space. |
| 6267 | // This will preemptively add an Authorization header which should have an |
| 6268 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6269 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6270 | HttpRequestInfo request; |
| 6271 | request.method = "GET"; |
| 6272 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6273 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6274 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6275 | request.load_flags = 0; |
| 6276 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6277 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6279 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6280 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6281 | MockWrite( |
| 6282 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6283 | "Host: www.example.org\r\n" |
| 6284 | "Connection: keep-alive\r\n" |
| 6285 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6286 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6287 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6288 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6289 | }; |
| 6290 | |
| 6291 | // Sever accepts the authorization. |
| 6292 | MockRead data_reads1[] = { |
| 6293 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6294 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6295 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6296 | }; |
| 6297 | |
| 6298 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6299 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6300 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6302 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6304 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6306 | |
| 6307 | rv = callback1.WaitForResult(); |
| 6308 | EXPECT_EQ(OK, rv); |
| 6309 | |
| 6310 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6311 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6312 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6313 | } |
| 6314 | } |
| 6315 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6316 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6317 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6318 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6319 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6320 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6321 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6322 | |
| 6323 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6324 | trans->read_buf_ = new IOBuffer(15); |
| 6325 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6326 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6327 | |
| 6328 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6329 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6330 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6331 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6332 | response->response_time = base::Time::Now(); |
| 6333 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6334 | |
| 6335 | { // Setup state for response_.vary_data |
| 6336 | HttpRequestInfo request; |
| 6337 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6338 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6339 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6340 | request.extra_headers.SetHeader("Foo", "1"); |
| 6341 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6342 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | // Cause the above state to be reset. |
| 6346 | trans->ResetStateForRestart(); |
| 6347 | |
| 6348 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6349 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6350 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6351 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6352 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6353 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6354 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6355 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6356 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6357 | } |
| 6358 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6359 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6360 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6361 | HttpRequestInfo request; |
| 6362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6363 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6364 | request.load_flags = 0; |
| 6365 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6366 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6367 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6368 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6369 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6370 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6371 | MockWrite( |
| 6372 | "GET / HTTP/1.1\r\n" |
| 6373 | "Host: www.example.org\r\n" |
| 6374 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6375 | }; |
| 6376 | |
| 6377 | MockRead data_reads[] = { |
| 6378 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6379 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6380 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6381 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6382 | }; |
| 6383 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6384 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6385 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6386 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6387 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6388 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6389 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6390 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6391 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6395 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6397 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6398 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6399 | |
| 6400 | rv = callback.WaitForResult(); |
| 6401 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6403 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6404 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6405 | |
| 6406 | rv = callback.WaitForResult(); |
| 6407 | EXPECT_EQ(OK, rv); |
| 6408 | |
| 6409 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6410 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6411 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6412 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6413 | } |
| 6414 | |
| 6415 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6416 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6417 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6418 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6419 | |
| 6420 | HttpRequestInfo request; |
| 6421 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6422 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6423 | request.load_flags = 0; |
| 6424 | |
| 6425 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6426 | MockWrite( |
| 6427 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6428 | "Host: www.example.org\r\n" |
| 6429 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6430 | }; |
| 6431 | |
| 6432 | MockRead proxy_reads[] = { |
| 6433 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6434 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6435 | }; |
| 6436 | |
| 6437 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6438 | MockWrite( |
| 6439 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6440 | "Host: www.example.org\r\n" |
| 6441 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6442 | MockWrite( |
| 6443 | "GET / HTTP/1.1\r\n" |
| 6444 | "Host: www.example.org\r\n" |
| 6445 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6446 | }; |
| 6447 | |
| 6448 | MockRead data_reads[] = { |
| 6449 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6450 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6451 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6452 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6453 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6454 | }; |
| 6455 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6456 | StaticSocketDataProvider ssl_bad_certificate( |
| 6457 | proxy_reads, arraysize(proxy_reads), |
| 6458 | proxy_writes, arraysize(proxy_writes)); |
| 6459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6460 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6461 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6462 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6463 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6464 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6469 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6470 | |
| 6471 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6472 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6473 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6474 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6475 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6478 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6479 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6480 | |
| 6481 | rv = callback.WaitForResult(); |
| 6482 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6484 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6486 | |
| 6487 | rv = callback.WaitForResult(); |
| 6488 | EXPECT_EQ(OK, rv); |
| 6489 | |
| 6490 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6491 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6492 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6493 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6494 | } |
| 6495 | } |
| 6496 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6497 | |
| 6498 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6499 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6500 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6501 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6502 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6503 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6504 | |
| 6505 | HttpRequestInfo request; |
| 6506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6507 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6508 | request.load_flags = 0; |
| 6509 | |
| 6510 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6511 | MockWrite( |
| 6512 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6513 | "Host: www.example.org\r\n" |
| 6514 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6515 | MockWrite( |
| 6516 | "GET / HTTP/1.1\r\n" |
| 6517 | "Host: www.example.org\r\n" |
| 6518 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6519 | }; |
| 6520 | |
| 6521 | MockRead data_reads[] = { |
| 6522 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6523 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6527 | }; |
| 6528 | |
| 6529 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6530 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6531 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6532 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6533 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6537 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6538 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6539 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6540 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6541 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6544 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6545 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6546 | |
| 6547 | rv = callback.WaitForResult(); |
| 6548 | EXPECT_EQ(OK, rv); |
| 6549 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6550 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6551 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6552 | |
| 6553 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6554 | EXPECT_EQ(200, response->headers->response_code()); |
| 6555 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6556 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6557 | |
| 6558 | LoadTimingInfo load_timing_info; |
| 6559 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6560 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6561 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6562 | } |
| 6563 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6564 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6565 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6566 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6567 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6568 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6569 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6570 | |
| 6571 | HttpRequestInfo request; |
| 6572 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6573 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6574 | request.load_flags = 0; |
| 6575 | |
| 6576 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6577 | MockWrite( |
| 6578 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6579 | "Host: www.example.org\r\n" |
| 6580 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6581 | }; |
| 6582 | |
| 6583 | MockRead data_reads[] = { |
| 6584 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6585 | MockRead("Location: http://login.example.com/\r\n"), |
| 6586 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6587 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6588 | }; |
| 6589 | |
| 6590 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6591 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6592 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6593 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6597 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6598 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6599 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6600 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6601 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6603 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6605 | |
| 6606 | rv = callback.WaitForResult(); |
| 6607 | EXPECT_EQ(OK, rv); |
| 6608 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6609 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6610 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6611 | |
| 6612 | EXPECT_EQ(302, response->headers->response_code()); |
| 6613 | std::string url; |
| 6614 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6615 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6616 | |
| 6617 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6618 | // timing for the proxy connection instead of the connection to the host, |
| 6619 | // and no send / receive times. |
| 6620 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6621 | LoadTimingInfo load_timing_info; |
| 6622 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6623 | |
| 6624 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6625 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6626 | |
| 6627 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6628 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6629 | load_timing_info.proxy_resolve_end); |
| 6630 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6631 | load_timing_info.connect_timing.connect_start); |
| 6632 | ExpectConnectTimingHasTimes( |
| 6633 | load_timing_info.connect_timing, |
| 6634 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6635 | |
| 6636 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6637 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6638 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6642 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6643 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6644 | ProxyService::CreateFixed("https://proxy:70")); |
| 6645 | |
| 6646 | HttpRequestInfo request; |
| 6647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6648 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6649 | request.load_flags = 0; |
| 6650 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6651 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6652 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6653 | scoped_ptr<SpdyFrame> goaway( |
| 6654 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6655 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6656 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6657 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6658 | }; |
| 6659 | |
| 6660 | static const char* const kExtraHeaders[] = { |
| 6661 | "location", |
| 6662 | "http://login.example.com/", |
| 6663 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6664 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6665 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6666 | arraysize(kExtraHeaders)/2, 1)); |
| 6667 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6668 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6669 | }; |
| 6670 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6671 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6672 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6673 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6674 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6675 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6676 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6679 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6681 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6682 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6683 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6685 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6687 | |
| 6688 | rv = callback.WaitForResult(); |
| 6689 | EXPECT_EQ(OK, rv); |
| 6690 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6691 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6692 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6693 | |
| 6694 | EXPECT_EQ(302, response->headers->response_code()); |
| 6695 | std::string url; |
| 6696 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6697 | EXPECT_EQ("http://login.example.com/", url); |
| 6698 | } |
| 6699 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6700 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6701 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6702 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6703 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6704 | ProxyService::CreateFixed("https://proxy:70")); |
| 6705 | |
| 6706 | HttpRequestInfo request; |
| 6707 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6708 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6709 | request.load_flags = 0; |
| 6710 | |
| 6711 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6712 | MockWrite( |
| 6713 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6714 | "Host: www.example.org\r\n" |
| 6715 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6716 | }; |
| 6717 | |
| 6718 | MockRead data_reads[] = { |
| 6719 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6720 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6721 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6722 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6723 | }; |
| 6724 | |
| 6725 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6726 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6727 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6728 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6732 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6733 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6734 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6735 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6736 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6738 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6739 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6740 | |
| 6741 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6742 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6743 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6744 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6745 | } |
| 6746 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6747 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6748 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6749 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6750 | session_deps_.proxy_service.reset( |
| 6751 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6752 | |
| 6753 | HttpRequestInfo request; |
| 6754 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6755 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6756 | request.load_flags = 0; |
| 6757 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6758 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6759 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6760 | scoped_ptr<SpdyFrame> rst( |
| 6761 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6762 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6763 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6764 | }; |
| 6765 | |
| 6766 | static const char* const kExtraHeaders[] = { |
| 6767 | "location", |
| 6768 | "http://login.example.com/", |
| 6769 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6770 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6771 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6772 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6773 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6774 | spdy_util_.ConstructSpdyBodyFrame( |
| 6775 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6776 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6777 | CreateMockRead(*resp.get(), 1), |
| 6778 | CreateMockRead(*body.get(), 2), |
| 6779 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6780 | }; |
| 6781 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6782 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6783 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6784 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6785 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6786 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6790 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6791 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6792 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6793 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6796 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6797 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6798 | |
| 6799 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6800 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6801 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6802 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6803 | } |
| 6804 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6805 | // Test the request-challenge-retry sequence for basic auth, through |
| 6806 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6807 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6808 | HttpRequestInfo request; |
| 6809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6810 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6811 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6812 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6813 | |
| 6814 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6815 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6816 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6817 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6818 | session_deps_.net_log = log.bound().net_log(); |
| 6819 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6820 | |
| 6821 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6822 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6823 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6824 | scoped_ptr<SpdyFrame> rst( |
| 6825 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6826 | |
| 6827 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6828 | // be issuing -- the final header line contains the credentials. |
| 6829 | const char* const kAuthCredentials[] = { |
| 6830 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6831 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6832 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6833 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6834 | HostPortPair("www.example.org", 443))); |
| 6835 | // fetch https://www.example.org/ via HTTP |
| 6836 | const char get[] = |
| 6837 | "GET / HTTP/1.1\r\n" |
| 6838 | "Host: www.example.org\r\n" |
| 6839 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6840 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6841 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6842 | |
| 6843 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6844 | CreateMockWrite(*req, 0, ASYNC), |
| 6845 | CreateMockWrite(*rst, 2, ASYNC), |
| 6846 | CreateMockWrite(*connect2, 3), |
| 6847 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6848 | }; |
| 6849 | |
| 6850 | // The proxy responds to the connect with a 407, using a persistent |
| 6851 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6852 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6853 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6854 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6855 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6856 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6857 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6858 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6859 | scoped_ptr<SpdyFrame> conn_resp( |
| 6860 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6861 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6862 | "Content-Length: 5\r\n\r\n"; |
| 6863 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6864 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6865 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6866 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6867 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6868 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6869 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6870 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6871 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6872 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6873 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6874 | }; |
| 6875 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6876 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6877 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6879 | // Negotiate SPDY to the proxy |
| 6880 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6881 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6883 | // Vanilla SSL to the server |
| 6884 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6886 | |
| 6887 | TestCompletionCallback callback1; |
| 6888 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6889 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6891 | |
| 6892 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6894 | |
| 6895 | rv = callback1.WaitForResult(); |
| 6896 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6897 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6898 | log.GetEntries(&entries); |
| 6899 | size_t pos = ExpectLogContainsSomewhere( |
| 6900 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6901 | NetLog::PHASE_NONE); |
| 6902 | ExpectLogContainsSomewhere( |
| 6903 | entries, pos, |
| 6904 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6905 | NetLog::PHASE_NONE); |
| 6906 | |
| 6907 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6908 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6909 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6910 | EXPECT_EQ(407, response->headers->response_code()); |
| 6911 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6912 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6913 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6914 | |
| 6915 | TestCompletionCallback callback2; |
| 6916 | |
| 6917 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6918 | callback2.callback()); |
| 6919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6920 | |
| 6921 | rv = callback2.WaitForResult(); |
| 6922 | EXPECT_EQ(OK, rv); |
| 6923 | |
| 6924 | response = trans->GetResponseInfo(); |
| 6925 | ASSERT_TRUE(response != NULL); |
| 6926 | |
| 6927 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6928 | EXPECT_EQ(200, response->headers->response_code()); |
| 6929 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6930 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6931 | |
| 6932 | // The password prompt info should not be set. |
| 6933 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6934 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6935 | LoadTimingInfo load_timing_info; |
| 6936 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6937 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6938 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6939 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6940 | trans.reset(); |
| 6941 | session->CloseAllConnections(); |
| 6942 | } |
| 6943 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6944 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6945 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6946 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6947 | HttpRequestInfo request; |
| 6948 | HttpRequestInfo push_request; |
| 6949 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6950 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6951 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6952 | push_request.method = "GET"; |
| 6953 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6954 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6955 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6956 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6957 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6958 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6959 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6960 | |
| 6961 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6962 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6963 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6964 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6965 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6966 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6967 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6968 | |
| 6969 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6970 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6971 | }; |
| 6972 | |
| 6973 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6974 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6975 | |
| 6976 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6977 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6978 | |
| 6979 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6980 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6981 | 0, |
| 6982 | 2, |
| 6983 | 1, |
| 6984 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6985 | const char kPushedData[] = "pushed"; |
| 6986 | scoped_ptr<SpdyFrame> stream2_body( |
| 6987 | spdy_util_.ConstructSpdyBodyFrame( |
| 6988 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6989 | |
| 6990 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6991 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 6992 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 6993 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 6994 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 6995 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6996 | }; |
| 6997 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6998 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6999 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7000 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7001 | // Negotiate SPDY to the proxy |
| 7002 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7003 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7004 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7005 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7006 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7007 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7008 | TestCompletionCallback callback; |
| 7009 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7010 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7011 | |
| 7012 | rv = callback.WaitForResult(); |
| 7013 | EXPECT_EQ(OK, rv); |
| 7014 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7015 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7016 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7018 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7019 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7020 | |
| 7021 | rv = callback.WaitForResult(); |
| 7022 | EXPECT_EQ(OK, rv); |
| 7023 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7024 | |
| 7025 | ASSERT_TRUE(response != NULL); |
| 7026 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7027 | |
| 7028 | EXPECT_EQ(200, response->headers->response_code()); |
| 7029 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7030 | |
| 7031 | std::string response_data; |
| 7032 | rv = ReadTransaction(trans.get(), &response_data); |
| 7033 | EXPECT_EQ(OK, rv); |
| 7034 | EXPECT_EQ("hello!", response_data); |
| 7035 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7036 | LoadTimingInfo load_timing_info; |
| 7037 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7038 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7039 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7040 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7041 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7042 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7043 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7044 | |
| 7045 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7046 | EXPECT_EQ(OK, rv); |
| 7047 | EXPECT_EQ("pushed", response_data); |
| 7048 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7049 | LoadTimingInfo push_load_timing_info; |
| 7050 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7051 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7052 | // The transactions should share a socket ID, despite being for different |
| 7053 | // origins. |
| 7054 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7055 | push_load_timing_info.socket_log_id); |
| 7056 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7057 | trans.reset(); |
| 7058 | push_trans.reset(); |
| 7059 | session->CloseAllConnections(); |
| 7060 | } |
| 7061 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7062 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7063 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7064 | HttpRequestInfo request; |
| 7065 | |
| 7066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7067 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7068 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7069 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7070 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7071 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7072 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7073 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7074 | |
| 7075 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7076 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7077 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7078 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7079 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7080 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7081 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7082 | |
| 7083 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7084 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7085 | |
| 7086 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7087 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7088 | }; |
| 7089 | |
| 7090 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7091 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7092 | |
| 7093 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7094 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7095 | |
| 7096 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7097 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7098 | 0, |
| 7099 | 2, |
| 7100 | 1, |
| 7101 | "https://www.another-origin.com/foo.dat")); |
| 7102 | |
| 7103 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7104 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7105 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7106 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7107 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7108 | }; |
| 7109 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7110 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7111 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7112 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7113 | // Negotiate SPDY to the proxy |
| 7114 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7115 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7117 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7118 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7120 | TestCompletionCallback callback; |
| 7121 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7123 | |
| 7124 | rv = callback.WaitForResult(); |
| 7125 | EXPECT_EQ(OK, rv); |
| 7126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7127 | |
| 7128 | ASSERT_TRUE(response != NULL); |
| 7129 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7130 | |
| 7131 | EXPECT_EQ(200, response->headers->response_code()); |
| 7132 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7133 | |
| 7134 | std::string response_data; |
| 7135 | rv = ReadTransaction(trans.get(), &response_data); |
| 7136 | EXPECT_EQ(OK, rv); |
| 7137 | EXPECT_EQ("hello!", response_data); |
| 7138 | |
| 7139 | trans.reset(); |
| 7140 | session->CloseAllConnections(); |
| 7141 | } |
| 7142 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7143 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7144 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7145 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7146 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7147 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7148 | |
| 7149 | HttpRequestInfo request; |
| 7150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7151 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7152 | request.load_flags = 0; |
| 7153 | |
| 7154 | // Attempt to fetch the URL from a server with a bad cert |
| 7155 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7156 | MockWrite( |
| 7157 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7158 | "Host: www.example.org\r\n" |
| 7159 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7160 | }; |
| 7161 | |
| 7162 | MockRead bad_cert_reads[] = { |
| 7163 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7164 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7165 | }; |
| 7166 | |
| 7167 | // Attempt to fetch the URL with a good cert |
| 7168 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7169 | MockWrite( |
| 7170 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7171 | "Host: www.example.org\r\n" |
| 7172 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7173 | MockWrite( |
| 7174 | "GET / HTTP/1.1\r\n" |
| 7175 | "Host: www.example.org\r\n" |
| 7176 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7177 | }; |
| 7178 | |
| 7179 | MockRead good_cert_reads[] = { |
| 7180 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7181 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7182 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7183 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7184 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7185 | }; |
| 7186 | |
| 7187 | StaticSocketDataProvider ssl_bad_certificate( |
| 7188 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7189 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7190 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7191 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7192 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7193 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7194 | |
| 7195 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7197 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7199 | |
| 7200 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7205 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7206 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7207 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7208 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7211 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7212 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7213 | |
| 7214 | rv = callback.WaitForResult(); |
| 7215 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7217 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7218 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7219 | |
| 7220 | rv = callback.WaitForResult(); |
| 7221 | EXPECT_EQ(OK, rv); |
| 7222 | |
| 7223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7224 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7225 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7226 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7227 | } |
| 7228 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7229 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7230 | HttpRequestInfo request; |
| 7231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7232 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7233 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7234 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7235 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7236 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7237 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7239 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7240 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7241 | MockWrite( |
| 7242 | "GET / HTTP/1.1\r\n" |
| 7243 | "Host: www.example.org\r\n" |
| 7244 | "Connection: keep-alive\r\n" |
| 7245 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7246 | }; |
| 7247 | |
| 7248 | // Lastly, the server responds with the actual content. |
| 7249 | MockRead data_reads[] = { |
| 7250 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7251 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7252 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7253 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7254 | }; |
| 7255 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7257 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7260 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7262 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7264 | |
| 7265 | rv = callback.WaitForResult(); |
| 7266 | EXPECT_EQ(OK, rv); |
| 7267 | } |
| 7268 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7269 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7270 | HttpRequestInfo request; |
| 7271 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7272 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7273 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7274 | "Chromium Ultra Awesome X Edition"); |
| 7275 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7276 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7277 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7278 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7280 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7281 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7282 | MockWrite( |
| 7283 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7284 | "Host: www.example.org\r\n" |
| 7285 | "Proxy-Connection: keep-alive\r\n" |
| 7286 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7287 | }; |
| 7288 | MockRead data_reads[] = { |
| 7289 | // Return an error, so the transaction stops here (this test isn't |
| 7290 | // interested in the rest). |
| 7291 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7292 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7293 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7294 | }; |
| 7295 | |
| 7296 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7297 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7298 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7300 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7302 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7303 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7304 | |
| 7305 | rv = callback.WaitForResult(); |
| 7306 | EXPECT_EQ(OK, rv); |
| 7307 | } |
| 7308 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7309 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7310 | HttpRequestInfo request; |
| 7311 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7312 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7313 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7314 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7315 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7316 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7317 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7318 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7319 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7320 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7321 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7322 | MockWrite( |
| 7323 | "GET / HTTP/1.1\r\n" |
| 7324 | "Host: www.example.org\r\n" |
| 7325 | "Connection: keep-alive\r\n" |
| 7326 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7327 | }; |
| 7328 | |
| 7329 | // Lastly, the server responds with the actual content. |
| 7330 | MockRead data_reads[] = { |
| 7331 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7332 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7333 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7334 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7335 | }; |
| 7336 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7337 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7338 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7339 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7341 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7343 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7344 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7345 | |
| 7346 | rv = callback.WaitForResult(); |
| 7347 | EXPECT_EQ(OK, rv); |
| 7348 | } |
| 7349 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7350 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7351 | HttpRequestInfo request; |
| 7352 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7353 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7354 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7355 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7356 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7357 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7358 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7359 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7360 | MockWrite( |
| 7361 | "POST / HTTP/1.1\r\n" |
| 7362 | "Host: www.example.org\r\n" |
| 7363 | "Connection: keep-alive\r\n" |
| 7364 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7365 | }; |
| 7366 | |
| 7367 | // Lastly, the server responds with the actual content. |
| 7368 | MockRead data_reads[] = { |
| 7369 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7370 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7371 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7372 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7373 | }; |
| 7374 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7375 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7376 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7379 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7381 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7382 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7383 | |
| 7384 | rv = callback.WaitForResult(); |
| 7385 | EXPECT_EQ(OK, rv); |
| 7386 | } |
| 7387 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7388 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7389 | HttpRequestInfo request; |
| 7390 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7391 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7392 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7393 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7394 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7396 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7397 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7398 | MockWrite( |
| 7399 | "PUT / HTTP/1.1\r\n" |
| 7400 | "Host: www.example.org\r\n" |
| 7401 | "Connection: keep-alive\r\n" |
| 7402 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7403 | }; |
| 7404 | |
| 7405 | // Lastly, the server responds with the actual content. |
| 7406 | MockRead data_reads[] = { |
| 7407 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7408 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7409 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7410 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7411 | }; |
| 7412 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7413 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7414 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7417 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7419 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7420 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7421 | |
| 7422 | rv = callback.WaitForResult(); |
| 7423 | EXPECT_EQ(OK, rv); |
| 7424 | } |
| 7425 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7426 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7427 | HttpRequestInfo request; |
| 7428 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7429 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7430 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7431 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7432 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7433 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7434 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7435 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 7436 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7437 | "Host: www.example.org\r\n" |
| 7438 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7439 | }; |
| 7440 | |
| 7441 | // Lastly, the server responds with the actual content. |
| 7442 | MockRead data_reads[] = { |
| 7443 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7444 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7445 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7446 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7447 | }; |
| 7448 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7449 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7450 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7453 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7455 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7456 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7457 | |
| 7458 | rv = callback.WaitForResult(); |
| 7459 | EXPECT_EQ(OK, rv); |
| 7460 | } |
| 7461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7462 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7463 | HttpRequestInfo request; |
| 7464 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7465 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7466 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7467 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7468 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7469 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7470 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7471 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7472 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7473 | MockWrite( |
| 7474 | "GET / HTTP/1.1\r\n" |
| 7475 | "Host: www.example.org\r\n" |
| 7476 | "Connection: keep-alive\r\n" |
| 7477 | "Pragma: no-cache\r\n" |
| 7478 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7479 | }; |
| 7480 | |
| 7481 | // Lastly, the server responds with the actual content. |
| 7482 | MockRead data_reads[] = { |
| 7483 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7484 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7485 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7486 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7487 | }; |
| 7488 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7489 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7490 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7491 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7493 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7495 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7496 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7497 | |
| 7498 | rv = callback.WaitForResult(); |
| 7499 | EXPECT_EQ(OK, rv); |
| 7500 | } |
| 7501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7502 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7503 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7504 | HttpRequestInfo request; |
| 7505 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7506 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7507 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7508 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7509 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7510 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7512 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7513 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7514 | MockWrite( |
| 7515 | "GET / HTTP/1.1\r\n" |
| 7516 | "Host: www.example.org\r\n" |
| 7517 | "Connection: keep-alive\r\n" |
| 7518 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | // Lastly, the server responds with the actual content. |
| 7522 | MockRead data_reads[] = { |
| 7523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7527 | }; |
| 7528 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7529 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7530 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7531 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7533 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7536 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7537 | |
| 7538 | rv = callback.WaitForResult(); |
| 7539 | EXPECT_EQ(OK, rv); |
| 7540 | } |
| 7541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7542 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7543 | HttpRequestInfo request; |
| 7544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7545 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7546 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7547 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7548 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7549 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7550 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7551 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7552 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7553 | MockWrite( |
| 7554 | "GET / HTTP/1.1\r\n" |
| 7555 | "Host: www.example.org\r\n" |
| 7556 | "Connection: keep-alive\r\n" |
| 7557 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7558 | }; |
| 7559 | |
| 7560 | // Lastly, the server responds with the actual content. |
| 7561 | MockRead data_reads[] = { |
| 7562 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7563 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7564 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7565 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7566 | }; |
| 7567 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7568 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7569 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7572 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7574 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7575 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7576 | |
| 7577 | rv = callback.WaitForResult(); |
| 7578 | EXPECT_EQ(OK, rv); |
| 7579 | } |
| 7580 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7581 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7582 | HttpRequestInfo request; |
| 7583 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7584 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7585 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7586 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7587 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7588 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7589 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7590 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7592 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7593 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7594 | MockWrite( |
| 7595 | "GET / HTTP/1.1\r\n" |
| 7596 | "Host: www.example.org\r\n" |
| 7597 | "Connection: keep-alive\r\n" |
| 7598 | "referer: www.foo.com\r\n" |
| 7599 | "hEllo: Kitty\r\n" |
| 7600 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7601 | }; |
| 7602 | |
| 7603 | // Lastly, the server responds with the actual content. |
| 7604 | MockRead data_reads[] = { |
| 7605 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7606 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7607 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7608 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7609 | }; |
| 7610 | |
| 7611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7612 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7615 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7616 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7617 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7619 | |
| 7620 | rv = callback.WaitForResult(); |
| 7621 | EXPECT_EQ(OK, rv); |
| 7622 | } |
| 7623 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7624 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7625 | HttpRequestInfo request; |
| 7626 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7627 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7628 | request.load_flags = 0; |
| 7629 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7630 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7631 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7632 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7633 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7634 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7635 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7636 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7637 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7638 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7639 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7640 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7641 | |
| 7642 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7643 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7644 | MockWrite( |
| 7645 | "GET / HTTP/1.1\r\n" |
| 7646 | "Host: www.example.org\r\n" |
| 7647 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7648 | |
| 7649 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7650 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7651 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7652 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7653 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7654 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7655 | }; |
| 7656 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7657 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7658 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7661 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7663 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7665 | |
| 7666 | rv = callback.WaitForResult(); |
| 7667 | EXPECT_EQ(OK, rv); |
| 7668 | |
| 7669 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7670 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7671 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7672 | LoadTimingInfo load_timing_info; |
| 7673 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7674 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7675 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7676 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7677 | std::string response_text; |
| 7678 | rv = ReadTransaction(trans.get(), &response_text); |
| 7679 | EXPECT_EQ(OK, rv); |
| 7680 | EXPECT_EQ("Payload", response_text); |
| 7681 | } |
| 7682 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7683 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7684 | HttpRequestInfo request; |
| 7685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7686 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7687 | request.load_flags = 0; |
| 7688 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7689 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7690 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7691 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7692 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7693 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7694 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7695 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7696 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7697 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7698 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7699 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7700 | |
| 7701 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7702 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7703 | arraysize(write_buffer)), |
| 7704 | MockWrite( |
| 7705 | "GET / HTTP/1.1\r\n" |
| 7706 | "Host: www.example.org\r\n" |
| 7707 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7708 | |
| 7709 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7710 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7711 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7712 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7713 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7714 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7715 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7716 | }; |
| 7717 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7718 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7719 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7720 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7721 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7722 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7725 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7727 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7728 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7729 | |
| 7730 | rv = callback.WaitForResult(); |
| 7731 | EXPECT_EQ(OK, rv); |
| 7732 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7733 | LoadTimingInfo load_timing_info; |
| 7734 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7735 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7736 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7737 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7738 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7739 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7740 | |
| 7741 | std::string response_text; |
| 7742 | rv = ReadTransaction(trans.get(), &response_text); |
| 7743 | EXPECT_EQ(OK, rv); |
| 7744 | EXPECT_EQ("Payload", response_text); |
| 7745 | } |
| 7746 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7747 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7748 | HttpRequestInfo request; |
| 7749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7750 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7751 | request.load_flags = 0; |
| 7752 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7753 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7754 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7755 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7756 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7757 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7758 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7759 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7761 | |
| 7762 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7763 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7764 | |
| 7765 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7766 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7767 | MockWrite( |
| 7768 | "GET / HTTP/1.1\r\n" |
| 7769 | "Host: www.example.org\r\n" |
| 7770 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7771 | |
| 7772 | MockRead data_reads[] = { |
| 7773 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7774 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7775 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7776 | MockRead("Payload"), |
| 7777 | MockRead(SYNCHRONOUS, OK) |
| 7778 | }; |
| 7779 | |
| 7780 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7781 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7783 | |
| 7784 | TestCompletionCallback callback; |
| 7785 | |
| 7786 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7787 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7788 | |
| 7789 | rv = callback.WaitForResult(); |
| 7790 | EXPECT_EQ(OK, rv); |
| 7791 | |
| 7792 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7793 | ASSERT_TRUE(response != NULL); |
| 7794 | |
| 7795 | LoadTimingInfo load_timing_info; |
| 7796 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7797 | TestLoadTimingNotReused(load_timing_info, |
| 7798 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7799 | |
| 7800 | std::string response_text; |
| 7801 | rv = ReadTransaction(trans.get(), &response_text); |
| 7802 | EXPECT_EQ(OK, rv); |
| 7803 | EXPECT_EQ("Payload", response_text); |
| 7804 | } |
| 7805 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7806 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7807 | HttpRequestInfo request; |
| 7808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7809 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7810 | request.load_flags = 0; |
| 7811 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7812 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7813 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7814 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7815 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7816 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7817 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7818 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7819 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7820 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7821 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7822 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7823 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7824 | 0x05, // Version |
| 7825 | 0x01, // Command (CONNECT) |
| 7826 | 0x00, // Reserved. |
| 7827 | 0x03, // Address type (DOMAINNAME). |
| 7828 | 0x0F, // Length of domain (15) |
| 7829 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7830 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7831 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7832 | const char kSOCKS5OkResponse[] = |
| 7833 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7834 | |
| 7835 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7836 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7837 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7838 | MockWrite( |
| 7839 | "GET / HTTP/1.1\r\n" |
| 7840 | "Host: www.example.org\r\n" |
| 7841 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7842 | |
| 7843 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7844 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7845 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7846 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7848 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7849 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7850 | }; |
| 7851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7853 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7855 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7856 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7858 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7860 | |
| 7861 | rv = callback.WaitForResult(); |
| 7862 | EXPECT_EQ(OK, rv); |
| 7863 | |
| 7864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7865 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7866 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7867 | LoadTimingInfo load_timing_info; |
| 7868 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7869 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7870 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7871 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7872 | std::string response_text; |
| 7873 | rv = ReadTransaction(trans.get(), &response_text); |
| 7874 | EXPECT_EQ(OK, rv); |
| 7875 | EXPECT_EQ("Payload", response_text); |
| 7876 | } |
| 7877 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7878 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7879 | HttpRequestInfo request; |
| 7880 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7881 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7882 | request.load_flags = 0; |
| 7883 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7884 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7885 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7886 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7887 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7888 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7889 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7890 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7892 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7893 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7894 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7895 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7896 | 0x05, // Version |
| 7897 | 0x01, // Command (CONNECT) |
| 7898 | 0x00, // Reserved. |
| 7899 | 0x03, // Address type (DOMAINNAME). |
| 7900 | 0x0F, // Length of domain (15) |
| 7901 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7902 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7903 | }; |
| 7904 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7905 | const char kSOCKS5OkResponse[] = |
| 7906 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7907 | |
| 7908 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7909 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7910 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7911 | arraysize(kSOCKS5OkRequest)), |
| 7912 | MockWrite( |
| 7913 | "GET / HTTP/1.1\r\n" |
| 7914 | "Host: www.example.org\r\n" |
| 7915 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7916 | |
| 7917 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7918 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7919 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7920 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7921 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7922 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7923 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7924 | }; |
| 7925 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7927 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7929 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7930 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7933 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7935 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7937 | |
| 7938 | rv = callback.WaitForResult(); |
| 7939 | EXPECT_EQ(OK, rv); |
| 7940 | |
| 7941 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7942 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7943 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7944 | LoadTimingInfo load_timing_info; |
| 7945 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7946 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7947 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7948 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7949 | std::string response_text; |
| 7950 | rv = ReadTransaction(trans.get(), &response_text); |
| 7951 | EXPECT_EQ(OK, rv); |
| 7952 | EXPECT_EQ("Payload", response_text); |
| 7953 | } |
| 7954 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7955 | namespace { |
| 7956 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7957 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7958 | |
| 7959 | struct GroupNameTest { |
| 7960 | std::string proxy_server; |
| 7961 | std::string url; |
| 7962 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7963 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7964 | }; |
| 7965 | |
| 7966 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7967 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7968 | SpdySessionDependencies* session_deps_) { |
| 7969 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7970 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7971 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7972 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7973 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7974 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7975 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7976 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7977 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 7978 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7979 | |
| 7980 | return session; |
| 7981 | } |
| 7982 | |
| 7983 | int GroupNameTransactionHelper( |
| 7984 | const std::string& url, |
| 7985 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7986 | HttpRequestInfo request; |
| 7987 | request.method = "GET"; |
| 7988 | request.url = GURL(url); |
| 7989 | request.load_flags = 0; |
| 7990 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7991 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7994 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7995 | |
| 7996 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7997 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7998 | } |
| 7999 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8000 | } // namespace |
| 8001 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8002 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8003 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8004 | { |
| 8005 | "", // unused |
| 8006 | "http://www.example.org/direct", |
| 8007 | "www.example.org:80", |
| 8008 | false, |
| 8009 | }, |
| 8010 | { |
| 8011 | "", // unused |
| 8012 | "http://[2001:1418:13:1::25]/direct", |
| 8013 | "[2001:1418:13:1::25]:80", |
| 8014 | false, |
| 8015 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8016 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8017 | // SSL Tests |
| 8018 | { |
| 8019 | "", // unused |
| 8020 | "https://www.example.org/direct_ssl", |
| 8021 | "ssl/www.example.org:443", |
| 8022 | true, |
| 8023 | }, |
| 8024 | { |
| 8025 | "", // unused |
| 8026 | "https://[2001:1418:13:1::25]/direct", |
| 8027 | "ssl/[2001:1418:13:1::25]:443", |
| 8028 | true, |
| 8029 | }, |
| 8030 | { |
| 8031 | "", // unused |
| 8032 | "http://host.with.alternate/direct", |
| 8033 | "ssl/host.with.alternate:443", |
| 8034 | true, |
| 8035 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8036 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8037 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8038 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8039 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8040 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8041 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8042 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8043 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8044 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8045 | |
| 8046 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8047 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8048 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8049 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8050 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8051 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8052 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8053 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8054 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8055 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8056 | |
| 8057 | EXPECT_EQ(ERR_IO_PENDING, |
| 8058 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8059 | if (tests[i].ssl) |
| 8060 | EXPECT_EQ(tests[i].expected_group_name, |
| 8061 | ssl_conn_pool->last_group_name_received()); |
| 8062 | else |
| 8063 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8064 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8065 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8066 | } |
| 8067 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8068 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8069 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8070 | { |
| 8071 | "http_proxy", |
| 8072 | "http://www.example.org/http_proxy_normal", |
| 8073 | "www.example.org:80", |
| 8074 | false, |
| 8075 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8076 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8077 | // SSL Tests |
| 8078 | { |
| 8079 | "http_proxy", |
| 8080 | "https://www.example.org/http_connect_ssl", |
| 8081 | "ssl/www.example.org:443", |
| 8082 | true, |
| 8083 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8084 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8085 | { |
| 8086 | "http_proxy", |
| 8087 | "http://host.with.alternate/direct", |
| 8088 | "ssl/host.with.alternate:443", |
| 8089 | true, |
| 8090 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8091 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8092 | { |
| 8093 | "http_proxy", |
| 8094 | "ftp://ftp.google.com/http_proxy_normal", |
| 8095 | "ftp/ftp.google.com:21", |
| 8096 | false, |
| 8097 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8098 | }; |
| 8099 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8100 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8101 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8102 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8103 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8104 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8105 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8106 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8107 | |
| 8108 | HttpNetworkSessionPeer peer(session); |
| 8109 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8110 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8111 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8112 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8113 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8114 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8115 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8116 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8117 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8118 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8119 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8120 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8121 | |
| 8122 | EXPECT_EQ(ERR_IO_PENDING, |
| 8123 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8124 | if (tests[i].ssl) |
| 8125 | EXPECT_EQ(tests[i].expected_group_name, |
| 8126 | ssl_conn_pool->last_group_name_received()); |
| 8127 | else |
| 8128 | EXPECT_EQ(tests[i].expected_group_name, |
| 8129 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8130 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8131 | } |
| 8132 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8133 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8134 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8135 | { |
| 8136 | "socks4://socks_proxy:1080", |
| 8137 | "http://www.example.org/socks4_direct", |
| 8138 | "socks4/www.example.org:80", |
| 8139 | false, |
| 8140 | }, |
| 8141 | { |
| 8142 | "socks5://socks_proxy:1080", |
| 8143 | "http://www.example.org/socks5_direct", |
| 8144 | "socks5/www.example.org:80", |
| 8145 | false, |
| 8146 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8147 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8148 | // SSL Tests |
| 8149 | { |
| 8150 | "socks4://socks_proxy:1080", |
| 8151 | "https://www.example.org/socks4_ssl", |
| 8152 | "socks4/ssl/www.example.org:443", |
| 8153 | true, |
| 8154 | }, |
| 8155 | { |
| 8156 | "socks5://socks_proxy:1080", |
| 8157 | "https://www.example.org/socks5_ssl", |
| 8158 | "socks5/ssl/www.example.org:443", |
| 8159 | true, |
| 8160 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8161 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8162 | { |
| 8163 | "socks4://socks_proxy:1080", |
| 8164 | "http://host.with.alternate/direct", |
| 8165 | "socks4/ssl/host.with.alternate:443", |
| 8166 | true, |
| 8167 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8168 | }; |
| 8169 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8170 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8171 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8172 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8173 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8174 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8175 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8176 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8177 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8178 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8179 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8180 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8181 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8182 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8183 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8184 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8185 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8186 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8187 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8188 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8189 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8190 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8191 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8192 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8194 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8195 | EXPECT_EQ(ERR_IO_PENDING, |
| 8196 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8197 | if (tests[i].ssl) |
| 8198 | EXPECT_EQ(tests[i].expected_group_name, |
| 8199 | ssl_conn_pool->last_group_name_received()); |
| 8200 | else |
| 8201 | EXPECT_EQ(tests[i].expected_group_name, |
| 8202 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8203 | } |
| 8204 | } |
| 8205 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8206 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8207 | HttpRequestInfo request; |
| 8208 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8209 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8210 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8211 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8212 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8213 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8214 | // This simulates failure resolving all hostnames; that means we will fail |
| 8215 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8216 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8217 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8218 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8219 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8222 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8226 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8227 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8228 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8229 | } |
| 8230 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8231 | // Base test to make sure that when the load flags for a request specify to |
| 8232 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8233 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8234 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8235 | // Issue a request, asking to bypass the cache(s). |
| 8236 | HttpRequestInfo request; |
| 8237 | request.method = "GET"; |
| 8238 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8239 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8240 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8241 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8242 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8243 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8244 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8245 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8247 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8248 | // 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] | 8249 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8250 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8251 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8252 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8253 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8255 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8256 | EXPECT_EQ(OK, rv); |
| 8257 | |
| 8258 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8259 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8260 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8261 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8262 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8263 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8264 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8265 | // 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] | 8266 | // we can tell if the next lookup hit the cache, or the "network". |
| 8267 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8268 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8269 | |
| 8270 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8271 | // 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] | 8272 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8273 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8274 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8275 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8276 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8277 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8278 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8279 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8280 | |
| 8281 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8282 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8283 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8284 | } |
| 8285 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8286 | // There are multiple load flags that should trigger the host cache bypass. |
| 8287 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8288 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8289 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8290 | } |
| 8291 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8292 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8293 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8294 | } |
| 8295 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8296 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8297 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8298 | } |
| 8299 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8300 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8301 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8302 | HttpRequestInfo request; |
| 8303 | request.method = "GET"; |
| 8304 | request.url = GURL("http://www.foo.com/"); |
| 8305 | request.load_flags = 0; |
| 8306 | |
| 8307 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8308 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8309 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8310 | StaticSocketDataProvider data(NULL, 0, |
| 8311 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8312 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8313 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8315 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8316 | |
| 8317 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8318 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8320 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8322 | |
| 8323 | rv = callback.WaitForResult(); |
| 8324 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8325 | } |
| 8326 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8327 | // Check that a connection closed after the start of the headers finishes ok. |
| 8328 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8329 | HttpRequestInfo request; |
| 8330 | request.method = "GET"; |
| 8331 | request.url = GURL("http://www.foo.com/"); |
| 8332 | request.load_flags = 0; |
| 8333 | |
| 8334 | MockRead data_reads[] = { |
| 8335 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8337 | }; |
| 8338 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8341 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8343 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8344 | |
| 8345 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8346 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8348 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8350 | |
| 8351 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8352 | EXPECT_EQ(OK, rv); |
| 8353 | |
| 8354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8355 | ASSERT_TRUE(response != NULL); |
| 8356 | |
| 8357 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8358 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8359 | |
| 8360 | std::string response_data; |
| 8361 | rv = ReadTransaction(trans.get(), &response_data); |
| 8362 | EXPECT_EQ(OK, rv); |
| 8363 | EXPECT_EQ("", response_data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8364 | } |
| 8365 | |
| 8366 | // Make sure that a dropped connection while draining the body for auth |
| 8367 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8368 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8369 | HttpRequestInfo request; |
| 8370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8371 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8372 | request.load_flags = 0; |
| 8373 | |
| 8374 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8375 | MockWrite( |
| 8376 | "GET / HTTP/1.1\r\n" |
| 8377 | "Host: www.example.org\r\n" |
| 8378 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8379 | }; |
| 8380 | |
| 8381 | MockRead data_reads1[] = { |
| 8382 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8383 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8384 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8385 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8386 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8387 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8388 | }; |
| 8389 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8390 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8391 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8392 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8393 | |
| 8394 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8395 | // be issuing -- the final header line contains the credentials. |
| 8396 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8397 | MockWrite( |
| 8398 | "GET / HTTP/1.1\r\n" |
| 8399 | "Host: www.example.org\r\n" |
| 8400 | "Connection: keep-alive\r\n" |
| 8401 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8402 | }; |
| 8403 | |
| 8404 | // Lastly, the server responds with the actual content. |
| 8405 | MockRead data_reads2[] = { |
| 8406 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8407 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8408 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8409 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8410 | }; |
| 8411 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8412 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8413 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8415 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8417 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8418 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8419 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8422 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8424 | |
| 8425 | rv = callback1.WaitForResult(); |
| 8426 | EXPECT_EQ(OK, rv); |
| 8427 | |
| 8428 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8429 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8430 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8432 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8434 | rv = trans->RestartWithAuth( |
| 8435 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8436 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8437 | |
| 8438 | rv = callback2.WaitForResult(); |
| 8439 | EXPECT_EQ(OK, rv); |
| 8440 | |
| 8441 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8442 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8443 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8444 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8445 | } |
| 8446 | |
| 8447 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8448 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8449 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8450 | |
| 8451 | HttpRequestInfo request; |
| 8452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8453 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8454 | request.load_flags = 0; |
| 8455 | |
| 8456 | MockRead proxy_reads[] = { |
| 8457 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8458 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8459 | }; |
| 8460 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8461 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8462 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8463 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8464 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8467 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8468 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8469 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8470 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8471 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8472 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8473 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8475 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8476 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8477 | |
| 8478 | rv = callback.WaitForResult(); |
| 8479 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8480 | } |
| 8481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8482 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8483 | HttpRequestInfo request; |
| 8484 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8485 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8486 | request.load_flags = 0; |
| 8487 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8488 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8489 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8490 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8491 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8492 | MockRead data_reads[] = { |
| 8493 | 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] | 8494 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8495 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8496 | |
| 8497 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8500 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8502 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8503 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8504 | |
| 8505 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8506 | |
| 8507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8508 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8509 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8510 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8511 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8512 | |
| 8513 | std::string response_data; |
| 8514 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8515 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8516 | } |
| 8517 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8518 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8519 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8520 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8521 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8522 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8523 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8524 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8525 | ScopedVector<UploadElementReader> element_readers; |
| 8526 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8527 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8528 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8529 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8530 | |
| 8531 | HttpRequestInfo request; |
| 8532 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8533 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8534 | request.upload_data_stream = &upload_data_stream; |
| 8535 | request.load_flags = 0; |
| 8536 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8537 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8538 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8539 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8540 | |
| 8541 | MockRead data_reads[] = { |
| 8542 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8543 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8544 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8545 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8546 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8549 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8551 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8552 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8553 | |
| 8554 | rv = callback.WaitForResult(); |
| 8555 | EXPECT_EQ(OK, rv); |
| 8556 | |
| 8557 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8558 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8559 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8560 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8561 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8562 | |
| 8563 | std::string response_data; |
| 8564 | rv = ReadTransaction(trans.get(), &response_data); |
| 8565 | EXPECT_EQ(OK, rv); |
| 8566 | EXPECT_EQ("hello world", response_data); |
| 8567 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8568 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8569 | } |
| 8570 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8571 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8572 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8573 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8574 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8575 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8576 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8577 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8578 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8579 | ScopedVector<UploadElementReader> element_readers; |
| 8580 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8581 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8582 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8583 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8584 | |
| 8585 | HttpRequestInfo request; |
| 8586 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8587 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8588 | request.upload_data_stream = &upload_data_stream; |
| 8589 | request.load_flags = 0; |
| 8590 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8591 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8592 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8593 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8595 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8596 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8597 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8599 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8601 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8603 | |
| 8604 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8605 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8606 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8607 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8608 | } |
| 8609 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8610 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8611 | class FakeUploadElementReader : public UploadElementReader { |
| 8612 | public: |
| 8613 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8614 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8615 | |
| 8616 | const CompletionCallback& callback() const { return callback_; } |
| 8617 | |
| 8618 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8619 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8620 | callback_ = callback; |
| 8621 | return ERR_IO_PENDING; |
| 8622 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8623 | uint64 GetContentLength() const override { return 0; } |
| 8624 | uint64 BytesRemaining() const override { return 0; } |
| 8625 | int Read(IOBuffer* buf, |
| 8626 | int buf_length, |
| 8627 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8628 | return ERR_FAILED; |
| 8629 | } |
| 8630 | |
| 8631 | private: |
| 8632 | CompletionCallback callback_; |
| 8633 | }; |
| 8634 | |
| 8635 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8636 | ScopedVector<UploadElementReader> element_readers; |
| 8637 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8638 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8639 | |
| 8640 | HttpRequestInfo request; |
| 8641 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8642 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8643 | request.upload_data_stream = &upload_data_stream; |
| 8644 | request.load_flags = 0; |
| 8645 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8646 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8647 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8648 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8649 | |
| 8650 | StaticSocketDataProvider data; |
| 8651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8652 | |
| 8653 | TestCompletionCallback callback; |
| 8654 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8656 | base::MessageLoop::current()->RunUntilIdle(); |
| 8657 | |
| 8658 | // Transaction is pending on request body initialization. |
| 8659 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8660 | |
| 8661 | // Return Init()'s result after the transaction gets destroyed. |
| 8662 | trans.reset(); |
| 8663 | fake_reader->callback().Run(OK); // Should not crash. |
| 8664 | } |
| 8665 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8666 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8667 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8668 | HttpRequestInfo request; |
| 8669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8670 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8671 | request.load_flags = 0; |
| 8672 | |
| 8673 | // First transaction will request a resource and receive a Basic challenge |
| 8674 | // with realm="first_realm". |
| 8675 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8676 | MockWrite( |
| 8677 | "GET / HTTP/1.1\r\n" |
| 8678 | "Host: www.example.org\r\n" |
| 8679 | "Connection: keep-alive\r\n" |
| 8680 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8681 | }; |
| 8682 | MockRead data_reads1[] = { |
| 8683 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8684 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8685 | "\r\n"), |
| 8686 | }; |
| 8687 | |
| 8688 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8689 | // for first_realm. The server will reject and provide a challenge with |
| 8690 | // second_realm. |
| 8691 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8692 | MockWrite( |
| 8693 | "GET / HTTP/1.1\r\n" |
| 8694 | "Host: www.example.org\r\n" |
| 8695 | "Connection: keep-alive\r\n" |
| 8696 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8697 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8698 | }; |
| 8699 | MockRead data_reads2[] = { |
| 8700 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8701 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8702 | "\r\n"), |
| 8703 | }; |
| 8704 | |
| 8705 | // This again fails, and goes back to first_realm. Make sure that the |
| 8706 | // entry is removed from cache. |
| 8707 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8708 | MockWrite( |
| 8709 | "GET / HTTP/1.1\r\n" |
| 8710 | "Host: www.example.org\r\n" |
| 8711 | "Connection: keep-alive\r\n" |
| 8712 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8713 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8714 | }; |
| 8715 | MockRead data_reads3[] = { |
| 8716 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8717 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8718 | "\r\n"), |
| 8719 | }; |
| 8720 | |
| 8721 | // Try one last time (with the correct password) and get the resource. |
| 8722 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8723 | MockWrite( |
| 8724 | "GET / HTTP/1.1\r\n" |
| 8725 | "Host: www.example.org\r\n" |
| 8726 | "Connection: keep-alive\r\n" |
| 8727 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8728 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8729 | }; |
| 8730 | MockRead data_reads4[] = { |
| 8731 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8732 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8733 | "Content-Length: 5\r\n" |
| 8734 | "\r\n" |
| 8735 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8736 | }; |
| 8737 | |
| 8738 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8739 | data_writes1, arraysize(data_writes1)); |
| 8740 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8741 | data_writes2, arraysize(data_writes2)); |
| 8742 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8743 | data_writes3, arraysize(data_writes3)); |
| 8744 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8745 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8746 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8747 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8748 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8749 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8751 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8752 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8753 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8754 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8756 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8757 | // Issue the first request with Authorize headers. There should be a |
| 8758 | // password prompt for first_realm waiting to be filled in after the |
| 8759 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8760 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8762 | rv = callback1.WaitForResult(); |
| 8763 | EXPECT_EQ(OK, rv); |
| 8764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8765 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8766 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8767 | ASSERT_FALSE(challenge == NULL); |
| 8768 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8769 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8770 | EXPECT_EQ("first_realm", challenge->realm); |
| 8771 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8772 | |
| 8773 | // Issue the second request with an incorrect password. There should be a |
| 8774 | // password prompt for second_realm waiting to be filled in after the |
| 8775 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8776 | TestCompletionCallback callback2; |
| 8777 | rv = trans->RestartWithAuth( |
| 8778 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8780 | rv = callback2.WaitForResult(); |
| 8781 | EXPECT_EQ(OK, rv); |
| 8782 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8783 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8784 | challenge = response->auth_challenge.get(); |
| 8785 | ASSERT_FALSE(challenge == NULL); |
| 8786 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8787 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8788 | EXPECT_EQ("second_realm", challenge->realm); |
| 8789 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8790 | |
| 8791 | // Issue the third request with another incorrect password. There should be |
| 8792 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8793 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8794 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8795 | TestCompletionCallback callback3; |
| 8796 | rv = trans->RestartWithAuth( |
| 8797 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8798 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8799 | rv = callback3.WaitForResult(); |
| 8800 | EXPECT_EQ(OK, rv); |
| 8801 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8802 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8803 | challenge = response->auth_challenge.get(); |
| 8804 | ASSERT_FALSE(challenge == NULL); |
| 8805 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8806 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8807 | EXPECT_EQ("first_realm", challenge->realm); |
| 8808 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8809 | |
| 8810 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8811 | TestCompletionCallback callback4; |
| 8812 | rv = trans->RestartWithAuth( |
| 8813 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8815 | rv = callback4.WaitForResult(); |
| 8816 | EXPECT_EQ(OK, rv); |
| 8817 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8818 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8819 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8820 | } |
| 8821 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8822 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 8823 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8824 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8825 | |
| 8826 | std::string alternative_service_http_header = |
| 8827 | GetAlternativeServiceHttpHeader(); |
| 8828 | |
| 8829 | MockRead data_reads[] = { |
| 8830 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8831 | MockRead(alternative_service_http_header.c_str()), |
| 8832 | MockRead("\r\n"), |
| 8833 | MockRead("hello world"), |
| 8834 | MockRead(SYNCHRONOUS, OK), |
| 8835 | }; |
| 8836 | |
| 8837 | HttpRequestInfo request; |
| 8838 | request.method = "GET"; |
| 8839 | request.url = GURL("http://www.example.org/"); |
| 8840 | request.load_flags = 0; |
| 8841 | |
| 8842 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8843 | |
| 8844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8845 | |
| 8846 | TestCompletionCallback callback; |
| 8847 | |
| 8848 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8849 | scoped_ptr<HttpTransaction> trans( |
| 8850 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8851 | |
| 8852 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8854 | |
| 8855 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8856 | HttpServerProperties& http_server_properties = |
| 8857 | *session->http_server_properties(); |
| 8858 | AlternativeServiceVector alternative_service_vector = |
| 8859 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8860 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8861 | |
| 8862 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8863 | |
| 8864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8865 | ASSERT_TRUE(response != NULL); |
| 8866 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8867 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8868 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8869 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8870 | |
| 8871 | std::string response_data; |
| 8872 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8873 | EXPECT_EQ("hello world", response_data); |
| 8874 | |
| 8875 | alternative_service_vector = |
| 8876 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8877 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8878 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8879 | alternative_service_vector[0].protocol); |
| 8880 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8881 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8882 | } |
| 8883 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8884 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 8885 | // is false. |
| 8886 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 8887 | session_deps_.next_protos = SpdyNextProtos(); |
| 8888 | session_deps_.use_alternative_services = false; |
| 8889 | |
| 8890 | std::string alternative_service_http_header = |
| 8891 | GetAlternativeServiceHttpHeader(); |
| 8892 | |
| 8893 | MockRead data_reads[] = { |
| 8894 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8895 | MockRead(alternative_service_http_header.c_str()), |
| 8896 | MockRead("\r\n"), |
| 8897 | MockRead("hello world"), |
| 8898 | MockRead(SYNCHRONOUS, OK), |
| 8899 | }; |
| 8900 | |
| 8901 | HttpRequestInfo request; |
| 8902 | request.method = "GET"; |
| 8903 | request.url = GURL("http://www.example.org/"); |
| 8904 | request.load_flags = 0; |
| 8905 | |
| 8906 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 8907 | |
| 8908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8909 | |
| 8910 | TestCompletionCallback callback; |
| 8911 | |
| 8912 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8913 | scoped_ptr<HttpTransaction> trans( |
| 8914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8915 | |
| 8916 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8918 | |
| 8919 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8920 | HttpServerProperties& http_server_properties = |
| 8921 | *session->http_server_properties(); |
| 8922 | AlternativeServiceVector alternative_service_vector = |
| 8923 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8924 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8925 | |
| 8926 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8927 | |
| 8928 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8929 | ASSERT_TRUE(response != nullptr); |
| 8930 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 8931 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8932 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8933 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8934 | |
| 8935 | std::string response_data; |
| 8936 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8937 | EXPECT_EQ("hello world", response_data); |
| 8938 | |
| 8939 | alternative_service_vector = |
| 8940 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8941 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8942 | } |
| 8943 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8944 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 8945 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8946 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8947 | |
| 8948 | MockRead data_reads[] = { |
| 8949 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8950 | MockRead("Alt-Svc: "), |
| 8951 | MockRead(GetAlternateProtocolFromParam()), |
| 8952 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 8953 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 8954 | MockRead("hello world"), |
| 8955 | MockRead(SYNCHRONOUS, OK), |
| 8956 | }; |
| 8957 | |
| 8958 | HttpRequestInfo request; |
| 8959 | request.method = "GET"; |
| 8960 | request.url = GURL("http://www.example.org/"); |
| 8961 | request.load_flags = 0; |
| 8962 | |
| 8963 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8964 | |
| 8965 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8966 | |
| 8967 | TestCompletionCallback callback; |
| 8968 | |
| 8969 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8970 | scoped_ptr<HttpTransaction> trans( |
| 8971 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8972 | |
| 8973 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8975 | |
| 8976 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8977 | HttpServerProperties& http_server_properties = |
| 8978 | *session->http_server_properties(); |
| 8979 | AlternativeServiceVector alternative_service_vector = |
| 8980 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8981 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8982 | |
| 8983 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8984 | |
| 8985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8986 | ASSERT_TRUE(response != NULL); |
| 8987 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8988 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8989 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8990 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8991 | |
| 8992 | std::string response_data; |
| 8993 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8994 | EXPECT_EQ("hello world", response_data); |
| 8995 | |
| 8996 | alternative_service_vector = |
| 8997 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8998 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 8999 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9000 | alternative_service_vector[0].protocol); |
| 9001 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9002 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9003 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9004 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9005 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9006 | } |
| 9007 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9008 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9009 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9010 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9011 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9012 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9013 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9014 | std::string alternate_protocol_http_header = |
| 9015 | GetAlternateProtocolHttpHeader(); |
| 9016 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9017 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9018 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9019 | MockRead(alternate_protocol_http_header.c_str()), |
| 9020 | MockRead("\r\n"), |
| 9021 | MockRead("hello world"), |
| 9022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9023 | }; |
| 9024 | |
| 9025 | HttpRequestInfo request; |
| 9026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9027 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9028 | request.load_flags = 0; |
| 9029 | |
| 9030 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9031 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9032 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9034 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9035 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9036 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9037 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9040 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9042 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9043 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9044 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9045 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9046 | AlternativeServiceVector alternative_service_vector = |
| 9047 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9048 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9049 | |
| 9050 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9051 | |
| 9052 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9053 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9054 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9055 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9056 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9057 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9058 | |
| 9059 | std::string response_data; |
| 9060 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9061 | EXPECT_EQ("hello world", response_data); |
| 9062 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9063 | alternative_service_vector = |
| 9064 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9065 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9066 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9067 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9068 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9069 | } |
| 9070 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9071 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9072 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9073 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9074 | |
| 9075 | MockRead data_reads[] = { |
| 9076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9077 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9078 | MockRead("hello world"), |
| 9079 | MockRead(SYNCHRONOUS, OK), |
| 9080 | }; |
| 9081 | |
| 9082 | HttpRequestInfo request; |
| 9083 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9084 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9085 | request.load_flags = 0; |
| 9086 | |
| 9087 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9088 | |
| 9089 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9090 | |
| 9091 | TestCompletionCallback callback; |
| 9092 | |
| 9093 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9095 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9096 | HttpServerProperties& http_server_properties = |
| 9097 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9098 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9099 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9100 | http_server_properties.SetAlternativeService( |
| 9101 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9102 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9103 | AlternativeServiceVector alternative_service_vector = |
| 9104 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9105 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9106 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9107 | |
| 9108 | scoped_ptr<HttpTransaction> trans( |
| 9109 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9110 | |
| 9111 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9113 | |
| 9114 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9115 | |
| 9116 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9117 | ASSERT_TRUE(response != NULL); |
| 9118 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9119 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9120 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9121 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9122 | |
| 9123 | std::string response_data; |
| 9124 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9125 | EXPECT_EQ("hello world", response_data); |
| 9126 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9127 | alternative_service_vector = |
| 9128 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9129 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9130 | } |
| 9131 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9132 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9133 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9134 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9135 | |
| 9136 | std::string alternative_service_http_header = |
| 9137 | GetAlternativeServiceHttpHeader(); |
| 9138 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9139 | |
| 9140 | MockRead data_reads[] = { |
| 9141 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9142 | MockRead(alternative_service_http_header.c_str()), |
| 9143 | MockRead(alternate_protocol_http_header.c_str()), |
| 9144 | MockRead("\r\n"), |
| 9145 | MockRead("hello world"), |
| 9146 | MockRead(SYNCHRONOUS, OK), |
| 9147 | }; |
| 9148 | |
| 9149 | HttpRequestInfo request; |
| 9150 | request.method = "GET"; |
| 9151 | request.url = GURL("http://www.example.org/"); |
| 9152 | request.load_flags = 0; |
| 9153 | |
| 9154 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9155 | |
| 9156 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9157 | |
| 9158 | TestCompletionCallback callback; |
| 9159 | |
| 9160 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9161 | scoped_ptr<HttpTransaction> trans( |
| 9162 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9163 | |
| 9164 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9165 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9166 | |
| 9167 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9168 | HttpServerProperties& http_server_properties = |
| 9169 | *session->http_server_properties(); |
| 9170 | AlternativeServiceVector alternative_service_vector = |
| 9171 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9172 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9173 | |
| 9174 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9175 | |
| 9176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9177 | ASSERT_TRUE(response != NULL); |
| 9178 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9179 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9180 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9181 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9182 | |
| 9183 | std::string response_data; |
| 9184 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9185 | EXPECT_EQ("hello world", response_data); |
| 9186 | |
| 9187 | alternative_service_vector = |
| 9188 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9189 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9190 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9191 | alternative_service_vector[0].protocol); |
| 9192 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9193 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9194 | } |
| 9195 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9196 | // When |use_alternative_services| is false, do not observe alternative service |
| 9197 | // entries that point to a different host. |
| 9198 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9199 | session_deps_.use_alternative_services = false; |
| 9200 | |
| 9201 | HttpRequestInfo request; |
| 9202 | request.method = "GET"; |
| 9203 | request.url = GURL("http://www.example.org/"); |
| 9204 | request.load_flags = 0; |
| 9205 | |
| 9206 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9207 | StaticSocketDataProvider first_data; |
| 9208 | first_data.set_connect_data(mock_connect); |
| 9209 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9210 | |
| 9211 | MockRead data_reads[] = { |
| 9212 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9213 | MockRead(ASYNC, OK), |
| 9214 | }; |
| 9215 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9216 | nullptr, 0); |
| 9217 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9218 | |
| 9219 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9220 | |
| 9221 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9222 | session->http_server_properties(); |
| 9223 | AlternativeService alternative_service( |
| 9224 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9225 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9226 | http_server_properties->SetAlternativeService( |
| 9227 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9228 | |
| 9229 | scoped_ptr<HttpTransaction> trans( |
| 9230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9231 | TestCompletionCallback callback; |
| 9232 | |
| 9233 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9234 | // The connetion to origin was refused, and the alternative service should not |
| 9235 | // be used (even though mock data are there), therefore the request should |
| 9236 | // fail. |
| 9237 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9238 | } |
| 9239 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9240 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9241 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9242 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9243 | |
| 9244 | HttpRequestInfo request; |
| 9245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9246 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9247 | request.load_flags = 0; |
| 9248 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9249 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9250 | StaticSocketDataProvider first_data; |
| 9251 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9252 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9253 | |
| 9254 | MockRead data_reads[] = { |
| 9255 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9256 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9257 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9258 | }; |
| 9259 | StaticSocketDataProvider second_data( |
| 9260 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9261 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9262 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9263 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9264 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9265 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9266 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9267 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9268 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9269 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9270 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9271 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9272 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9273 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9274 | http_server_properties->SetAlternativeService( |
| 9275 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9276 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9277 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9279 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9281 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9283 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9284 | |
| 9285 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9286 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9287 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9288 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9289 | |
| 9290 | std::string response_data; |
| 9291 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9292 | EXPECT_EQ("hello world", response_data); |
| 9293 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9294 | const AlternativeServiceVector alternative_service_vector = |
| 9295 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9296 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9297 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9298 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9299 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9300 | } |
| 9301 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9302 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9303 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9304 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9305 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9306 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9307 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9308 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9309 | |
| 9310 | HttpRequestInfo restricted_port_request; |
| 9311 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9312 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9313 | restricted_port_request.load_flags = 0; |
| 9314 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9315 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9316 | StaticSocketDataProvider first_data; |
| 9317 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9318 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9319 | |
| 9320 | MockRead data_reads[] = { |
| 9321 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9322 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9323 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9324 | }; |
| 9325 | StaticSocketDataProvider second_data( |
| 9326 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9327 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9328 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9329 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9330 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9331 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9332 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9333 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9334 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9335 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9336 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9337 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9338 | http_server_properties->SetAlternativeService( |
| 9339 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9340 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9341 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9342 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9343 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9344 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9347 | &restricted_port_request, |
| 9348 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9350 | // Invalid change to unrestricted port should fail. |
| 9351 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9352 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9353 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9354 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9355 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9356 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9357 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9358 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9359 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9360 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9361 | |
| 9362 | HttpRequestInfo restricted_port_request; |
| 9363 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9364 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9365 | restricted_port_request.load_flags = 0; |
| 9366 | |
| 9367 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9368 | StaticSocketDataProvider first_data; |
| 9369 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9370 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9371 | |
| 9372 | MockRead data_reads[] = { |
| 9373 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9374 | MockRead("hello world"), |
| 9375 | MockRead(ASYNC, OK), |
| 9376 | }; |
| 9377 | StaticSocketDataProvider second_data( |
| 9378 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9379 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9380 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9381 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9382 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9383 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9384 | session->http_server_properties(); |
| 9385 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9386 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9387 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9388 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9389 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9390 | http_server_properties->SetAlternativeService( |
| 9391 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9392 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9393 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9394 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9396 | TestCompletionCallback callback; |
| 9397 | |
| 9398 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9399 | &restricted_port_request, |
| 9400 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9401 | // Change to unrestricted port should succeed. |
| 9402 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9403 | } |
| 9404 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9405 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9406 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9407 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9408 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9409 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9410 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9411 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9412 | |
| 9413 | HttpRequestInfo restricted_port_request; |
| 9414 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9415 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9416 | restricted_port_request.load_flags = 0; |
| 9417 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9418 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9419 | StaticSocketDataProvider first_data; |
| 9420 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9421 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9422 | |
| 9423 | MockRead data_reads[] = { |
| 9424 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9425 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9426 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9427 | }; |
| 9428 | StaticSocketDataProvider second_data( |
| 9429 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9430 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9431 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9432 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9433 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9434 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9435 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9436 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9437 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9438 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9439 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9440 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9441 | http_server_properties->SetAlternativeService( |
| 9442 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9443 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9444 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9445 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9446 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9447 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9449 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9450 | &restricted_port_request, |
| 9451 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9453 | // Valid change to restricted port should pass. |
| 9454 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9455 | } |
| 9456 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9457 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9458 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9459 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9460 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9461 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9462 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9463 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9464 | |
| 9465 | HttpRequestInfo unrestricted_port_request; |
| 9466 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9467 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9468 | unrestricted_port_request.load_flags = 0; |
| 9469 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9470 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9471 | StaticSocketDataProvider first_data; |
| 9472 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9473 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9474 | |
| 9475 | MockRead data_reads[] = { |
| 9476 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9477 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9478 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9479 | }; |
| 9480 | StaticSocketDataProvider second_data( |
| 9481 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9482 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9483 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9484 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9485 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9486 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9487 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9488 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9489 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9490 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9491 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9492 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9493 | http_server_properties->SetAlternativeService( |
| 9494 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9495 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9496 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9497 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9498 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9499 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9501 | int rv = trans->Start( |
| 9502 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9503 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9504 | // Valid change to restricted port should pass. |
| 9505 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9506 | } |
| 9507 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9508 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9509 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9510 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9511 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9512 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9513 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9514 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9515 | |
| 9516 | HttpRequestInfo unrestricted_port_request; |
| 9517 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9518 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9519 | unrestricted_port_request.load_flags = 0; |
| 9520 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9521 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9522 | StaticSocketDataProvider first_data; |
| 9523 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9524 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9525 | |
| 9526 | MockRead data_reads[] = { |
| 9527 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9528 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9529 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9530 | }; |
| 9531 | StaticSocketDataProvider second_data( |
| 9532 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9533 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9534 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9535 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9536 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9537 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9538 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 9539 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9540 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9541 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9542 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9543 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9544 | http_server_properties->SetAlternativeService( |
| 9545 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9546 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9547 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9548 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9549 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9550 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9552 | int rv = trans->Start( |
| 9553 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9555 | // Valid change to an unrestricted port should pass. |
| 9556 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9557 | } |
| 9558 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9559 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9560 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 9561 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9562 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9563 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9564 | |
| 9565 | HttpRequestInfo request; |
| 9566 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9567 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9568 | request.load_flags = 0; |
| 9569 | |
| 9570 | // The alternate protocol request will error out before we attempt to connect, |
| 9571 | // so only the standard HTTP request will try to connect. |
| 9572 | MockRead data_reads[] = { |
| 9573 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9575 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9576 | }; |
| 9577 | StaticSocketDataProvider data( |
| 9578 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9579 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9580 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9581 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9582 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9583 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9584 | session->http_server_properties(); |
| 9585 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9586 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9587 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9588 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9589 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9590 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9591 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9592 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9593 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9595 | TestCompletionCallback callback; |
| 9596 | |
| 9597 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9599 | // The HTTP request should succeed. |
| 9600 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9601 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9602 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9603 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9604 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9605 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9606 | |
| 9607 | std::string response_data; |
| 9608 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9609 | EXPECT_EQ("hello world", response_data); |
| 9610 | } |
| 9611 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9612 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9613 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9614 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9615 | |
| 9616 | HttpRequestInfo request; |
| 9617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9618 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9619 | request.load_flags = 0; |
| 9620 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9621 | std::string alternate_protocol_http_header = |
| 9622 | GetAlternateProtocolHttpHeader(); |
| 9623 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9624 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9625 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9626 | MockRead(alternate_protocol_http_header.c_str()), |
| 9627 | MockRead("\r\n"), |
| 9628 | MockRead("hello world"), |
| 9629 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9630 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9631 | |
| 9632 | StaticSocketDataProvider first_transaction( |
| 9633 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9634 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9635 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9636 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9637 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9638 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9639 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9640 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9641 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9642 | scoped_ptr<SpdyFrame> req( |
| 9643 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9644 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9645 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9646 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9647 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9648 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9649 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9650 | }; |
| 9651 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9652 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9653 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9654 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9655 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9656 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9657 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9658 | NULL, 0, NULL, 0); |
| 9659 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9660 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9661 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9662 | &hanging_non_alternate_protocol_socket); |
| 9663 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9664 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9665 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9666 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9667 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9670 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9671 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9672 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9673 | |
| 9674 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9675 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9676 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9677 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9678 | |
| 9679 | std::string response_data; |
| 9680 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9681 | EXPECT_EQ("hello world", response_data); |
| 9682 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9683 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9685 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9687 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9688 | |
| 9689 | response = trans->GetResponseInfo(); |
| 9690 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9691 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9692 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9693 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9694 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9695 | |
| 9696 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9697 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9698 | } |
| 9699 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9700 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9701 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9702 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9703 | |
| 9704 | HttpRequestInfo request; |
| 9705 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9706 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9707 | request.load_flags = 0; |
| 9708 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9709 | std::string alternate_protocol_http_header = |
| 9710 | GetAlternateProtocolHttpHeader(); |
| 9711 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9712 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9713 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9714 | MockRead(alternate_protocol_http_header.c_str()), |
| 9715 | MockRead("\r\n"), |
| 9716 | MockRead("hello world"), |
| 9717 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9718 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9719 | }; |
| 9720 | |
| 9721 | StaticSocketDataProvider first_transaction( |
| 9722 | data_reads, arraysize(data_reads), NULL, 0); |
| 9723 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9724 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9725 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9726 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9727 | StaticSocketDataProvider hanging_socket( |
| 9728 | NULL, 0, NULL, 0); |
| 9729 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9730 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9731 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9732 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9733 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9734 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9735 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9736 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9737 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9738 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9740 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9741 | scoped_ptr<SpdyFrame> req1( |
| 9742 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9743 | scoped_ptr<SpdyFrame> req2( |
| 9744 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9745 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9746 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9747 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9748 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9749 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9750 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9751 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9752 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9753 | CreateMockRead(*resp1, 2), |
| 9754 | CreateMockRead(*data1, 3), |
| 9755 | CreateMockRead(*resp2, 4), |
| 9756 | CreateMockRead(*data2, 5), |
| 9757 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9758 | }; |
| 9759 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9760 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9761 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9762 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9764 | |
| 9765 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9766 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9767 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9768 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9769 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9770 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9772 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9774 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9775 | |
| 9776 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9777 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9778 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9779 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9780 | |
| 9781 | std::string response_data; |
| 9782 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9783 | EXPECT_EQ("hello world", response_data); |
| 9784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9785 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9786 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9787 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9788 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9790 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9791 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9792 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9794 | |
| 9795 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9796 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9797 | |
| 9798 | response = trans2.GetResponseInfo(); |
| 9799 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9800 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9801 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9802 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9803 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9804 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9805 | EXPECT_EQ("hello!", response_data); |
| 9806 | |
| 9807 | response = trans3.GetResponseInfo(); |
| 9808 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9809 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9810 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9811 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9812 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9813 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9814 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9815 | } |
| 9816 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9817 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9818 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9819 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9820 | |
| 9821 | HttpRequestInfo request; |
| 9822 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9823 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9824 | request.load_flags = 0; |
| 9825 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9826 | std::string alternate_protocol_http_header = |
| 9827 | GetAlternateProtocolHttpHeader(); |
| 9828 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9829 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9830 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9831 | MockRead(alternate_protocol_http_header.c_str()), |
| 9832 | MockRead("\r\n"), |
| 9833 | MockRead("hello world"), |
| 9834 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9835 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9836 | }; |
| 9837 | |
| 9838 | StaticSocketDataProvider first_transaction( |
| 9839 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9840 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9841 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9842 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9843 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9845 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9846 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9847 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9848 | NULL, 0, NULL, 0); |
| 9849 | hanging_alternate_protocol_socket.set_connect_data( |
| 9850 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9851 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9852 | &hanging_alternate_protocol_socket); |
| 9853 | |
| 9854 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9855 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9857 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9858 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9859 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9863 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9865 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9866 | |
| 9867 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9868 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9869 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9870 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9871 | |
| 9872 | std::string response_data; |
| 9873 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9874 | EXPECT_EQ("hello world", response_data); |
| 9875 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9876 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9878 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9879 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9880 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9881 | |
| 9882 | response = trans->GetResponseInfo(); |
| 9883 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9884 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9885 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9886 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9887 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9888 | |
| 9889 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9890 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9891 | } |
| 9892 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9893 | class CapturingProxyResolver : public ProxyResolver { |
| 9894 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9895 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9896 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9897 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9898 | int GetProxyForURL(const GURL& url, |
| 9899 | ProxyInfo* results, |
| 9900 | const CompletionCallback& callback, |
| 9901 | RequestHandle* request, |
| 9902 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9903 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9904 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9905 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9906 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9907 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9908 | } |
| 9909 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9910 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9911 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9912 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9913 | NOTREACHED(); |
| 9914 | return LOAD_STATE_IDLE; |
| 9915 | } |
| 9916 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9917 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9918 | |
| 9919 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9920 | std::vector<GURL> resolved_; |
| 9921 | |
| 9922 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9923 | }; |
| 9924 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9925 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9926 | public: |
| 9927 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9928 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9929 | |
| 9930 | int CreateProxyResolver( |
| 9931 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9932 | scoped_ptr<ProxyResolver>* resolver, |
| 9933 | const net::CompletionCallback& callback, |
| 9934 | scoped_ptr<Request>* request) override { |
| 9935 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9936 | return OK; |
| 9937 | } |
| 9938 | |
| 9939 | private: |
| 9940 | ProxyResolver* resolver_; |
| 9941 | }; |
| 9942 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9943 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9944 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9945 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9946 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9947 | |
| 9948 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9949 | proxy_config.set_auto_detect(true); |
| 9950 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9951 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9952 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9953 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9954 | new ProxyConfigServiceFixed(proxy_config), |
| 9955 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9956 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9957 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9958 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9959 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9960 | |
| 9961 | HttpRequestInfo request; |
| 9962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9964 | request.load_flags = 0; |
| 9965 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9966 | std::string alternate_protocol_http_header = |
| 9967 | GetAlternateProtocolHttpHeader(); |
| 9968 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9969 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9971 | MockRead(alternate_protocol_http_header.c_str()), |
| 9972 | MockRead("\r\n"), |
| 9973 | MockRead("hello world"), |
| 9974 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9975 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9976 | }; |
| 9977 | |
| 9978 | StaticSocketDataProvider first_transaction( |
| 9979 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9980 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9981 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9982 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9983 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9984 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9985 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9987 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9988 | scoped_ptr<SpdyFrame> req( |
| 9989 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9990 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9991 | MockWrite(ASYNC, 0, |
| 9992 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9993 | "Host: www.example.org\r\n" |
| 9994 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9995 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9996 | }; |
| 9997 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9998 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9999 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10000 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10001 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10002 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10003 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10004 | CreateMockRead(*resp.get(), 3), |
| 10005 | CreateMockRead(*data.get(), 4), |
| 10006 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10007 | }; |
| 10008 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10009 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10010 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10011 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10012 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10013 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10014 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10015 | NULL, 0, NULL, 0); |
| 10016 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10017 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10018 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10019 | &hanging_non_alternate_protocol_socket); |
| 10020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10021 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10022 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10023 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10024 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10025 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10027 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10028 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10029 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10030 | |
| 10031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10032 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10033 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10034 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10035 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10036 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10037 | |
| 10038 | std::string response_data; |
| 10039 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10040 | EXPECT_EQ("hello world", response_data); |
| 10041 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10042 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10044 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10046 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10047 | |
| 10048 | response = trans->GetResponseInfo(); |
| 10049 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10050 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10051 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10052 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10053 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10054 | |
| 10055 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10056 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10057 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10058 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10059 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10060 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10061 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10062 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10063 | LoadTimingInfo load_timing_info; |
| 10064 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10065 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10066 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10067 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10068 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10069 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10070 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10071 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10072 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10073 | |
| 10074 | HttpRequestInfo request; |
| 10075 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10076 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10077 | request.load_flags = 0; |
| 10078 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10079 | std::string alternate_protocol_http_header = |
| 10080 | GetAlternateProtocolHttpHeader(); |
| 10081 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10082 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10083 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10084 | MockRead(alternate_protocol_http_header.c_str()), |
| 10085 | MockRead("\r\n"), |
| 10086 | MockRead("hello world"), |
| 10087 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10088 | }; |
| 10089 | |
| 10090 | StaticSocketDataProvider first_transaction( |
| 10091 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10092 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10093 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10094 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10095 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10096 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10097 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10099 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10100 | scoped_ptr<SpdyFrame> req( |
| 10101 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10102 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10103 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10104 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10105 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10106 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10107 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10108 | }; |
| 10109 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10110 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10111 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10112 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10113 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10114 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10115 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10116 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10117 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10118 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10121 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10123 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10124 | |
| 10125 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10126 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10127 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10128 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10129 | |
| 10130 | std::string response_data; |
| 10131 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10132 | EXPECT_EQ("hello world", response_data); |
| 10133 | |
| 10134 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10135 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10136 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10137 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10138 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10139 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10140 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10141 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10143 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10145 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10146 | |
| 10147 | response = trans->GetResponseInfo(); |
| 10148 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10149 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10151 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10152 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10153 | |
| 10154 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10155 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10156 | } |
| 10157 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10158 | // GenerateAuthToken is a mighty big test. |
| 10159 | // It tests all permutation of GenerateAuthToken behavior: |
| 10160 | // - Synchronous and Asynchronous completion. |
| 10161 | // - OK or error on completion. |
| 10162 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10163 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10164 | // - Non-authenticating and authenticating backend. |
| 10165 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10166 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10167 | // problems generating an auth token for an authenticating proxy, we don't |
| 10168 | // need to test all permutations of the backend server). |
| 10169 | // |
| 10170 | // The test proceeds by going over each of the configuration cases, and |
| 10171 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10172 | // specifies both the configuration for the test as well as the expectations |
| 10173 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10174 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10175 | static const char kServer[] = "http://www.example.com"; |
| 10176 | static const char kSecureServer[] = "https://www.example.com"; |
| 10177 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10178 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10179 | |
| 10180 | enum AuthTiming { |
| 10181 | AUTH_NONE, |
| 10182 | AUTH_SYNC, |
| 10183 | AUTH_ASYNC, |
| 10184 | }; |
| 10185 | |
| 10186 | const MockWrite kGet( |
| 10187 | "GET / HTTP/1.1\r\n" |
| 10188 | "Host: www.example.com\r\n" |
| 10189 | "Connection: keep-alive\r\n\r\n"); |
| 10190 | const MockWrite kGetProxy( |
| 10191 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10192 | "Host: www.example.com\r\n" |
| 10193 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10194 | const MockWrite kGetAuth( |
| 10195 | "GET / HTTP/1.1\r\n" |
| 10196 | "Host: www.example.com\r\n" |
| 10197 | "Connection: keep-alive\r\n" |
| 10198 | "Authorization: auth_token\r\n\r\n"); |
| 10199 | const MockWrite kGetProxyAuth( |
| 10200 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10201 | "Host: www.example.com\r\n" |
| 10202 | "Proxy-Connection: keep-alive\r\n" |
| 10203 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10204 | const MockWrite kGetAuthThroughProxy( |
| 10205 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10206 | "Host: www.example.com\r\n" |
| 10207 | "Proxy-Connection: keep-alive\r\n" |
| 10208 | "Authorization: auth_token\r\n\r\n"); |
| 10209 | const MockWrite kGetAuthWithProxyAuth( |
| 10210 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10211 | "Host: www.example.com\r\n" |
| 10212 | "Proxy-Connection: keep-alive\r\n" |
| 10213 | "Proxy-Authorization: auth_token\r\n" |
| 10214 | "Authorization: auth_token\r\n\r\n"); |
| 10215 | const MockWrite kConnect( |
| 10216 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10217 | "Host: www.example.com\r\n" |
| 10218 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10219 | const MockWrite kConnectProxyAuth( |
| 10220 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10221 | "Host: www.example.com\r\n" |
| 10222 | "Proxy-Connection: keep-alive\r\n" |
| 10223 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10224 | |
| 10225 | const MockRead kSuccess( |
| 10226 | "HTTP/1.1 200 OK\r\n" |
| 10227 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10228 | "Content-Length: 3\r\n\r\n" |
| 10229 | "Yes"); |
| 10230 | const MockRead kFailure( |
| 10231 | "Should not be called."); |
| 10232 | const MockRead kServerChallenge( |
| 10233 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10234 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10235 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10236 | "Content-Length: 14\r\n\r\n" |
| 10237 | "Unauthorized\r\n"); |
| 10238 | const MockRead kProxyChallenge( |
| 10239 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10240 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10241 | "Proxy-Connection: close\r\n" |
| 10242 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10243 | "Content-Length: 14\r\n\r\n" |
| 10244 | "Unauthorized\r\n"); |
| 10245 | const MockRead kProxyConnected( |
| 10246 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10247 | |
| 10248 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10249 | // no constructors, but the C++ compiler on Windows warns about |
| 10250 | // unspecified data in compound literals. So, moved to using constructors, |
| 10251 | // and TestRound's created with the default constructor should not be used. |
| 10252 | struct TestRound { |
| 10253 | TestRound() |
| 10254 | : expected_rv(ERR_UNEXPECTED), |
| 10255 | extra_write(NULL), |
| 10256 | extra_read(NULL) { |
| 10257 | } |
| 10258 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10259 | int expected_rv_arg) |
| 10260 | : write(write_arg), |
| 10261 | read(read_arg), |
| 10262 | expected_rv(expected_rv_arg), |
| 10263 | extra_write(NULL), |
| 10264 | extra_read(NULL) { |
| 10265 | } |
| 10266 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10267 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10268 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10269 | : write(write_arg), |
| 10270 | read(read_arg), |
| 10271 | expected_rv(expected_rv_arg), |
| 10272 | extra_write(extra_write_arg), |
| 10273 | extra_read(extra_read_arg) { |
| 10274 | } |
| 10275 | MockWrite write; |
| 10276 | MockRead read; |
| 10277 | int expected_rv; |
| 10278 | const MockWrite* extra_write; |
| 10279 | const MockRead* extra_read; |
| 10280 | }; |
| 10281 | |
| 10282 | static const int kNoSSL = 500; |
| 10283 | |
| 10284 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10285 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10286 | AuthTiming proxy_auth_timing; |
| 10287 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10288 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10289 | AuthTiming server_auth_timing; |
| 10290 | int server_auth_rv; |
| 10291 | int num_auth_rounds; |
| 10292 | int first_ssl_round; |
| 10293 | TestRound rounds[3]; |
| 10294 | } test_configs[] = { |
| 10295 | // Non-authenticating HTTP server with a direct connection. |
| 10296 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10297 | { TestRound(kGet, kSuccess, OK)}}, |
| 10298 | // Authenticating HTTP server with a direct connection. |
| 10299 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10300 | { TestRound(kGet, kServerChallenge, OK), |
| 10301 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10302 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10303 | { TestRound(kGet, kServerChallenge, OK), |
| 10304 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10305 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10306 | { TestRound(kGet, kServerChallenge, OK), |
| 10307 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10308 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10309 | { TestRound(kGet, kServerChallenge, OK), |
| 10310 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10311 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10312 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10313 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10314 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10315 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10316 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10317 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10318 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10319 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10320 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10321 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10322 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10323 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10324 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10325 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10326 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10327 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10328 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10329 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10330 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10331 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10332 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10333 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10334 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10335 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10336 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10337 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10338 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10339 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10340 | // Authenticating HTTP server through an authenticating proxy. |
| 10341 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10342 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10343 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10344 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10345 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10346 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10347 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10348 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10349 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10350 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10351 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10352 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10353 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10354 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10355 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10356 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10357 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10358 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10359 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10360 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10361 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10362 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10363 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10364 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10365 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10366 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10367 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10368 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10369 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10370 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10371 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10372 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10373 | // Non-authenticating HTTPS server with a direct connection. |
| 10374 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10375 | { TestRound(kGet, kSuccess, OK)}}, |
| 10376 | // Authenticating HTTPS server with a direct connection. |
| 10377 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10378 | { TestRound(kGet, kServerChallenge, OK), |
| 10379 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10380 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10381 | { TestRound(kGet, kServerChallenge, OK), |
| 10382 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10383 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10384 | { TestRound(kGet, kServerChallenge, OK), |
| 10385 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10386 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10387 | { TestRound(kGet, kServerChallenge, OK), |
| 10388 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10389 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10390 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10391 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10392 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10393 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10394 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10395 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10396 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10397 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10398 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10399 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10400 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10401 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10402 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10403 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10404 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10405 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10406 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10407 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10408 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10409 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10410 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10411 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10412 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10413 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10414 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10415 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10416 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10417 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10418 | // Authenticating HTTPS server through an authenticating proxy. |
| 10419 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10420 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10421 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10422 | &kGet, &kServerChallenge), |
| 10423 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10424 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10425 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10426 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10427 | &kGet, &kServerChallenge), |
| 10428 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10429 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10430 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10431 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10432 | &kGet, &kServerChallenge), |
| 10433 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10434 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10435 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10436 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10437 | &kGet, &kServerChallenge), |
| 10438 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10439 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10440 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10441 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10442 | &kGet, &kServerChallenge), |
| 10443 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10444 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10445 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10446 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10447 | &kGet, &kServerChallenge), |
| 10448 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10449 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10450 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10451 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10452 | &kGet, &kServerChallenge), |
| 10453 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10454 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10455 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10456 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10457 | &kGet, &kServerChallenge), |
| 10458 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10459 | }; |
| 10460 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10461 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10462 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10463 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10464 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10465 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10466 | |
| 10467 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10468 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10469 | for (int n = 0; n < 2; n++) { |
| 10470 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10471 | std::string auth_challenge = "Mock realm=proxy"; |
| 10472 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10473 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10474 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10475 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10476 | origin, BoundNetLog()); |
| 10477 | auth_handler->SetGenerateExpectation( |
| 10478 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10479 | test_config.proxy_auth_rv); |
| 10480 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10481 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10482 | } |
| 10483 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10484 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10485 | std::string auth_challenge = "Mock realm=server"; |
| 10486 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10487 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10488 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10489 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10490 | origin, BoundNetLog()); |
| 10491 | auth_handler->SetGenerateExpectation( |
| 10492 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10493 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10494 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10495 | } |
| 10496 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10497 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10498 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10499 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10500 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10501 | } |
| 10502 | |
| 10503 | HttpRequestInfo request; |
| 10504 | request.method = "GET"; |
| 10505 | request.url = GURL(test_config.server_url); |
| 10506 | request.load_flags = 0; |
| 10507 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10508 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10509 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10510 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10511 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10512 | |
| 10513 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10514 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10515 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10516 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10517 | |
| 10518 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10519 | mock_reads.back().push_back(read_write_round.read); |
| 10520 | mock_writes.back().push_back(read_write_round.write); |
| 10521 | |
| 10522 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10523 | // socket is closed and a new one will be created for the next request. |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 10524 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10525 | mock_reads.push_back(std::vector<MockRead>()); |
| 10526 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10527 | } |
| 10528 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10529 | if (read_write_round.extra_read) { |
| 10530 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10531 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10532 | if (read_write_round.extra_write) { |
| 10533 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10534 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10535 | |
| 10536 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10537 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10538 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10539 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10540 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10541 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10542 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10543 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10544 | data_providers.push_back(new StaticSocketDataProvider( |
| 10545 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10546 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10547 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10548 | data_providers.back()); |
| 10549 | } |
| 10550 | |
| 10551 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10552 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10553 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10554 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10555 | int rv; |
| 10556 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10557 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10558 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10559 | rv = trans.RestartWithAuth( |
| 10560 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10561 | } |
| 10562 | if (rv == ERR_IO_PENDING) |
| 10563 | rv = callback.WaitForResult(); |
| 10564 | |
| 10565 | // Compare results with expected data. |
| 10566 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10567 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10568 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10569 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10570 | continue; |
| 10571 | } |
| 10572 | if (round + 1 < test_config.num_auth_rounds) { |
| 10573 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10574 | } else { |
| 10575 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10576 | } |
| 10577 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10578 | } |
| 10579 | } |
| 10580 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10581 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10582 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10583 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10584 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10585 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10586 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10587 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10588 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10589 | |
| 10590 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10591 | auth_handler->set_connection_based(true); |
| 10592 | std::string auth_challenge = "Mock realm=server"; |
| 10593 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10594 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10595 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10596 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10597 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10598 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10599 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10600 | int rv = OK; |
| 10601 | const HttpResponseInfo* response = NULL; |
| 10602 | HttpRequestInfo request; |
| 10603 | request.method = "GET"; |
| 10604 | request.url = origin; |
| 10605 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10606 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10607 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10608 | |
| 10609 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10610 | // to validate that the TCP socket is not released to the pool between |
| 10611 | // each round of multi-round authentication. |
| 10612 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10613 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10614 | 50, // Max sockets for pool |
| 10615 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10616 | session_deps_.host_resolver.get(), |
| 10617 | session_deps_.socket_factory.get(), |
| 10618 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10619 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10620 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10621 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10622 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10623 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10624 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10625 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10626 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10627 | |
| 10628 | const MockWrite kGet( |
| 10629 | "GET / HTTP/1.1\r\n" |
| 10630 | "Host: www.example.com\r\n" |
| 10631 | "Connection: keep-alive\r\n\r\n"); |
| 10632 | const MockWrite kGetAuth( |
| 10633 | "GET / HTTP/1.1\r\n" |
| 10634 | "Host: www.example.com\r\n" |
| 10635 | "Connection: keep-alive\r\n" |
| 10636 | "Authorization: auth_token\r\n\r\n"); |
| 10637 | |
| 10638 | const MockRead kServerChallenge( |
| 10639 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10640 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10641 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10642 | "Content-Length: 14\r\n\r\n" |
| 10643 | "Unauthorized\r\n"); |
| 10644 | const MockRead kSuccess( |
| 10645 | "HTTP/1.1 200 OK\r\n" |
| 10646 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10647 | "Content-Length: 3\r\n\r\n" |
| 10648 | "Yes"); |
| 10649 | |
| 10650 | MockWrite writes[] = { |
| 10651 | // First round |
| 10652 | kGet, |
| 10653 | // Second round |
| 10654 | kGetAuth, |
| 10655 | // Third round |
| 10656 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10657 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10658 | kGetAuth, |
| 10659 | // Competing request |
| 10660 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10661 | }; |
| 10662 | MockRead reads[] = { |
| 10663 | // First round |
| 10664 | kServerChallenge, |
| 10665 | // Second round |
| 10666 | kServerChallenge, |
| 10667 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10668 | kServerChallenge, |
| 10669 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10670 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10671 | // Competing response |
| 10672 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10673 | }; |
| 10674 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10675 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10676 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10677 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10678 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10679 | |
| 10680 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10681 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10682 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10683 | if (rv == ERR_IO_PENDING) |
| 10684 | rv = callback.WaitForResult(); |
| 10685 | EXPECT_EQ(OK, rv); |
| 10686 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10687 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10688 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10689 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10690 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10691 | // In between rounds, another request comes in for the same domain. |
| 10692 | // It should not be able to grab the TCP socket that trans has already |
| 10693 | // claimed. |
| 10694 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10696 | TestCompletionCallback callback_compete; |
| 10697 | rv = trans_compete->Start( |
| 10698 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10699 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10700 | // callback_compete.WaitForResult at this point would stall forever, |
| 10701 | // since the HttpNetworkTransaction does not release the request back to |
| 10702 | // the pool until after authentication completes. |
| 10703 | |
| 10704 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10705 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10706 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10707 | if (rv == ERR_IO_PENDING) |
| 10708 | rv = callback.WaitForResult(); |
| 10709 | EXPECT_EQ(OK, rv); |
| 10710 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10711 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10712 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10713 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10714 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10715 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10716 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10717 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10718 | if (rv == ERR_IO_PENDING) |
| 10719 | rv = callback.WaitForResult(); |
| 10720 | EXPECT_EQ(OK, rv); |
| 10721 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10722 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10723 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10724 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10725 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10726 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10727 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10728 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10729 | if (rv == ERR_IO_PENDING) |
| 10730 | rv = callback.WaitForResult(); |
| 10731 | EXPECT_EQ(OK, rv); |
| 10732 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10733 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10734 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10735 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10736 | |
| 10737 | // Read the body since the fourth round was successful. This will also |
| 10738 | // release the socket back to the pool. |
| 10739 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10740 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10741 | if (rv == ERR_IO_PENDING) |
| 10742 | rv = callback.WaitForResult(); |
| 10743 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10744 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10745 | EXPECT_EQ(0, rv); |
| 10746 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10747 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10748 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10749 | |
| 10750 | // The competing request can now finish. Wait for the headers and then |
| 10751 | // read the body. |
| 10752 | rv = callback_compete.WaitForResult(); |
| 10753 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10754 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10755 | if (rv == ERR_IO_PENDING) |
| 10756 | rv = callback.WaitForResult(); |
| 10757 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10758 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10759 | EXPECT_EQ(0, rv); |
| 10760 | |
| 10761 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10762 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10763 | } |
| 10764 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10765 | // This tests the case that a request is issued via http instead of spdy after |
| 10766 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10767 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10768 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10769 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10770 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10771 | session_deps_.next_protos = next_protos; |
| 10772 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10773 | HttpRequestInfo request; |
| 10774 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10775 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10776 | request.load_flags = 0; |
| 10777 | |
| 10778 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10779 | MockWrite( |
| 10780 | "GET / HTTP/1.1\r\n" |
| 10781 | "Host: www.example.org\r\n" |
| 10782 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10783 | }; |
| 10784 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10785 | std::string alternate_protocol_http_header = |
| 10786 | GetAlternateProtocolHttpHeader(); |
| 10787 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10788 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10790 | MockRead(alternate_protocol_http_header.c_str()), |
| 10791 | MockRead("\r\n"), |
| 10792 | MockRead("hello world"), |
| 10793 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10794 | }; |
| 10795 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10796 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10797 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10798 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10799 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10800 | |
| 10801 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10802 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10805 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10806 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10807 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10808 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10809 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10811 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10812 | |
| 10813 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10814 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10815 | |
| 10816 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10817 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10818 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10819 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10820 | |
| 10821 | std::string response_data; |
| 10822 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10823 | EXPECT_EQ("hello world", response_data); |
| 10824 | |
| 10825 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10826 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10827 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10828 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10829 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 10830 | // immediate server closing of the socket. |
| 10831 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10832 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10833 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10834 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10835 | |
| 10836 | HttpRequestInfo request; |
| 10837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10838 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10839 | request.load_flags = 0; |
| 10840 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10841 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10842 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10844 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10845 | scoped_ptr<SpdyFrame> req( |
| 10846 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10847 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10848 | |
| 10849 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10850 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10851 | }; |
| 10852 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10853 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10854 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10855 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10857 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10858 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10863 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10865 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10866 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10867 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10868 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10869 | // it gets it. This is needed since the auth handler may get destroyed |
| 10870 | // before we get a chance to query it. |
| 10871 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10872 | public: |
| 10873 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10874 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10875 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10876 | |
| 10877 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10878 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10879 | const HttpRequestInfo* request, |
| 10880 | const CompletionCallback& callback, |
| 10881 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10882 | *url_ = request->url; |
| 10883 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10884 | credentials, request, callback, auth_token); |
| 10885 | } |
| 10886 | |
| 10887 | private: |
| 10888 | GURL* url_; |
| 10889 | }; |
| 10890 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10891 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 10892 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10893 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10894 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10895 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10896 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10897 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10898 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10899 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10900 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10901 | GURL request_url; |
| 10902 | { |
| 10903 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10904 | new HttpAuthHandlerMock::Factory(); |
| 10905 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10906 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10907 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10908 | auth_factory->set_do_init_from_challenge(true); |
| 10909 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10910 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10911 | |
| 10912 | HttpRequestInfo request; |
| 10913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10914 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10915 | request.load_flags = 0; |
| 10916 | |
| 10917 | // First round goes unauthenticated through the proxy. |
| 10918 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10919 | MockWrite( |
| 10920 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10921 | "Host: www.example.org\r\n" |
| 10922 | "Proxy-Connection: keep-alive\r\n" |
| 10923 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10924 | }; |
| 10925 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10926 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10927 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10928 | MockRead("Alternate-Protocol: 443:"), |
| 10929 | MockRead(GetAlternateProtocolFromParam()), |
| 10930 | MockRead("\r\n"), |
| 10931 | MockRead("Proxy-Connection: close\r\n"), |
| 10932 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10933 | }; |
| 10934 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10935 | data_writes_1, arraysize(data_writes_1)); |
| 10936 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10937 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10938 | // Alternate-Protocol announcement in the first round. It fails due |
| 10939 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10940 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10941 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10942 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10943 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10944 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10945 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10946 | // to obtain a new one. |
| 10947 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10948 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10949 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10950 | // establishment and SPDY framing issues. Alas, the |
| 10951 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10952 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10953 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10954 | scoped_ptr<SpdyFrame> req( |
| 10955 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10956 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10957 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10958 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10959 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10960 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10961 | MockWrite(ASYNC, 0, |
| 10962 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10963 | "Host: www.example.org\r\n" |
| 10964 | "Proxy-Connection: keep-alive\r\n" |
| 10965 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10966 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10967 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10968 | MockWrite(ASYNC, 2, |
| 10969 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10970 | "Host: www.example.org\r\n" |
| 10971 | "Proxy-Connection: keep-alive\r\n" |
| 10972 | "Proxy-Authorization: auth_token\r\n" |
| 10973 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10974 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10975 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10976 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10977 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10978 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10979 | // First connection attempt fails |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 10980 | MockRead(ASYNC, 1, |
| 10981 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10982 | "Proxy-Authenticate: Mock\r\n" |
| 10983 | "Content-Length: 0\r\n" |
| 10984 | "Proxy-Connection: keep-alive\r\n" |
| 10985 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10986 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10987 | // Second connection attempt passes |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 10988 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10989 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10990 | // SPDY response |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 10991 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10992 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10993 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10994 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 10995 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10996 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10997 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10998 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10999 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11000 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11001 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11002 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11003 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11004 | NULL, 0, NULL, 0); |
| 11005 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11006 | never_finishing_connect); |
| 11007 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11008 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11009 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11011 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11012 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11013 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11014 | |
| 11015 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11016 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11017 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11019 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11020 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11021 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11022 | |
| 11023 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11024 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11025 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11026 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11027 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11028 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11029 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11030 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11031 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11032 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11033 | |
| 11034 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11035 | TestCompletionCallback callback_3; |
| 11036 | rv = trans_2->RestartWithAuth( |
| 11037 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11038 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11039 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11040 | |
| 11041 | // After all that work, these two lines (or actually, just the scheme) are |
| 11042 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11043 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11044 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11045 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11046 | LoadTimingInfo load_timing_info; |
| 11047 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11048 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11049 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11050 | } |
| 11051 | |
| 11052 | // Test that if we cancel the transaction as the connection is completing, that |
| 11053 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11054 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11055 | // Setup everything about the connection to complete synchronously, so that |
| 11056 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11057 | // for is the callback from the HttpStreamRequest. |
| 11058 | // Then cancel the transaction. |
| 11059 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11060 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11061 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11062 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11063 | MockRead(SYNCHRONOUS, "hello world"), |
| 11064 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11065 | }; |
| 11066 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11067 | HttpRequestInfo request; |
| 11068 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11069 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11070 | request.load_flags = 0; |
| 11071 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11072 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11073 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11074 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11075 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11076 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11077 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11078 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11081 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11082 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11083 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11084 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11085 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11086 | trans.reset(); // Cancel the transaction here. |
| 11087 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11088 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11089 | } |
| 11090 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11091 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11092 | // stream is drained properly and added back to the socket pool. The main |
| 11093 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11094 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11095 | // deleted. |
| 11096 | // See http://crbug.com/368418 |
| 11097 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11098 | MockRead data_reads[] = { |
| 11099 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11100 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11101 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11102 | MockRead(ASYNC, "1"), |
| 11103 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11104 | // HttpNetworkTransaction has been deleted. |
| 11105 | MockRead(ASYNC, "2"), |
| 11106 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11107 | }; |
| 11108 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11110 | |
| 11111 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11112 | |
| 11113 | { |
| 11114 | HttpRequestInfo request; |
| 11115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11116 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11117 | request.load_flags = 0; |
| 11118 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11120 | TestCompletionCallback callback; |
| 11121 | |
| 11122 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11123 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11124 | callback.WaitForResult(); |
| 11125 | |
| 11126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11127 | ASSERT_TRUE(response != NULL); |
| 11128 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11130 | |
| 11131 | // The transaction and HttpRequestInfo are deleted. |
| 11132 | } |
| 11133 | |
| 11134 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11135 | base::MessageLoop::current()->RunUntilIdle(); |
| 11136 | |
| 11137 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11138 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11139 | } |
| 11140 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11141 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11142 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11143 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11144 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11145 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11146 | session_deps_.net_log = log.bound().net_log(); |
| 11147 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11148 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11149 | HttpRequestInfo request; |
| 11150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11151 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11152 | |
| 11153 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11154 | MockWrite( |
| 11155 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11156 | "Host: www.example.org\r\n" |
| 11157 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11158 | }; |
| 11159 | |
| 11160 | MockRead data_reads1[] = { |
| 11161 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11162 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11163 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11165 | }; |
| 11166 | |
| 11167 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11168 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11171 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11172 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11173 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11174 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11175 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11176 | trans->SetBeforeProxyHeadersSentCallback( |
| 11177 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11178 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11180 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11182 | |
| 11183 | rv = callback1.WaitForResult(); |
| 11184 | EXPECT_EQ(OK, rv); |
| 11185 | |
| 11186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11187 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11188 | |
| 11189 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11190 | EXPECT_EQ(200, response->headers->response_code()); |
| 11191 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11192 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11193 | EXPECT_TRUE( |
| 11194 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11195 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11196 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11197 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11198 | |
| 11199 | LoadTimingInfo load_timing_info; |
| 11200 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11201 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11202 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11203 | } |
| 11204 | |
| 11205 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11206 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11207 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11208 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11209 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11210 | session_deps_.net_log = log.bound().net_log(); |
| 11211 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11212 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11213 | HttpRequestInfo request; |
| 11214 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11215 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11216 | |
| 11217 | // Since we have proxy, should try to establish tunnel. |
| 11218 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11219 | MockWrite( |
| 11220 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11221 | "Host: www.example.org\r\n" |
| 11222 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11223 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11224 | MockWrite( |
| 11225 | "GET / HTTP/1.1\r\n" |
| 11226 | "Host: www.example.org\r\n" |
| 11227 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11228 | }; |
| 11229 | |
| 11230 | MockRead data_reads1[] = { |
| 11231 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11232 | |
| 11233 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11234 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11235 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11236 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11237 | }; |
| 11238 | |
| 11239 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11240 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11241 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11242 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11243 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11245 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11246 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11247 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11250 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11251 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11252 | |
| 11253 | rv = callback1.WaitForResult(); |
| 11254 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11255 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11256 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11257 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11258 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11259 | NetLog::PHASE_NONE); |
| 11260 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11261 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11262 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11263 | NetLog::PHASE_NONE); |
| 11264 | |
| 11265 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11266 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11267 | |
| 11268 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11269 | EXPECT_EQ(200, response->headers->response_code()); |
| 11270 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11271 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11272 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11273 | EXPECT_TRUE( |
| 11274 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11275 | |
| 11276 | LoadTimingInfo load_timing_info; |
| 11277 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11278 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11279 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11280 | } |
| 11281 | |
| 11282 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11283 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11284 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11285 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11286 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11287 | session_deps_.net_log = log.bound().net_log(); |
| 11288 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11289 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11290 | HttpRequestInfo request; |
| 11291 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11292 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11293 | |
| 11294 | // Since we have proxy, should try to establish tunnel. |
| 11295 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11296 | MockWrite( |
| 11297 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11298 | "Host: www.example.org\r\n" |
| 11299 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11300 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11301 | MockWrite( |
| 11302 | "GET / HTTP/1.1\r\n" |
| 11303 | "Host: www.example.org\r\n" |
| 11304 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11305 | }; |
| 11306 | |
| 11307 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11308 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11309 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11310 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11311 | }; |
| 11312 | |
| 11313 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11314 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11315 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11316 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11319 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11320 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11321 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11322 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11323 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11324 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11325 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11326 | |
| 11327 | rv = callback1.WaitForResult(); |
| 11328 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11329 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11330 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11331 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11332 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11333 | NetLog::PHASE_NONE); |
| 11334 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11335 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11336 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11337 | NetLog::PHASE_NONE); |
| 11338 | } |
| 11339 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11340 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11341 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11342 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11343 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11344 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11345 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11346 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11347 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11348 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11349 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11350 | }; |
| 11351 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11352 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11353 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11354 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11355 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11356 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11357 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11359 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11360 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11361 | |
| 11362 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11363 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11364 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11365 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11366 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11367 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11368 | |
| 11369 | HttpRequestInfo request; |
| 11370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11371 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11372 | request.load_flags = 0; |
| 11373 | |
| 11374 | // This is the important line that marks this as a preconnect. |
| 11375 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11376 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11377 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11379 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11380 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11381 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11382 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11383 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11384 | } |
| 11385 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11386 | // Given a net error, cause that error to be returned from the first Write() |
| 11387 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11388 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11389 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11390 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11391 | request_info.url = GURL("https://www.example.com/"); |
| 11392 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11393 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11394 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11395 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11396 | MockWrite data_writes[] = { |
| 11397 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11398 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11399 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11400 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11402 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11403 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11404 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11405 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11407 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11408 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11409 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11410 | rv = callback.WaitForResult(); |
| 11411 | ASSERT_EQ(error, rv); |
| 11412 | } |
| 11413 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11414 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11415 | // Just check a grab bag of cert errors. |
| 11416 | static const int kErrors[] = { |
| 11417 | ERR_CERT_COMMON_NAME_INVALID, |
| 11418 | ERR_CERT_AUTHORITY_INVALID, |
| 11419 | ERR_CERT_DATE_INVALID, |
| 11420 | }; |
| 11421 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11422 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11423 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11424 | } |
| 11425 | } |
| 11426 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11427 | // Ensure that a client certificate is removed from the SSL client auth |
| 11428 | // cache when: |
| 11429 | // 1) No proxy is involved. |
| 11430 | // 2) TLS False Start is disabled. |
| 11431 | // 3) The initial TLS handshake requests a client certificate. |
| 11432 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11433 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11434 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11435 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11436 | request_info.url = GURL("https://www.example.com/"); |
| 11437 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11438 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11439 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11440 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11441 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11442 | |
| 11443 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11444 | // CertificateRequest is received for the first time, the handshake will |
| 11445 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11446 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11447 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11449 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11450 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11451 | |
| 11452 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11453 | // False Start is not being used, the result of the SSL handshake will be |
| 11454 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11455 | // matches the result of a server sending a handshake_failure alert, |
| 11456 | // rather than a Finished message, because it requires a client |
| 11457 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11458 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11459 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11461 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11462 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11463 | |
| 11464 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11465 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11466 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11467 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11468 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11469 | // requiring a client certificate, this fallback handshake should also |
| 11470 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11471 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11472 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11474 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11475 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11476 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11477 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11478 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11479 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11480 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11481 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11482 | // requiring a client certificate, this fallback handshake should also |
| 11483 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11484 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11485 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11487 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11488 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11489 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11490 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11491 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11492 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11493 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11494 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11495 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11496 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11497 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11498 | |
| 11499 | // Complete the SSL handshake, which should abort due to requiring a |
| 11500 | // client certificate. |
| 11501 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11502 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11503 | |
| 11504 | // Indicate that no certificate should be supplied. From the perspective |
| 11505 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11506 | // certificate, so this is the same as supply a |
| 11507 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11508 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11509 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11510 | |
| 11511 | // Ensure the certificate was added to the client auth cache before |
| 11512 | // allowing the connection to continue restarting. |
| 11513 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11514 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11515 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11516 | ASSERT_EQ(NULL, client_cert.get()); |
| 11517 | |
| 11518 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11519 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11520 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11521 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11522 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11523 | |
| 11524 | // Ensure that the client certificate is removed from the cache on a |
| 11525 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11526 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11527 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11528 | } |
| 11529 | |
| 11530 | // Ensure that a client certificate is removed from the SSL client auth |
| 11531 | // cache when: |
| 11532 | // 1) No proxy is involved. |
| 11533 | // 2) TLS False Start is enabled. |
| 11534 | // 3) The initial TLS handshake requests a client certificate. |
| 11535 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11536 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11537 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11538 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11539 | request_info.url = GURL("https://www.example.com/"); |
| 11540 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11541 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11542 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11543 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11544 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11545 | |
| 11546 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11547 | // return successfully after reading up to the peer's Certificate message. |
| 11548 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11549 | // enqueue application data to be sent in the same packet as the |
| 11550 | // ChangeCipherSpec and Finished messages. |
| 11551 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11552 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11553 | // Finished messages. If there was an error negotiating with the peer, |
| 11554 | // such as due to the peer requiring a client certificate when none was |
| 11555 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11556 | // called. |
| 11557 | |
| 11558 | // Like the non-False Start case, when a client certificate is requested by |
| 11559 | // the peer, the handshake is aborted during the Connect() call. |
| 11560 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11561 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11562 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11563 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11564 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11566 | |
| 11567 | // When a client certificate is supplied, Connect() will not be aborted |
| 11568 | // when the peer requests the certificate. Instead, the handshake will |
| 11569 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11570 | // the socket. The handshake messages are not processed until Read() is |
| 11571 | // called, which then detects that the handshake was aborted, due to the |
| 11572 | // peer sending a handshake_failure because it requires a client |
| 11573 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11574 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11575 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11577 | MockRead data2_reads[] = { |
| 11578 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11579 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11580 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11581 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11582 | |
| 11583 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11584 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11585 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11586 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11587 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11588 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11589 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11590 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11591 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11592 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11593 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11594 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11595 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11597 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11598 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11599 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11600 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11601 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11602 | ssl_data5.cert_request_info = cert_request.get(); |
| 11603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11604 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11605 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11606 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11607 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11608 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11610 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11611 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11612 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11613 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11614 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11615 | |
| 11616 | // Complete the SSL handshake, which should abort due to requiring a |
| 11617 | // client certificate. |
| 11618 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11619 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11620 | |
| 11621 | // Indicate that no certificate should be supplied. From the perspective |
| 11622 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11623 | // certificate, so this is the same as supply a |
| 11624 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11625 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11626 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11627 | |
| 11628 | // Ensure the certificate was added to the client auth cache before |
| 11629 | // allowing the connection to continue restarting. |
| 11630 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11631 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11632 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11633 | ASSERT_EQ(NULL, client_cert.get()); |
| 11634 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11635 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11636 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11637 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11638 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11639 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11640 | |
| 11641 | // Ensure that the client certificate is removed from the cache on a |
| 11642 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11643 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11644 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11645 | } |
| 11646 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11647 | // Ensure that a client certificate is removed from the SSL client auth |
| 11648 | // cache when: |
| 11649 | // 1) An HTTPS proxy is involved. |
| 11650 | // 3) The HTTPS proxy requests a client certificate. |
| 11651 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11652 | // proxy. |
| 11653 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11654 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11655 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11656 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11657 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11658 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11659 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11660 | |
| 11661 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11662 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11663 | |
| 11664 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11665 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11666 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11667 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11668 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11669 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11670 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11671 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11672 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11673 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11674 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11675 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11676 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11677 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11678 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11679 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11680 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11681 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11682 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11683 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11685 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11686 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11687 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11688 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11689 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11690 | requests[0].url = GURL("https://www.example.com/"); |
| 11691 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11692 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11693 | |
| 11694 | requests[1].url = GURL("http://www.example.com/"); |
| 11695 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11696 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11697 | |
| 11698 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11699 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11700 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11701 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11702 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11703 | |
| 11704 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11705 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11706 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11707 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11708 | |
| 11709 | // Complete the SSL handshake, which should abort due to requiring a |
| 11710 | // client certificate. |
| 11711 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11712 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11713 | |
| 11714 | // Indicate that no certificate should be supplied. From the perspective |
| 11715 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11716 | // certificate, so this is the same as supply a |
| 11717 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11718 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11719 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11720 | |
| 11721 | // Ensure the certificate was added to the client auth cache before |
| 11722 | // allowing the connection to continue restarting. |
| 11723 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11724 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11725 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11726 | ASSERT_EQ(NULL, client_cert.get()); |
| 11727 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11728 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11729 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11730 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11731 | |
| 11732 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11733 | // then consume ssl_data3, which should also fail. The result code is |
| 11734 | // checked against what ssl_data3 should return. |
| 11735 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11736 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11737 | |
| 11738 | // Now that the new handshake has failed, ensure that the client |
| 11739 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11740 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11741 | HostPortPair("proxy", 70), &client_cert)); |
| 11742 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11743 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11744 | } |
| 11745 | } |
| 11746 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11747 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11748 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11749 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11750 | |
| 11751 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11752 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11753 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11754 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11755 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11756 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11757 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11758 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11760 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11761 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11762 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11763 | scoped_ptr<SpdyFrame> host2_req( |
| 11764 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11765 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11766 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11767 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11768 | scoped_ptr<SpdyFrame> host1_resp( |
| 11769 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11770 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11771 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11772 | scoped_ptr<SpdyFrame> host2_resp( |
| 11773 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11774 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11775 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11776 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11777 | CreateMockRead(*host1_resp, 1), |
| 11778 | CreateMockRead(*host1_resp_body, 2), |
| 11779 | CreateMockRead(*host2_resp, 4), |
| 11780 | CreateMockRead(*host2_resp_body, 5), |
| 11781 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11782 | }; |
| 11783 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11784 | IPAddressNumber ip; |
| 11785 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11786 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11787 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11788 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11789 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11790 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11791 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11792 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11793 | HttpRequestInfo request1; |
| 11794 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11795 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11796 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11797 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11799 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11801 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11802 | |
| 11803 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11804 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11805 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11806 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11807 | |
| 11808 | std::string response_data; |
| 11809 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11810 | EXPECT_EQ("hello!", response_data); |
| 11811 | |
| 11812 | // Preload www.gmail.com into HostCache. |
| 11813 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11814 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11815 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11816 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11817 | DEFAULT_PRIORITY, |
| 11818 | &ignored, |
| 11819 | callback.callback(), |
| 11820 | NULL, |
| 11821 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11822 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11823 | rv = callback.WaitForResult(); |
| 11824 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11825 | |
| 11826 | HttpRequestInfo request2; |
| 11827 | request2.method = "GET"; |
| 11828 | request2.url = GURL("https://www.gmail.com/"); |
| 11829 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11830 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11832 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11834 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11835 | |
| 11836 | response = trans2.GetResponseInfo(); |
| 11837 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11838 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11839 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11840 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11841 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11842 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11843 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11844 | } |
| 11845 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11846 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11847 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11848 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11849 | |
| 11850 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11851 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11852 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11853 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11854 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11855 | |
| 11856 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11857 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11858 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11859 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11860 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11861 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11862 | scoped_ptr<SpdyFrame> host2_req( |
| 11863 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11864 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11865 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11866 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11867 | scoped_ptr<SpdyFrame> host1_resp( |
| 11868 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11869 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11870 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11871 | scoped_ptr<SpdyFrame> host2_resp( |
| 11872 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11873 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11874 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11875 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11876 | CreateMockRead(*host1_resp, 1), |
| 11877 | CreateMockRead(*host1_resp_body, 2), |
| 11878 | CreateMockRead(*host2_resp, 4), |
| 11879 | CreateMockRead(*host2_resp_body, 5), |
| 11880 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11881 | }; |
| 11882 | |
| 11883 | IPAddressNumber ip; |
| 11884 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11885 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11886 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11887 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11888 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11889 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11890 | |
| 11891 | TestCompletionCallback callback; |
| 11892 | HttpRequestInfo request1; |
| 11893 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11894 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11895 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11896 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11897 | |
| 11898 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11900 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11901 | |
| 11902 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11903 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11904 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11905 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11906 | |
| 11907 | std::string response_data; |
| 11908 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11909 | EXPECT_EQ("hello!", response_data); |
| 11910 | |
| 11911 | HttpRequestInfo request2; |
| 11912 | request2.method = "GET"; |
| 11913 | request2.url = GURL("https://www.gmail.com/"); |
| 11914 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11915 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11916 | |
| 11917 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11919 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11920 | |
| 11921 | response = trans2.GetResponseInfo(); |
| 11922 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11923 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11924 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11925 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11926 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11927 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11928 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11929 | } |
| 11930 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11931 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11932 | public: |
| 11933 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11934 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11935 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11936 | |
| 11937 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11938 | |
| 11939 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11940 | int Resolve(const RequestInfo& info, |
| 11941 | RequestPriority priority, |
| 11942 | AddressList* addresses, |
| 11943 | const CompletionCallback& callback, |
| 11944 | RequestHandle* out_req, |
| 11945 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11946 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11947 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11948 | } |
| 11949 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11950 | int ResolveFromCache(const RequestInfo& info, |
| 11951 | AddressList* addresses, |
| 11952 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11953 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11954 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11955 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11956 | return rv; |
| 11957 | } |
| 11958 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11959 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11960 | host_resolver_.CancelRequest(req); |
| 11961 | } |
| 11962 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11963 | MockCachingHostResolver* GetMockHostResolver() { |
| 11964 | return &host_resolver_; |
| 11965 | } |
| 11966 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11967 | private: |
| 11968 | MockCachingHostResolver host_resolver_; |
| 11969 | const HostPortPair host_port_; |
| 11970 | }; |
| 11971 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11972 | TEST_P(HttpNetworkTransactionTest, |
| 11973 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11974 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11975 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11976 | |
| 11977 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11978 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11979 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11980 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11981 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11982 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11983 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11984 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11985 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11986 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11987 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11989 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11990 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11991 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11992 | scoped_ptr<SpdyFrame> host2_req( |
| 11993 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11994 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11995 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11996 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11997 | scoped_ptr<SpdyFrame> host1_resp( |
| 11998 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11999 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12000 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12001 | scoped_ptr<SpdyFrame> host2_resp( |
| 12002 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12003 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12004 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12005 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12006 | CreateMockRead(*host1_resp, 1), |
| 12007 | CreateMockRead(*host1_resp_body, 2), |
| 12008 | CreateMockRead(*host2_resp, 4), |
| 12009 | CreateMockRead(*host2_resp_body, 5), |
| 12010 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12011 | }; |
| 12012 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12013 | IPAddressNumber ip; |
| 12014 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12015 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12016 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12017 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12018 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12019 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12020 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12021 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12022 | HttpRequestInfo request1; |
| 12023 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12024 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12025 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12026 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12028 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12029 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12030 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12031 | |
| 12032 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12033 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12034 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12035 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12036 | |
| 12037 | std::string response_data; |
| 12038 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12039 | EXPECT_EQ("hello!", response_data); |
| 12040 | |
| 12041 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12042 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12043 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12044 | rv = host_resolver.Resolve(resolve_info, |
| 12045 | DEFAULT_PRIORITY, |
| 12046 | &ignored, |
| 12047 | callback.callback(), |
| 12048 | NULL, |
| 12049 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12050 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12051 | rv = callback.WaitForResult(); |
| 12052 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12053 | |
| 12054 | HttpRequestInfo request2; |
| 12055 | request2.method = "GET"; |
| 12056 | request2.url = GURL("https://www.gmail.com/"); |
| 12057 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12058 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12060 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12061 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12062 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12063 | |
| 12064 | response = trans2.GetResponseInfo(); |
| 12065 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12066 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12067 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12068 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12069 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12070 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12071 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12072 | } |
| 12073 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12074 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12075 | const std::string https_url = "https://www.example.org:8080/"; |
| 12076 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12077 | |
| 12078 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12079 | scoped_ptr<SpdyFrame> req1( |
| 12080 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12081 | |
| 12082 | MockWrite writes1[] = { |
| 12083 | CreateMockWrite(*req1, 0), |
| 12084 | }; |
| 12085 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12086 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12087 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12088 | MockRead reads1[] = { |
| 12089 | CreateMockRead(*resp1, 1), |
| 12090 | CreateMockRead(*body1, 2), |
| 12091 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12092 | }; |
| 12093 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12094 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12095 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12096 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12097 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12098 | |
| 12099 | // HTTP GET for the HTTP URL |
| 12100 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12101 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12102 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12103 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12104 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12105 | }; |
| 12106 | |
| 12107 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12108 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12109 | MockRead(ASYNC, 2, "hello"), |
| 12110 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12111 | }; |
| 12112 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12113 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12114 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12115 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12116 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12117 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12119 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12120 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12121 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12122 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12123 | |
| 12124 | // Start the first transaction to set up the SpdySession |
| 12125 | HttpRequestInfo request1; |
| 12126 | request1.method = "GET"; |
| 12127 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12128 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12129 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12130 | TestCompletionCallback callback1; |
| 12131 | EXPECT_EQ(ERR_IO_PENDING, |
| 12132 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12133 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12134 | |
| 12135 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12136 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12137 | |
| 12138 | // Now, start the HTTP request |
| 12139 | HttpRequestInfo request2; |
| 12140 | request2.method = "GET"; |
| 12141 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12142 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12143 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12144 | TestCompletionCallback callback2; |
| 12145 | EXPECT_EQ(ERR_IO_PENDING, |
| 12146 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12147 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12148 | |
| 12149 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12150 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12151 | } |
| 12152 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12153 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12154 | public: |
| 12155 | void Run(bool pooling, bool valid) { |
| 12156 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12157 | 443); |
| 12158 | HostPortPair alternative("www.example.org", 443); |
| 12159 | |
| 12160 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12161 | scoped_refptr<X509Certificate> cert( |
| 12162 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12163 | ASSERT_TRUE(cert.get()); |
| 12164 | bool common_name_fallback_used; |
| 12165 | EXPECT_EQ(valid, |
| 12166 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12167 | EXPECT_TRUE( |
| 12168 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12169 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12170 | ssl.SetNextProto(GetParam()); |
| 12171 | ssl.cert = cert; |
| 12172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12173 | |
| 12174 | // If pooling, then start a request to alternative first to create a |
| 12175 | // SpdySession. |
| 12176 | std::string url0 = "https://www.example.org:443"; |
| 12177 | // Second request to origin, which has an alternative service, and could |
| 12178 | // open a connection to the alternative host or pool to the existing one. |
| 12179 | std::string url1("https://"); |
| 12180 | url1.append(origin.host()); |
| 12181 | url1.append(":443"); |
| 12182 | |
| 12183 | scoped_ptr<SpdyFrame> req0; |
| 12184 | scoped_ptr<SpdyFrame> req1; |
| 12185 | scoped_ptr<SpdyFrame> resp0; |
| 12186 | scoped_ptr<SpdyFrame> body0; |
| 12187 | scoped_ptr<SpdyFrame> resp1; |
| 12188 | scoped_ptr<SpdyFrame> body1; |
| 12189 | std::vector<MockWrite> writes; |
| 12190 | std::vector<MockRead> reads; |
| 12191 | |
| 12192 | if (pooling) { |
| 12193 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12194 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12195 | |
| 12196 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12197 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12198 | |
| 12199 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12200 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12201 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12202 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12203 | |
| 12204 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12205 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12206 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12207 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12208 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12209 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12210 | } else { |
| 12211 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12212 | |
| 12213 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12214 | |
| 12215 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12216 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12217 | |
| 12218 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12219 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12220 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12221 | } |
| 12222 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12223 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12224 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12225 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12226 | |
| 12227 | // Connection to the origin fails. |
| 12228 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12229 | StaticSocketDataProvider data_refused; |
| 12230 | data_refused.set_connect_data(mock_connect); |
| 12231 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12232 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12233 | session_deps_.use_alternative_services = true; |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12234 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12235 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12236 | session->http_server_properties(); |
| 12237 | AlternativeService alternative_service( |
| 12238 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12239 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12240 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12241 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12242 | |
| 12243 | // First request to alternative. |
| 12244 | if (pooling) { |
| 12245 | scoped_ptr<HttpTransaction> trans0( |
| 12246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12247 | HttpRequestInfo request0; |
| 12248 | request0.method = "GET"; |
| 12249 | request0.url = GURL(url0); |
| 12250 | request0.load_flags = 0; |
| 12251 | TestCompletionCallback callback0; |
| 12252 | |
| 12253 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12255 | rv = callback0.WaitForResult(); |
| 12256 | EXPECT_EQ(OK, rv); |
| 12257 | } |
| 12258 | |
| 12259 | // Second request to origin. |
| 12260 | scoped_ptr<HttpTransaction> trans1( |
| 12261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12262 | HttpRequestInfo request1; |
| 12263 | request1.method = "GET"; |
| 12264 | request1.url = GURL(url1); |
| 12265 | request1.load_flags = 0; |
| 12266 | TestCompletionCallback callback1; |
| 12267 | |
| 12268 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12269 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12270 | base::MessageLoop::current()->RunUntilIdle(); |
| 12271 | if (data.IsReadPaused()) { |
| 12272 | data.CompleteRead(); |
| 12273 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12274 | rv = callback1.WaitForResult(); |
| 12275 | if (valid) { |
| 12276 | EXPECT_EQ(OK, rv); |
| 12277 | } else { |
| 12278 | if (pooling) { |
| 12279 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12280 | } else { |
| 12281 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12282 | } |
| 12283 | } |
| 12284 | } |
| 12285 | }; |
| 12286 | |
| 12287 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12288 | AltSvcCertificateVerificationTest, |
| 12289 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12290 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12291 | |
| 12292 | // The alternative service host must exhibit a certificate that is valid for the |
| 12293 | // origin host. Test that this is enforced when pooling to an existing |
| 12294 | // connection. |
| 12295 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12296 | Run(true, true); |
| 12297 | } |
| 12298 | |
| 12299 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12300 | Run(true, false); |
| 12301 | } |
| 12302 | |
| 12303 | // The alternative service host must exhibit a certificate that is valid for the |
| 12304 | // origin host. Test that this is enforced when opening a new connection. |
| 12305 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12306 | Run(false, true); |
| 12307 | } |
| 12308 | |
| 12309 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12310 | Run(false, false); |
| 12311 | } |
| 12312 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12313 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12314 | // with the alternative server. That connection should not be used. |
| 12315 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12316 | HostPortPair origin("origin.example.org", 443); |
| 12317 | HostPortPair alternative("alternative.example.org", 443); |
| 12318 | |
| 12319 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12320 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12321 | ssl.SetNextProto(kProtoHTTP11); |
| 12322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12323 | |
| 12324 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12325 | // negotiated. |
| 12326 | StaticSocketDataProvider data; |
| 12327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12328 | |
| 12329 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12330 | // negotiated. In order to test this, a failed connection to the origin is |
| 12331 | // mocked. This way the request relies on the alternate Job. |
| 12332 | StaticSocketDataProvider data_refused; |
| 12333 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12334 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12335 | |
| 12336 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12337 | session_deps_.use_alternative_services = true; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12338 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12339 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12340 | session->http_server_properties(); |
| 12341 | AlternativeService alternative_service( |
| 12342 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12343 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12344 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12345 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12346 | |
| 12347 | scoped_ptr<HttpTransaction> trans( |
| 12348 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12349 | HttpRequestInfo request; |
| 12350 | request.method = "GET"; |
| 12351 | request.url = GURL("https://origin.example.org:443"); |
| 12352 | request.load_flags = 0; |
| 12353 | TestCompletionCallback callback; |
| 12354 | |
| 12355 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12356 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12357 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12358 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12359 | } |
| 12360 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12361 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12362 | // origin, and an alternate one to the alternative server. If the former |
| 12363 | // succeeds, the request should succeed, even if the latter fails because |
| 12364 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12365 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12366 | HostPortPair origin("origin.example.org", 443); |
| 12367 | HostPortPair alternative("alternative.example.org", 443); |
| 12368 | |
| 12369 | // Negotiate HTTP/1.1 with alternative. |
| 12370 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12371 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12373 | |
| 12374 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12375 | // negotiated. |
| 12376 | StaticSocketDataProvider data; |
| 12377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12378 | |
| 12379 | // Negotiate HTTP/1.1 with origin. |
| 12380 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12381 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12383 | |
| 12384 | MockWrite http_writes[] = { |
| 12385 | MockWrite( |
| 12386 | "GET / HTTP/1.1\r\n" |
| 12387 | "Host: origin.example.org\r\n" |
| 12388 | "Connection: keep-alive\r\n\r\n"), |
| 12389 | MockWrite( |
| 12390 | "GET /second HTTP/1.1\r\n" |
| 12391 | "Host: origin.example.org\r\n" |
| 12392 | "Connection: keep-alive\r\n\r\n"), |
| 12393 | }; |
| 12394 | |
| 12395 | MockRead http_reads[] = { |
| 12396 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12397 | MockRead("Content-Type: text/html\r\n"), |
| 12398 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12399 | MockRead("foobar"), |
| 12400 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12401 | MockRead("Content-Type: text/html\r\n"), |
| 12402 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12403 | MockRead("another"), |
| 12404 | }; |
| 12405 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12406 | http_writes, arraysize(http_writes)); |
| 12407 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12408 | |
| 12409 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12410 | session_deps_.use_alternative_services = true; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12411 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12412 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12413 | session->http_server_properties(); |
| 12414 | AlternativeService alternative_service( |
| 12415 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12416 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12417 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12418 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12419 | |
| 12420 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12421 | HttpRequestInfo request1; |
| 12422 | request1.method = "GET"; |
| 12423 | request1.url = GURL("https://origin.example.org:443"); |
| 12424 | request1.load_flags = 0; |
| 12425 | TestCompletionCallback callback1; |
| 12426 | |
| 12427 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12428 | rv = callback1.GetResult(rv); |
| 12429 | EXPECT_EQ(OK, rv); |
| 12430 | |
| 12431 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12432 | ASSERT_TRUE(response1 != nullptr); |
| 12433 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12434 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12435 | |
| 12436 | std::string response_data1; |
| 12437 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12438 | EXPECT_EQ("foobar", response_data1); |
| 12439 | |
| 12440 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12441 | // for alternative service. |
| 12442 | EXPECT_TRUE( |
| 12443 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12444 | |
| 12445 | // Since |alternative_service| is broken, a second transaction to origin |
| 12446 | // should not start an alternate Job. It should pool to existing connection |
| 12447 | // to origin. |
| 12448 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12449 | HttpRequestInfo request2; |
| 12450 | request2.method = "GET"; |
| 12451 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12452 | request2.load_flags = 0; |
| 12453 | TestCompletionCallback callback2; |
| 12454 | |
| 12455 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12456 | rv = callback2.GetResult(rv); |
| 12457 | EXPECT_EQ(OK, rv); |
| 12458 | |
| 12459 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12460 | ASSERT_TRUE(response2 != nullptr); |
| 12461 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12462 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12463 | |
| 12464 | std::string response_data2; |
| 12465 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12466 | EXPECT_EQ("another", response_data2); |
| 12467 | } |
| 12468 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12469 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12470 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12471 | // used. |
| 12472 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12473 | HostPortPair origin("origin.example.org", 443); |
| 12474 | HostPortPair alternative("alternative.example.org", 443); |
| 12475 | std::string origin_url = "https://origin.example.org:443"; |
| 12476 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12477 | |
| 12478 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12479 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12480 | ssl.SetNextProto(kProtoHTTP11); |
| 12481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12482 | |
| 12483 | // HTTP/1.1 data for |request1| and |request2|. |
| 12484 | MockWrite http_writes[] = { |
| 12485 | MockWrite( |
| 12486 | "GET / HTTP/1.1\r\n" |
| 12487 | "Host: alternative.example.org\r\n" |
| 12488 | "Connection: keep-alive\r\n\r\n"), |
| 12489 | MockWrite( |
| 12490 | "GET / HTTP/1.1\r\n" |
| 12491 | "Host: alternative.example.org\r\n" |
| 12492 | "Connection: keep-alive\r\n\r\n"), |
| 12493 | }; |
| 12494 | |
| 12495 | MockRead http_reads[] = { |
| 12496 | MockRead( |
| 12497 | "HTTP/1.1 200 OK\r\n" |
| 12498 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12499 | "Content-Length: 40\r\n\r\n" |
| 12500 | "first HTTP/1.1 response from alternative"), |
| 12501 | MockRead( |
| 12502 | "HTTP/1.1 200 OK\r\n" |
| 12503 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12504 | "Content-Length: 41\r\n\r\n" |
| 12505 | "second HTTP/1.1 response from alternative"), |
| 12506 | }; |
| 12507 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12508 | http_writes, arraysize(http_writes)); |
| 12509 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12510 | |
| 12511 | // This test documents that an alternate Job should not pool to an already |
| 12512 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12513 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12514 | StaticSocketDataProvider data_refused; |
| 12515 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12516 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12517 | |
| 12518 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12519 | session_deps_.use_alternative_services = true; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12520 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12521 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12522 | session->http_server_properties(); |
| 12523 | AlternativeService alternative_service( |
| 12524 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12525 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12526 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12527 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12528 | |
| 12529 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12530 | scoped_ptr<HttpTransaction> trans1( |
| 12531 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12532 | HttpRequestInfo request1; |
| 12533 | request1.method = "GET"; |
| 12534 | request1.url = GURL(alternative_url); |
| 12535 | request1.load_flags = 0; |
| 12536 | TestCompletionCallback callback1; |
| 12537 | |
| 12538 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12539 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12540 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12541 | ASSERT_TRUE(response1); |
| 12542 | ASSERT_TRUE(response1->headers.get()); |
| 12543 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12544 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12545 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12546 | std::string response_data1; |
| 12547 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12548 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12549 | |
| 12550 | // Request for origin.example.org, which has an alternative service. This |
| 12551 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12552 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12553 | // open other connections to alternative server. The Job to origin fails, so |
| 12554 | // this request fails. |
| 12555 | scoped_ptr<HttpTransaction> trans2( |
| 12556 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12557 | HttpRequestInfo request2; |
| 12558 | request2.method = "GET"; |
| 12559 | request2.url = GURL(origin_url); |
| 12560 | request2.load_flags = 0; |
| 12561 | TestCompletionCallback callback2; |
| 12562 | |
| 12563 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12564 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12565 | |
| 12566 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12567 | // socket is still open and in the pool. |
| 12568 | scoped_ptr<HttpTransaction> trans3( |
| 12569 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12570 | HttpRequestInfo request3; |
| 12571 | request3.method = "GET"; |
| 12572 | request3.url = GURL(alternative_url); |
| 12573 | request3.load_flags = 0; |
| 12574 | TestCompletionCallback callback3; |
| 12575 | |
| 12576 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12577 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12578 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12579 | ASSERT_TRUE(response3); |
| 12580 | ASSERT_TRUE(response3->headers.get()); |
| 12581 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12582 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12583 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12584 | std::string response_data3; |
| 12585 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12586 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12587 | } |
| 12588 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12589 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12590 | const std::string https_url = "https://www.example.org:8080/"; |
| 12591 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12592 | |
| 12593 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12594 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12595 | scoped_ptr<SpdyFrame> connect( |
| 12596 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12597 | scoped_ptr<SpdyFrame> req1( |
| 12598 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12599 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12600 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12601 | |
| 12602 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12603 | SpdyHeaderBlock req2_block; |
| 12604 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 12605 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12606 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12607 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 12608 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12609 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12610 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12611 | |
| 12612 | MockWrite writes1[] = { |
| 12613 | CreateMockWrite(*connect, 0), |
| 12614 | CreateMockWrite(*wrapped_req1, 2), |
| 12615 | CreateMockWrite(*req2, 5), |
| 12616 | }; |
| 12617 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12618 | scoped_ptr<SpdyFrame> conn_resp( |
| 12619 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12620 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12621 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12622 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12623 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12624 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12625 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12626 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12627 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12628 | MockRead reads1[] = { |
| 12629 | CreateMockRead(*conn_resp, 1), |
| 12630 | CreateMockRead(*wrapped_resp1, 3), |
| 12631 | CreateMockRead(*wrapped_body1, 4), |
| 12632 | CreateMockRead(*resp2, 6), |
| 12633 | CreateMockRead(*body2, 7), |
| 12634 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12635 | }; |
| 12636 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12637 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12638 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12639 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12640 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12641 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12642 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12643 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12644 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12645 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12646 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12647 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12648 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12649 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12650 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12651 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12652 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12653 | |
| 12654 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12655 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12656 | |
| 12657 | // Start the first transaction to set up the SpdySession |
| 12658 | HttpRequestInfo request1; |
| 12659 | request1.method = "GET"; |
| 12660 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12661 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12662 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12663 | TestCompletionCallback callback1; |
| 12664 | EXPECT_EQ(ERR_IO_PENDING, |
| 12665 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12666 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12667 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12668 | |
| 12669 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12670 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12671 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12672 | LoadTimingInfo load_timing_info1; |
| 12673 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12674 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12675 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12676 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12677 | // Now, start the HTTP request |
| 12678 | HttpRequestInfo request2; |
| 12679 | request2.method = "GET"; |
| 12680 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12681 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12682 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12683 | TestCompletionCallback callback2; |
| 12684 | EXPECT_EQ(ERR_IO_PENDING, |
| 12685 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12686 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12687 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12688 | |
| 12689 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12690 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12691 | |
| 12692 | LoadTimingInfo load_timing_info2; |
| 12693 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12694 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12695 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12696 | // HTTP requests over a SPDY session should have a different connection |
| 12697 | // socket_log_id than requests over a tunnel. |
| 12698 | 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] | 12699 | } |
| 12700 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12701 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12702 | // that we do not pool other origins that resolve to the same IP when |
| 12703 | // the certificate does not match the new origin. |
| 12704 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12705 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12706 | const std::string url1 = "http://www.example.org/"; |
| 12707 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12708 | const std::string ip_addr = "1.2.3.4"; |
| 12709 | |
| 12710 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12711 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12712 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12713 | scoped_ptr<SpdyFrame> req1( |
| 12714 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12715 | |
| 12716 | MockWrite writes1[] = { |
| 12717 | CreateMockWrite(*req1, 0), |
| 12718 | }; |
| 12719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12720 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12721 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12722 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12723 | CreateMockRead(*resp1, 1), |
| 12724 | CreateMockRead(*body1, 2), |
| 12725 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12726 | }; |
| 12727 | |
| 12728 | scoped_ptr<DeterministicSocketData> data1( |
| 12729 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12730 | writes1, arraysize(writes1))); |
| 12731 | IPAddressNumber ip; |
| 12732 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12733 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12734 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12735 | data1->set_connect_data(connect_data1); |
| 12736 | |
| 12737 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12738 | scoped_ptr<SpdyFrame> req2( |
| 12739 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12740 | |
| 12741 | MockWrite writes2[] = { |
| 12742 | CreateMockWrite(*req2, 0), |
| 12743 | }; |
| 12744 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12745 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12746 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12747 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12748 | CreateMockRead(*resp2, 1), |
| 12749 | CreateMockRead(*body2, 2), |
| 12750 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12751 | }; |
| 12752 | |
| 12753 | scoped_ptr<DeterministicSocketData> data2( |
| 12754 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12755 | writes2, arraysize(writes2))); |
| 12756 | MockConnect connect_data2(ASYNC, OK); |
| 12757 | data2->set_connect_data(connect_data2); |
| 12758 | |
| 12759 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12760 | // all others direct. |
| 12761 | ProxyConfig proxy_config; |
| 12762 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12763 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12764 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12765 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12766 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12767 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12768 | // Load a valid cert. Note, that this does not need to |
| 12769 | // be valid for proxy because the MockSSLClientSocket does |
| 12770 | // not actually verify it. But SpdySession will use this |
| 12771 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12772 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12773 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12774 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12775 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12776 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12777 | |
| 12778 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12779 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12780 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12781 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12782 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12783 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12784 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12785 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12786 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12787 | |
| 12788 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12789 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12790 | |
| 12791 | // Start the first transaction to set up the SpdySession |
| 12792 | HttpRequestInfo request1; |
| 12793 | request1.method = "GET"; |
| 12794 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12795 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12796 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12797 | TestCompletionCallback callback1; |
| 12798 | ASSERT_EQ(ERR_IO_PENDING, |
| 12799 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12800 | data1->RunFor(3); |
| 12801 | |
| 12802 | ASSERT_TRUE(callback1.have_result()); |
| 12803 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12804 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12805 | |
| 12806 | // Now, start the HTTP request |
| 12807 | HttpRequestInfo request2; |
| 12808 | request2.method = "GET"; |
| 12809 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12810 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12811 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12812 | TestCompletionCallback callback2; |
| 12813 | EXPECT_EQ(ERR_IO_PENDING, |
| 12814 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12815 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12816 | data2->RunFor(3); |
| 12817 | |
| 12818 | ASSERT_TRUE(callback2.have_result()); |
| 12819 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12820 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12821 | } |
| 12822 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12823 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12824 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12825 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12826 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12827 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12828 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12829 | |
| 12830 | MockRead reads1[] = { |
| 12831 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12832 | }; |
| 12833 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12834 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12835 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12836 | scoped_ptr<SpdyFrame> req2( |
| 12837 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12838 | MockWrite writes2[] = { |
| 12839 | CreateMockWrite(*req2, 0), |
| 12840 | }; |
| 12841 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12842 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12843 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12844 | MockRead reads2[] = { |
| 12845 | CreateMockRead(*resp2, 1), |
| 12846 | CreateMockRead(*body2, 2), |
| 12847 | MockRead(ASYNC, OK, 3) // EOF |
| 12848 | }; |
| 12849 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12850 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12851 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12852 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12853 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12854 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12855 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12856 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12857 | |
| 12858 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12859 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12861 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12862 | |
| 12863 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12864 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12865 | |
| 12866 | // Start the first transaction to set up the SpdySession and verify that |
| 12867 | // connection was closed. |
| 12868 | HttpRequestInfo request1; |
| 12869 | request1.method = "GET"; |
| 12870 | request1.url = GURL(https_url); |
| 12871 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12872 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12873 | TestCompletionCallback callback1; |
| 12874 | EXPECT_EQ(ERR_IO_PENDING, |
| 12875 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12876 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12877 | |
| 12878 | // Now, start the second request and make sure it succeeds. |
| 12879 | HttpRequestInfo request2; |
| 12880 | request2.method = "GET"; |
| 12881 | request2.url = GURL(https_url); |
| 12882 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12883 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12884 | TestCompletionCallback callback2; |
| 12885 | EXPECT_EQ(ERR_IO_PENDING, |
| 12886 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12887 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12888 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12889 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12890 | } |
| 12891 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12892 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12893 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12894 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12895 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12896 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12897 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12898 | |
| 12899 | // Use two different hosts with different IPs so they don't get pooled. |
| 12900 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12901 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12902 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12903 | |
| 12904 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12905 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12906 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12907 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12909 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12910 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12911 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12912 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12913 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12914 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12915 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12916 | scoped_ptr<SpdyFrame> host1_resp( |
| 12917 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12918 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12919 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12920 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12921 | CreateMockRead(*host1_resp, 1), |
| 12922 | CreateMockRead(*host1_resp_body, 2), |
| 12923 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12924 | }; |
| 12925 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12926 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12927 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12928 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12929 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12930 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12931 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12932 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12933 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12934 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12935 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12936 | scoped_ptr<SpdyFrame> host2_resp( |
| 12937 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12938 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12939 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12940 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12941 | CreateMockRead(*host2_resp, 1), |
| 12942 | CreateMockRead(*host2_resp_body, 2), |
| 12943 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12944 | }; |
| 12945 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12946 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12947 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12948 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12949 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12950 | |
| 12951 | MockWrite http_write[] = { |
| 12952 | MockWrite("GET / HTTP/1.1\r\n" |
| 12953 | "Host: www.a.com\r\n" |
| 12954 | "Connection: keep-alive\r\n\r\n"), |
| 12955 | }; |
| 12956 | |
| 12957 | MockRead http_read[] = { |
| 12958 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12959 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12960 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12961 | MockRead("hello!"), |
| 12962 | }; |
| 12963 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12964 | http_write, arraysize(http_write)); |
| 12965 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12966 | |
| 12967 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12968 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12969 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12970 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12971 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12972 | |
| 12973 | TestCompletionCallback callback; |
| 12974 | HttpRequestInfo request1; |
| 12975 | request1.method = "GET"; |
| 12976 | request1.url = GURL("https://www.a.com/"); |
| 12977 | request1.load_flags = 0; |
| 12978 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12979 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12980 | |
| 12981 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12983 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12984 | |
| 12985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12986 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12987 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12988 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12989 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12990 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12991 | |
| 12992 | std::string response_data; |
| 12993 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12994 | EXPECT_EQ("hello!", response_data); |
| 12995 | trans.reset(); |
| 12996 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12997 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12998 | |
| 12999 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13000 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13001 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13002 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13003 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13004 | HttpRequestInfo request2; |
| 13005 | request2.method = "GET"; |
| 13006 | request2.url = GURL("https://www.b.com/"); |
| 13007 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13008 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13009 | |
| 13010 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13011 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13012 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13013 | |
| 13014 | response = trans->GetResponseInfo(); |
| 13015 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13016 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13017 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13018 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13019 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13020 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13021 | EXPECT_EQ("hello!", response_data); |
| 13022 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13023 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13024 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13025 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13026 | |
| 13027 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13028 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13029 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13030 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13031 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13032 | HttpRequestInfo request3; |
| 13033 | request3.method = "GET"; |
| 13034 | request3.url = GURL("http://www.a.com/"); |
| 13035 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13036 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13037 | |
| 13038 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13039 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13040 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13041 | |
| 13042 | response = trans->GetResponseInfo(); |
| 13043 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13044 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13045 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13046 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13047 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13048 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13049 | EXPECT_EQ("hello!", response_data); |
| 13050 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13051 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13052 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13053 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13054 | } |
| 13055 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13056 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13057 | HttpRequestInfo request; |
| 13058 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13059 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13060 | request.load_flags = 0; |
| 13061 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13062 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13063 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13065 | |
| 13066 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 13067 | StaticSocketDataProvider data; |
| 13068 | data.set_connect_data(mock_connect); |
| 13069 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13070 | |
| 13071 | TestCompletionCallback callback; |
| 13072 | |
| 13073 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13074 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13075 | |
| 13076 | rv = callback.WaitForResult(); |
| 13077 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13078 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13079 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13080 | HttpRequestHeaders request_headers; |
| 13081 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13082 | |
| 13083 | ConnectionAttempts attempts; |
| 13084 | trans->GetConnectionAttempts(&attempts); |
| 13085 | ASSERT_EQ(1u, attempts.size()); |
| 13086 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13087 | } |
| 13088 | |
| 13089 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13090 | HttpRequestInfo request; |
| 13091 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13092 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13093 | request.load_flags = 0; |
| 13094 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13095 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13096 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13098 | |
| 13099 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13100 | StaticSocketDataProvider data; |
| 13101 | data.set_connect_data(mock_connect); |
| 13102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13103 | |
| 13104 | TestCompletionCallback callback; |
| 13105 | |
| 13106 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13107 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13108 | |
| 13109 | rv = callback.WaitForResult(); |
| 13110 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13111 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13112 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13113 | HttpRequestHeaders request_headers; |
| 13114 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13115 | |
| 13116 | ConnectionAttempts attempts; |
| 13117 | trans->GetConnectionAttempts(&attempts); |
| 13118 | ASSERT_EQ(1u, attempts.size()); |
| 13119 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13120 | } |
| 13121 | |
| 13122 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13123 | HttpRequestInfo request; |
| 13124 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13125 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13126 | request.load_flags = 0; |
| 13127 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13128 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13129 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13131 | |
| 13132 | MockWrite data_writes[] = { |
| 13133 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13134 | }; |
| 13135 | MockRead data_reads[] = { |
| 13136 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13137 | }; |
| 13138 | |
| 13139 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13140 | data_writes, arraysize(data_writes)); |
| 13141 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13142 | |
| 13143 | TestCompletionCallback callback; |
| 13144 | |
| 13145 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13147 | |
| 13148 | rv = callback.WaitForResult(); |
| 13149 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13150 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13151 | HttpRequestHeaders request_headers; |
| 13152 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13153 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13154 | } |
| 13155 | |
| 13156 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13157 | HttpRequestInfo request; |
| 13158 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13159 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13160 | request.load_flags = 0; |
| 13161 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13162 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13163 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13165 | |
| 13166 | MockWrite data_writes[] = { |
| 13167 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13168 | }; |
| 13169 | MockRead data_reads[] = { |
| 13170 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13171 | }; |
| 13172 | |
| 13173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13174 | data_writes, arraysize(data_writes)); |
| 13175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13176 | |
| 13177 | TestCompletionCallback callback; |
| 13178 | |
| 13179 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13180 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13181 | |
| 13182 | rv = callback.WaitForResult(); |
| 13183 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13184 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13185 | HttpRequestHeaders request_headers; |
| 13186 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13187 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13188 | } |
| 13189 | |
| 13190 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13191 | HttpRequestInfo request; |
| 13192 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13193 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13194 | request.load_flags = 0; |
| 13195 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13196 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13197 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13198 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13199 | |
| 13200 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13201 | MockWrite( |
| 13202 | "GET / HTTP/1.1\r\n" |
| 13203 | "Host: www.example.org\r\n" |
| 13204 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13205 | }; |
| 13206 | MockRead data_reads[] = { |
| 13207 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13208 | }; |
| 13209 | |
| 13210 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13211 | data_writes, arraysize(data_writes)); |
| 13212 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13213 | |
| 13214 | TestCompletionCallback callback; |
| 13215 | |
| 13216 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13217 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13218 | |
| 13219 | rv = callback.WaitForResult(); |
| 13220 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13221 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13222 | HttpRequestHeaders request_headers; |
| 13223 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13224 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13225 | } |
| 13226 | |
| 13227 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13228 | HttpRequestInfo request; |
| 13229 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13230 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13231 | request.load_flags = 0; |
| 13232 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13233 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13234 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13236 | |
| 13237 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13238 | MockWrite( |
| 13239 | "GET / HTTP/1.1\r\n" |
| 13240 | "Host: www.example.org\r\n" |
| 13241 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13242 | }; |
| 13243 | MockRead data_reads[] = { |
| 13244 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13245 | }; |
| 13246 | |
| 13247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13248 | data_writes, arraysize(data_writes)); |
| 13249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13250 | |
| 13251 | TestCompletionCallback callback; |
| 13252 | |
| 13253 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13255 | |
| 13256 | rv = callback.WaitForResult(); |
| 13257 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13258 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13259 | HttpRequestHeaders request_headers; |
| 13260 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13261 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13262 | } |
| 13263 | |
| 13264 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13265 | HttpRequestInfo request; |
| 13266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13267 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13268 | request.load_flags = 0; |
| 13269 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13270 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13271 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13272 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13273 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13274 | |
| 13275 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13276 | MockWrite( |
| 13277 | "GET / HTTP/1.1\r\n" |
| 13278 | "Host: www.example.org\r\n" |
| 13279 | "Connection: keep-alive\r\n" |
| 13280 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13281 | }; |
| 13282 | MockRead data_reads[] = { |
| 13283 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13284 | "Content-Length: 5\r\n\r\n" |
| 13285 | "hello"), |
| 13286 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13287 | }; |
| 13288 | |
| 13289 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13290 | data_writes, arraysize(data_writes)); |
| 13291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13292 | |
| 13293 | TestCompletionCallback callback; |
| 13294 | |
| 13295 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13297 | |
| 13298 | rv = callback.WaitForResult(); |
| 13299 | EXPECT_EQ(OK, rv); |
| 13300 | |
| 13301 | HttpRequestHeaders request_headers; |
| 13302 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13303 | std::string foo; |
| 13304 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13305 | EXPECT_EQ("bar", foo); |
| 13306 | } |
| 13307 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13308 | namespace { |
| 13309 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13310 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13311 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13312 | public base::SupportsWeakPtr<FakeStream> { |
| 13313 | public: |
| 13314 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13315 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13316 | |
| 13317 | RequestPriority priority() const { return priority_; } |
| 13318 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13319 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13320 | RequestPriority priority, |
| 13321 | const BoundNetLog& net_log, |
| 13322 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13323 | return ERR_IO_PENDING; |
| 13324 | } |
| 13325 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13326 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13327 | HttpResponseInfo* response, |
| 13328 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13329 | ADD_FAILURE(); |
| 13330 | return ERR_UNEXPECTED; |
| 13331 | } |
| 13332 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13333 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13334 | ADD_FAILURE(); |
| 13335 | return ERR_UNEXPECTED; |
| 13336 | } |
| 13337 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13338 | int ReadResponseBody(IOBuffer* buf, |
| 13339 | int buf_len, |
| 13340 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13341 | ADD_FAILURE(); |
| 13342 | return ERR_UNEXPECTED; |
| 13343 | } |
| 13344 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13345 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13346 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13347 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13348 | ADD_FAILURE(); |
| 13349 | return false; |
| 13350 | } |
| 13351 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13352 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13353 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13354 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13355 | ADD_FAILURE(); |
| 13356 | return false; |
| 13357 | } |
| 13358 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13359 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13360 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13361 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13362 | ADD_FAILURE(); |
| 13363 | return false; |
| 13364 | } |
| 13365 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13366 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13367 | ADD_FAILURE(); |
| 13368 | return 0; |
| 13369 | } |
| 13370 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13371 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13372 | ADD_FAILURE(); |
| 13373 | return false; |
| 13374 | } |
| 13375 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13376 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13377 | |
| 13378 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13379 | ADD_FAILURE(); |
| 13380 | } |
| 13381 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13382 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13383 | ADD_FAILURE(); |
| 13384 | return false; |
| 13385 | } |
| 13386 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13387 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13388 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13389 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13390 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13391 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13392 | |
| 13393 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13394 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13395 | private: |
| 13396 | RequestPriority priority_; |
| 13397 | |
| 13398 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13399 | }; |
| 13400 | |
| 13401 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13402 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13403 | class FakeStreamRequest : public HttpStreamRequest, |
| 13404 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13405 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13406 | FakeStreamRequest(RequestPriority priority, |
| 13407 | HttpStreamRequest::Delegate* delegate) |
| 13408 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13409 | delegate_(delegate), |
| 13410 | websocket_stream_create_helper_(NULL) {} |
| 13411 | |
| 13412 | FakeStreamRequest(RequestPriority priority, |
| 13413 | HttpStreamRequest::Delegate* delegate, |
| 13414 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13415 | : priority_(priority), |
| 13416 | delegate_(delegate), |
| 13417 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13418 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13419 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13420 | |
| 13421 | RequestPriority priority() const { return priority_; } |
| 13422 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13423 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13424 | websocket_stream_create_helper() const { |
| 13425 | return websocket_stream_create_helper_; |
| 13426 | } |
| 13427 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13428 | // Create a new FakeStream and pass it to the request's |
| 13429 | // delegate. Returns a weak pointer to the FakeStream. |
| 13430 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13431 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13432 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13433 | // immediately delete |fake_stream|. |
| 13434 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13435 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13436 | return weak_stream; |
| 13437 | } |
| 13438 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13439 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13440 | ADD_FAILURE(); |
| 13441 | return ERR_UNEXPECTED; |
| 13442 | } |
| 13443 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13444 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13445 | ADD_FAILURE(); |
| 13446 | return LoadState(); |
| 13447 | } |
| 13448 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13449 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13450 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13451 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13452 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13453 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13454 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13455 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13456 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13457 | const ConnectionAttempts& connection_attempts() const override { |
| 13458 | static ConnectionAttempts no_attempts; |
| 13459 | return no_attempts; |
| 13460 | } |
| 13461 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13462 | private: |
| 13463 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13464 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13465 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13466 | |
| 13467 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13468 | }; |
| 13469 | |
| 13470 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13471 | class FakeStreamFactory : public HttpStreamFactory { |
| 13472 | public: |
| 13473 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13474 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13475 | |
| 13476 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13477 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13478 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13479 | return last_stream_request_; |
| 13480 | } |
| 13481 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13482 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13483 | RequestPriority priority, |
| 13484 | const SSLConfig& server_ssl_config, |
| 13485 | const SSLConfig& proxy_ssl_config, |
| 13486 | HttpStreamRequest::Delegate* delegate, |
| 13487 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13488 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13489 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13490 | return fake_request; |
| 13491 | } |
| 13492 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13493 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13494 | const HttpRequestInfo& info, |
| 13495 | RequestPriority priority, |
| 13496 | const SSLConfig& server_ssl_config, |
| 13497 | const SSLConfig& proxy_ssl_config, |
| 13498 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13499 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13500 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13501 | FakeStreamRequest* fake_request = |
| 13502 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13503 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13504 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13505 | } |
| 13506 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13507 | void PreconnectStreams(int num_streams, |
| 13508 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13509 | const SSLConfig& server_ssl_config, |
| 13510 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13511 | ADD_FAILURE(); |
| 13512 | } |
| 13513 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13514 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13515 | ADD_FAILURE(); |
| 13516 | return NULL; |
| 13517 | } |
| 13518 | |
| 13519 | private: |
| 13520 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13521 | |
| 13522 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13523 | }; |
| 13524 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13525 | // TODO(ricea): Maybe unify this with the one in |
| 13526 | // url_request_http_job_unittest.cc ? |
| 13527 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13528 | public: |
| 13529 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13530 | bool using_proxy) |
| 13531 | : state_(connection.release(), using_proxy) {} |
| 13532 | |
| 13533 | // Fake implementation of HttpStreamBase methods. |
| 13534 | // This ends up being quite "real" because this object has to really send data |
| 13535 | // on the mock socket. It might be easier to use the real implementation, but |
| 13536 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13537 | // difficult. |
| 13538 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13539 | RequestPriority priority, |
| 13540 | const BoundNetLog& net_log, |
| 13541 | const CompletionCallback& callback) override { |
| 13542 | state_.Initialize(request_info, priority, net_log, callback); |
| 13543 | return OK; |
| 13544 | } |
| 13545 | |
| 13546 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13547 | HttpResponseInfo* response, |
| 13548 | const CompletionCallback& callback) override { |
| 13549 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13550 | response, callback); |
| 13551 | } |
| 13552 | |
| 13553 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13554 | return parser()->ReadResponseHeaders(callback); |
| 13555 | } |
| 13556 | |
| 13557 | int ReadResponseBody(IOBuffer* buf, |
| 13558 | int buf_len, |
| 13559 | const CompletionCallback& callback) override { |
| 13560 | NOTREACHED(); |
| 13561 | return ERR_IO_PENDING; |
| 13562 | } |
| 13563 | |
| 13564 | void Close(bool not_reusable) override { |
| 13565 | if (parser()) |
| 13566 | parser()->Close(true); |
| 13567 | } |
| 13568 | |
| 13569 | bool IsResponseBodyComplete() const override { |
| 13570 | NOTREACHED(); |
| 13571 | return false; |
| 13572 | } |
| 13573 | |
| 13574 | bool CanFindEndOfResponse() const override { |
| 13575 | return parser()->CanFindEndOfResponse(); |
| 13576 | } |
| 13577 | |
| 13578 | bool IsConnectionReused() const override { |
| 13579 | NOTREACHED(); |
| 13580 | return false; |
| 13581 | } |
| 13582 | void SetConnectionReused() override { NOTREACHED(); } |
| 13583 | |
| 13584 | bool IsConnectionReusable() const override { |
| 13585 | NOTREACHED(); |
| 13586 | return false; |
| 13587 | } |
| 13588 | |
| 13589 | int64 GetTotalReceivedBytes() const override { |
| 13590 | NOTREACHED(); |
| 13591 | return 0; |
| 13592 | } |
| 13593 | |
| 13594 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13595 | NOTREACHED(); |
| 13596 | return false; |
| 13597 | } |
| 13598 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13599 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13600 | |
| 13601 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13602 | NOTREACHED(); |
| 13603 | } |
| 13604 | |
| 13605 | bool IsSpdyHttpStream() const override { |
| 13606 | NOTREACHED(); |
| 13607 | return false; |
| 13608 | } |
| 13609 | |
| 13610 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13611 | |
| 13612 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13613 | |
| 13614 | UploadProgress GetUploadProgress() const override { |
| 13615 | NOTREACHED(); |
| 13616 | return UploadProgress(); |
| 13617 | } |
| 13618 | |
| 13619 | HttpStream* RenewStreamForAuth() override { |
| 13620 | NOTREACHED(); |
| 13621 | return nullptr; |
| 13622 | } |
| 13623 | |
| 13624 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13625 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13626 | NOTREACHED(); |
| 13627 | return scoped_ptr<WebSocketStream>(); |
| 13628 | } |
| 13629 | |
| 13630 | private: |
| 13631 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13632 | HttpBasicState state_; |
| 13633 | |
| 13634 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13635 | }; |
| 13636 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13637 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13638 | // worth doing. |
| 13639 | class FakeWebSocketStreamCreateHelper : |
| 13640 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13641 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13642 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13643 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13644 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13645 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13646 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13647 | } |
| 13648 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13649 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13650 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13651 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13652 | NOTREACHED(); |
| 13653 | return NULL; |
| 13654 | }; |
| 13655 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13656 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13657 | |
| 13658 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13659 | NOTREACHED(); |
| 13660 | return scoped_ptr<WebSocketStream>(); |
| 13661 | } |
| 13662 | }; |
| 13663 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13664 | } // namespace |
| 13665 | |
| 13666 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13667 | // stream request on start. |
| 13668 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 13669 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13670 | HttpNetworkSessionPeer peer(session); |
| 13671 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13672 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13673 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13674 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13675 | |
| 13676 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13677 | |
| 13678 | HttpRequestInfo request; |
| 13679 | TestCompletionCallback callback; |
| 13680 | EXPECT_EQ(ERR_IO_PENDING, |
| 13681 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13682 | |
| 13683 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13684 | fake_factory->last_stream_request(); |
| 13685 | ASSERT_TRUE(fake_request != NULL); |
| 13686 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13687 | } |
| 13688 | |
| 13689 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13690 | // updates to its stream request. |
| 13691 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 13692 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13693 | HttpNetworkSessionPeer peer(session); |
| 13694 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13695 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13696 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13697 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13698 | |
| 13699 | HttpRequestInfo request; |
| 13700 | TestCompletionCallback callback; |
| 13701 | EXPECT_EQ(ERR_IO_PENDING, |
| 13702 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13703 | |
| 13704 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13705 | fake_factory->last_stream_request(); |
| 13706 | ASSERT_TRUE(fake_request != NULL); |
| 13707 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13708 | |
| 13709 | trans.SetPriority(LOWEST); |
| 13710 | ASSERT_TRUE(fake_request != NULL); |
| 13711 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13712 | } |
| 13713 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13714 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13715 | // updates to its stream. |
| 13716 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 13717 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13718 | HttpNetworkSessionPeer peer(session); |
| 13719 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13720 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13721 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13722 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13723 | |
| 13724 | HttpRequestInfo request; |
| 13725 | TestCompletionCallback callback; |
| 13726 | EXPECT_EQ(ERR_IO_PENDING, |
| 13727 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13728 | |
| 13729 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13730 | fake_factory->last_stream_request(); |
| 13731 | ASSERT_TRUE(fake_request != NULL); |
| 13732 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13733 | ASSERT_TRUE(fake_stream != NULL); |
| 13734 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13735 | |
| 13736 | trans.SetPriority(LOWEST); |
| 13737 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13738 | } |
| 13739 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13740 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13741 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13742 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13743 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13744 | std::string test_cases[] = {"ws://www.example.org/", |
| 13745 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13746 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 13747 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13748 | HttpNetworkSessionPeer peer(session); |
| 13749 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13750 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13751 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13752 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13753 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13754 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13755 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13756 | &websocket_stream_create_helper); |
| 13757 | |
| 13758 | HttpRequestInfo request; |
| 13759 | TestCompletionCallback callback; |
| 13760 | request.method = "GET"; |
| 13761 | request.url = GURL(test_cases[i]); |
| 13762 | |
| 13763 | EXPECT_EQ(ERR_IO_PENDING, |
| 13764 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13765 | |
| 13766 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13767 | fake_factory->last_stream_request(); |
| 13768 | ASSERT_TRUE(fake_request != NULL); |
| 13769 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13770 | fake_request->websocket_stream_create_helper()); |
| 13771 | } |
| 13772 | } |
| 13773 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13774 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13775 | // if the transport socket pool is stalled on the global socket limit. |
| 13776 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13777 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13778 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13779 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13780 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13781 | |
| 13782 | // Set up SSL request. |
| 13783 | |
| 13784 | HttpRequestInfo ssl_request; |
| 13785 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13786 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13787 | |
| 13788 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13789 | MockWrite( |
| 13790 | "GET / HTTP/1.1\r\n" |
| 13791 | "Host: www.example.org\r\n" |
| 13792 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13793 | }; |
| 13794 | MockRead ssl_reads[] = { |
| 13795 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13796 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13797 | MockRead("hello world"), |
| 13798 | MockRead(SYNCHRONOUS, OK), |
| 13799 | }; |
| 13800 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13801 | ssl_writes, arraysize(ssl_writes)); |
| 13802 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13803 | |
| 13804 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13806 | |
| 13807 | // Set up HTTP request. |
| 13808 | |
| 13809 | HttpRequestInfo http_request; |
| 13810 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13811 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13812 | |
| 13813 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13814 | MockWrite( |
| 13815 | "GET / HTTP/1.1\r\n" |
| 13816 | "Host: www.example.org\r\n" |
| 13817 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13818 | }; |
| 13819 | MockRead http_reads[] = { |
| 13820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13821 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13822 | MockRead("falafel"), |
| 13823 | MockRead(SYNCHRONOUS, OK), |
| 13824 | }; |
| 13825 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13826 | http_writes, arraysize(http_writes)); |
| 13827 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13828 | |
| 13829 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13830 | |
| 13831 | // Start the SSL request. |
| 13832 | TestCompletionCallback ssl_callback; |
| 13833 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13835 | ASSERT_EQ(ERR_IO_PENDING, |
| 13836 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13837 | BoundNetLog())); |
| 13838 | |
| 13839 | // Start the HTTP request. Pool should stall. |
| 13840 | TestCompletionCallback http_callback; |
| 13841 | scoped_ptr<HttpTransaction> http_trans( |
| 13842 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13843 | ASSERT_EQ(ERR_IO_PENDING, |
| 13844 | http_trans->Start(&http_request, http_callback.callback(), |
| 13845 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13846 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13847 | |
| 13848 | // Wait for response from SSL request. |
| 13849 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13850 | std::string response_data; |
| 13851 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13852 | EXPECT_EQ("hello world", response_data); |
| 13853 | |
| 13854 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13855 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13856 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13857 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13858 | |
| 13859 | // The HTTP request can now complete. |
| 13860 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13861 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13862 | EXPECT_EQ("falafel", response_data); |
| 13863 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13864 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13865 | } |
| 13866 | |
| 13867 | // Tests that when a SSL connection is established but there's no corresponding |
| 13868 | // request that needs it, the new socket is closed if the transport socket pool |
| 13869 | // is stalled on the global socket limit. |
| 13870 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13871 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13872 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13873 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13874 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13875 | |
| 13876 | // Set up an ssl request. |
| 13877 | |
| 13878 | HttpRequestInfo ssl_request; |
| 13879 | ssl_request.method = "GET"; |
| 13880 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13881 | |
| 13882 | // No data will be sent on the SSL socket. |
| 13883 | StaticSocketDataProvider ssl_data; |
| 13884 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13885 | |
| 13886 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13887 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13888 | |
| 13889 | // Set up HTTP request. |
| 13890 | |
| 13891 | HttpRequestInfo http_request; |
| 13892 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13893 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13894 | |
| 13895 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13896 | MockWrite( |
| 13897 | "GET / HTTP/1.1\r\n" |
| 13898 | "Host: www.example.org\r\n" |
| 13899 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13900 | }; |
| 13901 | MockRead http_reads[] = { |
| 13902 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13903 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13904 | MockRead("falafel"), |
| 13905 | MockRead(SYNCHRONOUS, OK), |
| 13906 | }; |
| 13907 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13908 | http_writes, arraysize(http_writes)); |
| 13909 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13910 | |
| 13911 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13912 | |
| 13913 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13914 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13915 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13916 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13917 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 13918 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 13919 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13920 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13921 | |
| 13922 | // Start the HTTP request. Pool should stall. |
| 13923 | TestCompletionCallback http_callback; |
| 13924 | scoped_ptr<HttpTransaction> http_trans( |
| 13925 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13926 | ASSERT_EQ(ERR_IO_PENDING, |
| 13927 | http_trans->Start(&http_request, http_callback.callback(), |
| 13928 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13929 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13930 | |
| 13931 | // The SSL connection will automatically be closed once the connection is |
| 13932 | // established, to let the HTTP request start. |
| 13933 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13934 | std::string response_data; |
| 13935 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13936 | EXPECT_EQ("falafel", response_data); |
| 13937 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13938 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13939 | } |
| 13940 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13941 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13942 | ScopedVector<UploadElementReader> element_readers; |
| 13943 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13944 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13945 | |
| 13946 | HttpRequestInfo request; |
| 13947 | request.method = "POST"; |
| 13948 | request.url = GURL("http://www.foo.com/"); |
| 13949 | request.upload_data_stream = &upload_data_stream; |
| 13950 | request.load_flags = 0; |
| 13951 | |
| 13952 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13953 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13954 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13955 | // Send headers successfully, but get an error while sending the body. |
| 13956 | MockWrite data_writes[] = { |
| 13957 | MockWrite("POST / HTTP/1.1\r\n" |
| 13958 | "Host: www.foo.com\r\n" |
| 13959 | "Connection: keep-alive\r\n" |
| 13960 | "Content-Length: 3\r\n\r\n"), |
| 13961 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13962 | }; |
| 13963 | |
| 13964 | MockRead data_reads[] = { |
| 13965 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13966 | MockRead("hello world"), |
| 13967 | MockRead(SYNCHRONOUS, OK), |
| 13968 | }; |
| 13969 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13970 | arraysize(data_writes)); |
| 13971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13972 | |
| 13973 | TestCompletionCallback callback; |
| 13974 | |
| 13975 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13977 | |
| 13978 | rv = callback.WaitForResult(); |
| 13979 | EXPECT_EQ(OK, rv); |
| 13980 | |
| 13981 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13982 | ASSERT_TRUE(response != NULL); |
| 13983 | |
| 13984 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13985 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13986 | |
| 13987 | std::string response_data; |
| 13988 | rv = ReadTransaction(trans.get(), &response_data); |
| 13989 | EXPECT_EQ(OK, rv); |
| 13990 | EXPECT_EQ("hello world", response_data); |
| 13991 | } |
| 13992 | |
| 13993 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13994 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13995 | TEST_P(HttpNetworkTransactionTest, |
| 13996 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13997 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13998 | MockWrite data_writes[] = { |
| 13999 | MockWrite("GET / HTTP/1.1\r\n" |
| 14000 | "Host: www.foo.com\r\n" |
| 14001 | "Connection: keep-alive\r\n\r\n"), |
| 14002 | MockWrite("POST / HTTP/1.1\r\n" |
| 14003 | "Host: www.foo.com\r\n" |
| 14004 | "Connection: keep-alive\r\n" |
| 14005 | "Content-Length: 3\r\n\r\n"), |
| 14006 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14007 | }; |
| 14008 | |
| 14009 | MockRead data_reads[] = { |
| 14010 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14011 | "Content-Length: 14\r\n\r\n"), |
| 14012 | MockRead("first response"), |
| 14013 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14014 | "Content-Length: 15\r\n\r\n"), |
| 14015 | MockRead("second response"), |
| 14016 | MockRead(SYNCHRONOUS, OK), |
| 14017 | }; |
| 14018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14019 | arraysize(data_writes)); |
| 14020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14021 | |
| 14022 | TestCompletionCallback callback; |
| 14023 | HttpRequestInfo request1; |
| 14024 | request1.method = "GET"; |
| 14025 | request1.url = GURL("http://www.foo.com/"); |
| 14026 | request1.load_flags = 0; |
| 14027 | |
| 14028 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14030 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14032 | |
| 14033 | rv = callback.WaitForResult(); |
| 14034 | EXPECT_EQ(OK, rv); |
| 14035 | |
| 14036 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14037 | ASSERT_TRUE(response1 != NULL); |
| 14038 | |
| 14039 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14040 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14041 | |
| 14042 | std::string response_data1; |
| 14043 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14044 | EXPECT_EQ(OK, rv); |
| 14045 | EXPECT_EQ("first response", response_data1); |
| 14046 | // Delete the transaction to release the socket back into the socket pool. |
| 14047 | trans1.reset(); |
| 14048 | |
| 14049 | ScopedVector<UploadElementReader> element_readers; |
| 14050 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14051 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14052 | |
| 14053 | HttpRequestInfo request2; |
| 14054 | request2.method = "POST"; |
| 14055 | request2.url = GURL("http://www.foo.com/"); |
| 14056 | request2.upload_data_stream = &upload_data_stream; |
| 14057 | request2.load_flags = 0; |
| 14058 | |
| 14059 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14060 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14061 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14062 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14063 | |
| 14064 | rv = callback.WaitForResult(); |
| 14065 | EXPECT_EQ(OK, rv); |
| 14066 | |
| 14067 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14068 | ASSERT_TRUE(response2 != NULL); |
| 14069 | |
| 14070 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14071 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14072 | |
| 14073 | std::string response_data2; |
| 14074 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14075 | EXPECT_EQ(OK, rv); |
| 14076 | EXPECT_EQ("second response", response_data2); |
| 14077 | } |
| 14078 | |
| 14079 | TEST_P(HttpNetworkTransactionTest, |
| 14080 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14081 | ScopedVector<UploadElementReader> element_readers; |
| 14082 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14083 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14084 | |
| 14085 | HttpRequestInfo request; |
| 14086 | request.method = "POST"; |
| 14087 | request.url = GURL("http://www.foo.com/"); |
| 14088 | request.upload_data_stream = &upload_data_stream; |
| 14089 | request.load_flags = 0; |
| 14090 | |
| 14091 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14092 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14093 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14094 | // Send headers successfully, but get an error while sending the body. |
| 14095 | MockWrite data_writes[] = { |
| 14096 | MockWrite("POST / HTTP/1.1\r\n" |
| 14097 | "Host: www.foo.com\r\n" |
| 14098 | "Connection: keep-alive\r\n" |
| 14099 | "Content-Length: 3\r\n\r\n" |
| 14100 | "fo"), |
| 14101 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14102 | }; |
| 14103 | |
| 14104 | MockRead data_reads[] = { |
| 14105 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14106 | MockRead("hello world"), |
| 14107 | MockRead(SYNCHRONOUS, OK), |
| 14108 | }; |
| 14109 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14110 | arraysize(data_writes)); |
| 14111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14112 | |
| 14113 | TestCompletionCallback callback; |
| 14114 | |
| 14115 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14116 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14117 | |
| 14118 | rv = callback.WaitForResult(); |
| 14119 | EXPECT_EQ(OK, rv); |
| 14120 | |
| 14121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14122 | ASSERT_TRUE(response != NULL); |
| 14123 | |
| 14124 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14125 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14126 | |
| 14127 | std::string response_data; |
| 14128 | rv = ReadTransaction(trans.get(), &response_data); |
| 14129 | EXPECT_EQ(OK, rv); |
| 14130 | EXPECT_EQ("hello world", response_data); |
| 14131 | } |
| 14132 | |
| 14133 | // This tests the more common case than the previous test, where headers and |
| 14134 | // body are not merged into a single request. |
| 14135 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14136 | ScopedVector<UploadElementReader> element_readers; |
| 14137 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14138 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14139 | |
| 14140 | HttpRequestInfo request; |
| 14141 | request.method = "POST"; |
| 14142 | request.url = GURL("http://www.foo.com/"); |
| 14143 | request.upload_data_stream = &upload_data_stream; |
| 14144 | request.load_flags = 0; |
| 14145 | |
| 14146 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14147 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14149 | // Send headers successfully, but get an error while sending the body. |
| 14150 | MockWrite data_writes[] = { |
| 14151 | MockWrite("POST / HTTP/1.1\r\n" |
| 14152 | "Host: www.foo.com\r\n" |
| 14153 | "Connection: keep-alive\r\n" |
| 14154 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14155 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14156 | }; |
| 14157 | |
| 14158 | MockRead data_reads[] = { |
| 14159 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14160 | MockRead("hello world"), |
| 14161 | MockRead(SYNCHRONOUS, OK), |
| 14162 | }; |
| 14163 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14164 | arraysize(data_writes)); |
| 14165 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14166 | |
| 14167 | TestCompletionCallback callback; |
| 14168 | |
| 14169 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14171 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14172 | // they can't be merged with the body in a single send. Not currently |
| 14173 | // necessary since a chunked body is never merged with headers, but this makes |
| 14174 | // the test more future proof. |
| 14175 | base::RunLoop().RunUntilIdle(); |
| 14176 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14177 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14178 | |
| 14179 | rv = callback.WaitForResult(); |
| 14180 | EXPECT_EQ(OK, rv); |
| 14181 | |
| 14182 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14183 | ASSERT_TRUE(response != NULL); |
| 14184 | |
| 14185 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14186 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14187 | |
| 14188 | std::string response_data; |
| 14189 | rv = ReadTransaction(trans.get(), &response_data); |
| 14190 | EXPECT_EQ(OK, rv); |
| 14191 | EXPECT_EQ("hello world", response_data); |
| 14192 | } |
| 14193 | |
| 14194 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 14195 | ScopedVector<UploadElementReader> element_readers; |
| 14196 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14197 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14198 | |
| 14199 | HttpRequestInfo request; |
| 14200 | request.method = "POST"; |
| 14201 | request.url = GURL("http://www.foo.com/"); |
| 14202 | request.upload_data_stream = &upload_data_stream; |
| 14203 | request.load_flags = 0; |
| 14204 | |
| 14205 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14206 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14208 | |
| 14209 | MockWrite data_writes[] = { |
| 14210 | MockWrite("POST / HTTP/1.1\r\n" |
| 14211 | "Host: www.foo.com\r\n" |
| 14212 | "Connection: keep-alive\r\n" |
| 14213 | "Content-Length: 3\r\n\r\n"), |
| 14214 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14215 | }; |
| 14216 | |
| 14217 | MockRead data_reads[] = { |
| 14218 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14219 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14220 | MockRead("hello world"), |
| 14221 | MockRead(SYNCHRONOUS, OK), |
| 14222 | }; |
| 14223 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14224 | arraysize(data_writes)); |
| 14225 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14226 | |
| 14227 | TestCompletionCallback callback; |
| 14228 | |
| 14229 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14230 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14231 | |
| 14232 | rv = callback.WaitForResult(); |
| 14233 | EXPECT_EQ(OK, rv); |
| 14234 | |
| 14235 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14236 | ASSERT_TRUE(response != NULL); |
| 14237 | |
| 14238 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14239 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14240 | |
| 14241 | std::string response_data; |
| 14242 | rv = ReadTransaction(trans.get(), &response_data); |
| 14243 | EXPECT_EQ(OK, rv); |
| 14244 | EXPECT_EQ("hello world", response_data); |
| 14245 | } |
| 14246 | |
| 14247 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14248 | ScopedVector<UploadElementReader> element_readers; |
| 14249 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14250 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14251 | |
| 14252 | HttpRequestInfo request; |
| 14253 | request.method = "POST"; |
| 14254 | request.url = GURL("http://www.foo.com/"); |
| 14255 | request.upload_data_stream = &upload_data_stream; |
| 14256 | request.load_flags = 0; |
| 14257 | |
| 14258 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14259 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14261 | // Send headers successfully, but get an error while sending the body. |
| 14262 | MockWrite data_writes[] = { |
| 14263 | MockWrite("POST / HTTP/1.1\r\n" |
| 14264 | "Host: www.foo.com\r\n" |
| 14265 | "Connection: keep-alive\r\n" |
| 14266 | "Content-Length: 3\r\n\r\n"), |
| 14267 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14268 | }; |
| 14269 | |
| 14270 | MockRead data_reads[] = { |
| 14271 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14272 | MockRead("hello world"), |
| 14273 | MockRead(SYNCHRONOUS, OK), |
| 14274 | }; |
| 14275 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14276 | arraysize(data_writes)); |
| 14277 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14278 | |
| 14279 | TestCompletionCallback callback; |
| 14280 | |
| 14281 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14283 | |
| 14284 | rv = callback.WaitForResult(); |
| 14285 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14286 | } |
| 14287 | |
| 14288 | TEST_P(HttpNetworkTransactionTest, |
| 14289 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14290 | ScopedVector<UploadElementReader> element_readers; |
| 14291 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14292 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14293 | |
| 14294 | HttpRequestInfo request; |
| 14295 | request.method = "POST"; |
| 14296 | request.url = GURL("http://www.foo.com/"); |
| 14297 | request.upload_data_stream = &upload_data_stream; |
| 14298 | request.load_flags = 0; |
| 14299 | |
| 14300 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14301 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14302 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14303 | // Send headers successfully, but get an error while sending the body. |
| 14304 | MockWrite data_writes[] = { |
| 14305 | MockWrite("POST / HTTP/1.1\r\n" |
| 14306 | "Host: www.foo.com\r\n" |
| 14307 | "Connection: keep-alive\r\n" |
| 14308 | "Content-Length: 3\r\n\r\n"), |
| 14309 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14310 | }; |
| 14311 | |
| 14312 | MockRead data_reads[] = { |
| 14313 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14314 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14315 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14316 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14317 | MockRead(SYNCHRONOUS, OK), |
| 14318 | }; |
| 14319 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14320 | arraysize(data_writes)); |
| 14321 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14322 | |
| 14323 | TestCompletionCallback callback; |
| 14324 | |
| 14325 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14327 | |
| 14328 | rv = callback.WaitForResult(); |
| 14329 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14330 | } |
| 14331 | |
| 14332 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14333 | ScopedVector<UploadElementReader> element_readers; |
| 14334 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14335 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14336 | |
| 14337 | HttpRequestInfo request; |
| 14338 | request.method = "POST"; |
| 14339 | request.url = GURL("http://www.foo.com/"); |
| 14340 | request.upload_data_stream = &upload_data_stream; |
| 14341 | request.load_flags = 0; |
| 14342 | |
| 14343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14344 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14346 | // Send headers successfully, but get an error while sending the body. |
| 14347 | MockWrite data_writes[] = { |
| 14348 | MockWrite("POST / HTTP/1.1\r\n" |
| 14349 | "Host: www.foo.com\r\n" |
| 14350 | "Connection: keep-alive\r\n" |
| 14351 | "Content-Length: 3\r\n\r\n"), |
| 14352 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14353 | }; |
| 14354 | |
| 14355 | MockRead data_reads[] = { |
| 14356 | MockRead("HTTP 0.9 rocks!"), |
| 14357 | MockRead(SYNCHRONOUS, OK), |
| 14358 | }; |
| 14359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14360 | arraysize(data_writes)); |
| 14361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14362 | |
| 14363 | TestCompletionCallback callback; |
| 14364 | |
| 14365 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14366 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14367 | |
| 14368 | rv = callback.WaitForResult(); |
| 14369 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14370 | } |
| 14371 | |
| 14372 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14373 | ScopedVector<UploadElementReader> element_readers; |
| 14374 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14375 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14376 | |
| 14377 | HttpRequestInfo request; |
| 14378 | request.method = "POST"; |
| 14379 | request.url = GURL("http://www.foo.com/"); |
| 14380 | request.upload_data_stream = &upload_data_stream; |
| 14381 | request.load_flags = 0; |
| 14382 | |
| 14383 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14384 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14386 | // Send headers successfully, but get an error while sending the body. |
| 14387 | MockWrite data_writes[] = { |
| 14388 | MockWrite("POST / HTTP/1.1\r\n" |
| 14389 | "Host: www.foo.com\r\n" |
| 14390 | "Connection: keep-alive\r\n" |
| 14391 | "Content-Length: 3\r\n\r\n"), |
| 14392 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14393 | }; |
| 14394 | |
| 14395 | MockRead data_reads[] = { |
| 14396 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14397 | MockRead(SYNCHRONOUS, OK), |
| 14398 | }; |
| 14399 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14400 | arraysize(data_writes)); |
| 14401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14402 | |
| 14403 | TestCompletionCallback callback; |
| 14404 | |
| 14405 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14406 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14407 | |
| 14408 | rv = callback.WaitForResult(); |
| 14409 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14410 | } |
| 14411 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14412 | // Verify that proxy headers are not sent to the destination server when |
| 14413 | // establishing a tunnel for a secure WebSocket connection. |
| 14414 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14415 | HttpRequestInfo request; |
| 14416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14417 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14418 | AddWebSocketHeaders(&request.extra_headers); |
| 14419 | |
| 14420 | // Configure against proxy server "myproxy:70". |
| 14421 | session_deps_.proxy_service.reset( |
| 14422 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14423 | |
| 14424 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14425 | |
| 14426 | // Since a proxy is configured, try to establish a tunnel. |
| 14427 | MockWrite data_writes[] = { |
| 14428 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14429 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14430 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14432 | |
| 14433 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14434 | // be issuing -- the final header line contains the credentials. |
| 14435 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14436 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14437 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14438 | "Proxy-Connection: keep-alive\r\n" |
| 14439 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14440 | |
| 14441 | MockWrite( |
| 14442 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14443 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14444 | "Connection: Upgrade\r\n" |
| 14445 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14446 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14447 | "Sec-WebSocket-Version: 13\r\n" |
| 14448 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14449 | }; |
| 14450 | |
| 14451 | // The proxy responds to the connect with a 407, using a persistent |
| 14452 | // connection. |
| 14453 | MockRead data_reads[] = { |
| 14454 | // No credentials. |
| 14455 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14456 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame^] | 14457 | MockRead("Content-Length: 0\r\n"), |
| 14458 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14459 | |
| 14460 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14461 | |
| 14462 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14463 | MockRead("Upgrade: websocket\r\n"), |
| 14464 | MockRead("Connection: Upgrade\r\n"), |
| 14465 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14466 | }; |
| 14467 | |
| 14468 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14469 | arraysize(data_writes)); |
| 14470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14471 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14473 | |
| 14474 | scoped_ptr<HttpTransaction> trans( |
| 14475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14476 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14477 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14478 | &websocket_stream_create_helper); |
| 14479 | |
| 14480 | { |
| 14481 | TestCompletionCallback callback; |
| 14482 | |
| 14483 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14484 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14485 | |
| 14486 | rv = callback.WaitForResult(); |
| 14487 | EXPECT_EQ(OK, rv); |
| 14488 | } |
| 14489 | |
| 14490 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14491 | ASSERT_TRUE(response); |
| 14492 | ASSERT_TRUE(response->headers.get()); |
| 14493 | EXPECT_EQ(407, response->headers->response_code()); |
| 14494 | |
| 14495 | { |
| 14496 | TestCompletionCallback callback; |
| 14497 | |
| 14498 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14499 | callback.callback()); |
| 14500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14501 | |
| 14502 | rv = callback.WaitForResult(); |
| 14503 | EXPECT_EQ(OK, rv); |
| 14504 | } |
| 14505 | |
| 14506 | response = trans->GetResponseInfo(); |
| 14507 | ASSERT_TRUE(response); |
| 14508 | ASSERT_TRUE(response->headers.get()); |
| 14509 | |
| 14510 | EXPECT_EQ(101, response->headers->response_code()); |
| 14511 | |
| 14512 | trans.reset(); |
| 14513 | session->CloseAllConnections(); |
| 14514 | } |
| 14515 | |
| 14516 | // Verify that proxy headers are not sent to the destination server when |
| 14517 | // establishing a tunnel for an insecure WebSocket connection. |
| 14518 | // This requires the authentication info to be injected into the auth cache |
| 14519 | // due to crbug.com/395064 |
| 14520 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14521 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14522 | HttpRequestInfo request; |
| 14523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14524 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14525 | AddWebSocketHeaders(&request.extra_headers); |
| 14526 | |
| 14527 | // Configure against proxy server "myproxy:70". |
| 14528 | session_deps_.proxy_service.reset( |
| 14529 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14530 | |
| 14531 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14532 | |
| 14533 | MockWrite data_writes[] = { |
| 14534 | // Try to establish a tunnel for the WebSocket connection, with |
| 14535 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14536 | // they cannot and will not use the same TCP/IP connection as the |
| 14537 | // preflight HTTP request. |
| 14538 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14539 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14540 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14541 | "Proxy-Connection: keep-alive\r\n" |
| 14542 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14543 | |
| 14544 | MockWrite( |
| 14545 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14546 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14547 | "Connection: Upgrade\r\n" |
| 14548 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14549 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14550 | "Sec-WebSocket-Version: 13\r\n" |
| 14551 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14552 | }; |
| 14553 | |
| 14554 | MockRead data_reads[] = { |
| 14555 | // HTTP CONNECT with credentials. |
| 14556 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14557 | |
| 14558 | // WebSocket connection established inside tunnel. |
| 14559 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14560 | MockRead("Upgrade: websocket\r\n"), |
| 14561 | MockRead("Connection: Upgrade\r\n"), |
| 14562 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14563 | }; |
| 14564 | |
| 14565 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14566 | arraysize(data_writes)); |
| 14567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14568 | |
| 14569 | session->http_auth_cache()->Add( |
| 14570 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14571 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14572 | |
| 14573 | scoped_ptr<HttpTransaction> trans( |
| 14574 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14575 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14576 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14577 | &websocket_stream_create_helper); |
| 14578 | |
| 14579 | TestCompletionCallback callback; |
| 14580 | |
| 14581 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14582 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14583 | |
| 14584 | rv = callback.WaitForResult(); |
| 14585 | EXPECT_EQ(OK, rv); |
| 14586 | |
| 14587 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14588 | ASSERT_TRUE(response); |
| 14589 | ASSERT_TRUE(response->headers.get()); |
| 14590 | |
| 14591 | EXPECT_EQ(101, response->headers->response_code()); |
| 14592 | |
| 14593 | trans.reset(); |
| 14594 | session->CloseAllConnections(); |
| 14595 | } |
| 14596 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14597 | } // namespace net |