[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame^] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 35 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 37 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 38 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 39 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 40 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 41 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 42 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 81 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 82 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 84 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 85 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 87 | using base::ASCIIToUTF16; |
| 88 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 89 | //----------------------------------------------------------------------------- |
| 90 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 91 | namespace net { |
| 92 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 93 | namespace { |
| 94 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 95 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 96 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 97 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 98 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 99 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 100 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 101 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 102 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 103 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 104 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 105 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 106 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 107 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 108 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 109 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 110 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 111 | } |
| 112 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 113 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 114 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 115 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 116 | } |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 119 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 120 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 123 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 124 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 125 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 126 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | if (!params) |
| 128 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 129 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 130 | if (!params->GetList("headers", &header_list)) |
| 131 | return false; |
| 132 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 133 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 134 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 139 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 144 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 145 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
| 150 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 152 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 154 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 158 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 159 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 161 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 164 | |
| 165 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 166 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 169 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 171 | load_timing_info.send_start); |
| 172 | |
| 173 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 175 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 177 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 178 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 182 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
| 189 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 191 | load_timing_info.proxy_resolve_end); |
| 192 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 193 | load_timing_info.send_start); |
| 194 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 203 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | int connect_timing_flags) { |
| 206 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | |
| 209 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 211 | load_timing_info.proxy_resolve_end); |
| 212 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 213 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 214 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 215 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 217 | load_timing_info.send_start); |
| 218 | |
| 219 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 221 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 223 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 225 | } |
| 226 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 227 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 228 | headers->SetHeader("Connection", "Upgrade"); |
| 229 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 230 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 231 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 232 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 233 | } |
| 234 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 235 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 236 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 237 | } |
| 238 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 239 | } // namespace |
| 240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 241 | class HttpNetworkTransactionTest |
| 242 | : public PlatformTest, |
| 243 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 245 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 246 | // Important to restore the per-pool limit first, since the pool limit must |
| 247 | // always be greater than group limit, and the tests reduce both limits. |
| 248 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 250 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 251 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 252 | } |
| 253 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 254 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 255 | HttpNetworkTransactionTest() |
| 256 | : spdy_util_(GetParam()), |
| 257 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 258 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 260 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 261 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 262 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 263 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 264 | struct SimpleGetHelperResult { |
| 265 | int rv; |
| 266 | std::string status_line; |
| 267 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 268 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 269 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 270 | ConnectionAttempts connection_attempts; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 271 | }; |
| 272 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 273 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 274 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 275 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 276 | } |
| 277 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 278 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 279 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[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 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 282 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 283 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 284 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 285 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 286 | } |
| 287 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 288 | const char* GetAlternateProtocolFromParam() { |
| 289 | return |
| 290 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 291 | } |
| 292 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 293 | std::string GetAlternativeServiceHttpHeader() { |
| 294 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 295 | "=\"www.example.com:443\"\r\n"; |
| 296 | } |
| 297 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 298 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 299 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 300 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 301 | } |
| 302 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 303 | // Either |write_failure| specifies a write failure or |read_failure| |
| 304 | // specifies a read failure when using a reused socket. In either case, the |
| 305 | // failure should cause the network transaction to resend the request, and the |
| 306 | // other argument should be NULL. |
| 307 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 308 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 309 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 310 | // Either |write_failure| specifies a write failure or |read_failure| |
| 311 | // specifies a read failure when using a reused socket. In either case, the |
| 312 | // failure should cause the network transaction to resend the request, and the |
| 313 | // other argument should be NULL. |
| 314 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 315 | const MockRead* read_failure, |
| 316 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 317 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 318 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 319 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 320 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 321 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 322 | HttpRequestInfo request; |
| 323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 324 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 325 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 326 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 327 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 328 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 329 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 330 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 332 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 333 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 334 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 335 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 337 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 338 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 339 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 340 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 342 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 343 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 344 | |
| 345 | // Even in the failure cases that use this function, connections are always |
| 346 | // successfully established before the error. |
| 347 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 348 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 349 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 350 | if (out.rv != OK) |
| 351 | return out; |
| 352 | |
| 353 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 354 | // Can't use ASSERT_* inside helper functions like this, so |
| 355 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 356 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 357 | out.rv = ERR_UNEXPECTED; |
| 358 | return out; |
| 359 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 360 | out.status_line = response->headers->GetStatusLine(); |
| 361 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 362 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 363 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 364 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 365 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 366 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 367 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 368 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 369 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 370 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 371 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 372 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 373 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 374 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 375 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 376 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 377 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 378 | std::string line; |
| 379 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 380 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 381 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 382 | HttpRequestHeaders request_headers; |
| 383 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 384 | std::string value; |
| 385 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 386 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 387 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 388 | EXPECT_EQ("keep-alive", value); |
| 389 | |
| 390 | std::string response_headers; |
| 391 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 392 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 393 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 394 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 395 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 396 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 397 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 398 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 399 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 400 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 401 | size_t reads_count) { |
| 402 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 403 | StaticSocketDataProvider* data[] = { &reads }; |
| 404 | return SimpleGetHelperForData(data, 1); |
| 405 | } |
| 406 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 407 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 408 | int64 size = 0; |
| 409 | for (size_t i = 0; i < reads_count; ++i) |
| 410 | size += data_reads[i].data_len; |
| 411 | return size; |
| 412 | } |
| 413 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 414 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 415 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 416 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 417 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 418 | |
| 419 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 420 | |
| 421 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 422 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 423 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 424 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 425 | |
| 426 | // Original socket limits. Some tests set these. Safest to always restore |
| 427 | // them once each test has been run. |
| 428 | int old_max_group_sockets_; |
| 429 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 430 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 431 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 432 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 433 | HttpNetworkTransactionTest, |
| 434 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 435 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 436 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 437 | namespace { |
| 438 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 439 | class BeforeNetworkStartHandler { |
| 440 | public: |
| 441 | explicit BeforeNetworkStartHandler(bool defer) |
| 442 | : defer_on_before_network_start_(defer), |
| 443 | observed_before_network_start_(false) {} |
| 444 | |
| 445 | void OnBeforeNetworkStart(bool* defer) { |
| 446 | *defer = defer_on_before_network_start_; |
| 447 | observed_before_network_start_ = true; |
| 448 | } |
| 449 | |
| 450 | bool observed_before_network_start() const { |
| 451 | return observed_before_network_start_; |
| 452 | } |
| 453 | |
| 454 | private: |
| 455 | const bool defer_on_before_network_start_; |
| 456 | bool observed_before_network_start_; |
| 457 | |
| 458 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 459 | }; |
| 460 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 461 | class BeforeProxyHeadersSentHandler { |
| 462 | public: |
| 463 | BeforeProxyHeadersSentHandler() |
| 464 | : observed_before_proxy_headers_sent_(false) {} |
| 465 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 466 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 467 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 468 | observed_before_proxy_headers_sent_ = true; |
| 469 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 470 | } |
| 471 | |
| 472 | bool observed_before_proxy_headers_sent() const { |
| 473 | return observed_before_proxy_headers_sent_; |
| 474 | } |
| 475 | |
| 476 | std::string observed_proxy_server_uri() const { |
| 477 | return observed_proxy_server_uri_; |
| 478 | } |
| 479 | |
| 480 | private: |
| 481 | bool observed_before_proxy_headers_sent_; |
| 482 | std::string observed_proxy_server_uri_; |
| 483 | |
| 484 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 485 | }; |
| 486 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 487 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 488 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 489 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 490 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 491 | const int sizeof_row = strlen(row); |
| 492 | const int num_rows = static_cast<int>( |
| 493 | ceil(static_cast<float>(size) / sizeof_row)); |
| 494 | const int sizeof_data = num_rows * sizeof_row; |
| 495 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 496 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 497 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 498 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 499 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 500 | } |
| 501 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 502 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 503 | // Alternative functions that eliminate randomness and dependency on the local |
| 504 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 505 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 506 | static const uint8 bytes[] = { |
| 507 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 508 | }; |
| 509 | static size_t current_byte = 0; |
| 510 | for (size_t i = 0; i < n; ++i) { |
| 511 | output[i] = bytes[current_byte++]; |
| 512 | current_byte %= arraysize(bytes); |
| 513 | } |
| 514 | } |
| 515 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 516 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 517 | static const uint8 bytes[] = { |
| 518 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 519 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 520 | }; |
| 521 | static size_t current_byte = 0; |
| 522 | for (size_t i = 0; i < n; ++i) { |
| 523 | output[i] = bytes[current_byte++]; |
| 524 | current_byte %= arraysize(bytes); |
| 525 | } |
| 526 | } |
| 527 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 528 | std::string MockGetHostName() { |
| 529 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 530 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 531 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 532 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 533 | template<typename ParentPool> |
| 534 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 535 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 536 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 537 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 538 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 539 | const std::string last_group_name_received() const { |
| 540 | return last_group_name_; |
| 541 | } |
| 542 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 543 | int RequestSocket(const std::string& group_name, |
| 544 | const void* socket_params, |
| 545 | RequestPriority priority, |
| 546 | ClientSocketHandle* handle, |
| 547 | const CompletionCallback& callback, |
| 548 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 549 | last_group_name_ = group_name; |
| 550 | return ERR_IO_PENDING; |
| 551 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 552 | void CancelRequest(const std::string& group_name, |
| 553 | ClientSocketHandle* handle) override {} |
| 554 | void ReleaseSocket(const std::string& group_name, |
| 555 | scoped_ptr<StreamSocket> socket, |
| 556 | int id) override {} |
| 557 | void CloseIdleSockets() override {} |
| 558 | int IdleSocketCount() const override { return 0; } |
| 559 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 560 | return 0; |
| 561 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 562 | LoadState GetLoadState(const std::string& group_name, |
| 563 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 564 | return LOAD_STATE_IDLE; |
| 565 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 566 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 567 | return base::TimeDelta(); |
| 568 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 569 | |
| 570 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 571 | std::string last_group_name_; |
| 572 | }; |
| 573 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 574 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 575 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 576 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 577 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 578 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 579 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 580 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 581 | CaptureGroupNameSSLSocketPool; |
| 582 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 583 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 584 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 585 | HostResolver* host_resolver, |
| 586 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 587 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 588 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 589 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 590 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 591 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 592 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 593 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 594 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 595 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 596 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 597 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 598 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 599 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 600 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 601 | : SSLClientSocketPool(0, |
| 602 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 603 | cert_verifier, |
| 604 | NULL, |
| 605 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 606 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 607 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 608 | std::string(), |
| 609 | NULL, |
| 610 | NULL, |
| 611 | NULL, |
| 612 | NULL, |
| 613 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 614 | NULL) { |
| 615 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 616 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 617 | //----------------------------------------------------------------------------- |
| 618 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 619 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 620 | // configured for common cases. |
| 621 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 622 | if (!auth_challenge) |
| 623 | return false; |
| 624 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 625 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 626 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 627 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 628 | return true; |
| 629 | } |
| 630 | |
| 631 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 632 | if (!auth_challenge) |
| 633 | return false; |
| 634 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 635 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 636 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 637 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 642 | if (!auth_challenge) |
| 643 | return false; |
| 644 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 645 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 646 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 647 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 648 | return true; |
| 649 | } |
| 650 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 651 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 652 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 653 | if (!auth_challenge) |
| 654 | return false; |
| 655 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 656 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 657 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 658 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 659 | return true; |
| 660 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 661 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 662 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 663 | } // namespace |
| 664 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 665 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 666 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 667 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 669 | } |
| 670 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 671 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 672 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 673 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 674 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 675 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 676 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 677 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 678 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 679 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 680 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 681 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 682 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 683 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 684 | EXPECT_EQ(0u, out.connection_attempts.size()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 688 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 689 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 690 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 691 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 692 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 693 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 694 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 695 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 696 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 697 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 698 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 699 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 703 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 704 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 705 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 706 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 708 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 709 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 710 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 711 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 712 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 713 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 714 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 718 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 719 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 720 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 723 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 724 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 725 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 726 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 727 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 728 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 729 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // 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] | 733 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 734 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 735 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 736 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 738 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 739 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 740 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 741 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 742 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 743 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 744 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 748 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 750 | MockRead("\n"), |
| 751 | MockRead("\n"), |
| 752 | MockRead("Q"), |
| 753 | MockRead("J"), |
| 754 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 755 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 757 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 758 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 759 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 760 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 761 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 762 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 763 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 767 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 769 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 771 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 772 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 773 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 774 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 775 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 776 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 777 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 778 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 779 | } |
| 780 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 781 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 782 | // persistent connection. The response should still terminate since a 204 |
| 783 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 784 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 785 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 786 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 787 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 788 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 790 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 791 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 792 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 793 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 794 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 795 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 796 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 797 | int64 response_size = reads_size - strlen(junk); |
| 798 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 799 | } |
| 800 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 801 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 802 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 803 | std::string final_chunk = "0\r\n\r\n"; |
| 804 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 805 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 806 | MockRead data_reads[] = { |
| 807 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 808 | MockRead("5\r\nHello\r\n"), |
| 809 | MockRead("1\r\n"), |
| 810 | MockRead(" \r\n"), |
| 811 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 812 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 813 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 814 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 815 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 816 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 817 | EXPECT_EQ(OK, out.rv); |
| 818 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 819 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 820 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 821 | int64 response_size = reads_size - extra_data.size(); |
| 822 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 823 | } |
| 824 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 825 | // Next tests deal with http://crbug.com/56344. |
| 826 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 827 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 828 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 829 | MockRead data_reads[] = { |
| 830 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 831 | MockRead("Content-Length: 10\r\n"), |
| 832 | MockRead("Content-Length: 5\r\n\r\n"), |
| 833 | }; |
| 834 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 835 | arraysize(data_reads)); |
| 836 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 837 | } |
| 838 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 839 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 840 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 841 | MockRead data_reads[] = { |
| 842 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 843 | MockRead("Content-Length: 5\r\n"), |
| 844 | MockRead("Content-Length: 5\r\n\r\n"), |
| 845 | MockRead("Hello"), |
| 846 | }; |
| 847 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 848 | arraysize(data_reads)); |
| 849 | EXPECT_EQ(OK, out.rv); |
| 850 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 851 | EXPECT_EQ("Hello", out.response_data); |
| 852 | } |
| 853 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 854 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 855 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 856 | // More than 2 dupes. |
| 857 | { |
| 858 | MockRead data_reads[] = { |
| 859 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 860 | MockRead("Content-Length: 5\r\n"), |
| 861 | MockRead("Content-Length: 5\r\n"), |
| 862 | MockRead("Content-Length: 5\r\n\r\n"), |
| 863 | MockRead("Hello"), |
| 864 | }; |
| 865 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 866 | arraysize(data_reads)); |
| 867 | EXPECT_EQ(OK, out.rv); |
| 868 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 869 | EXPECT_EQ("Hello", out.response_data); |
| 870 | } |
| 871 | // HTTP/1.0 |
| 872 | { |
| 873 | MockRead data_reads[] = { |
| 874 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 875 | MockRead("Content-Length: 5\r\n"), |
| 876 | MockRead("Content-Length: 5\r\n"), |
| 877 | MockRead("Content-Length: 5\r\n\r\n"), |
| 878 | MockRead("Hello"), |
| 879 | }; |
| 880 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 881 | arraysize(data_reads)); |
| 882 | EXPECT_EQ(OK, out.rv); |
| 883 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 884 | EXPECT_EQ("Hello", out.response_data); |
| 885 | } |
| 886 | // 2 dupes and one mismatched. |
| 887 | { |
| 888 | MockRead data_reads[] = { |
| 889 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 890 | MockRead("Content-Length: 10\r\n"), |
| 891 | MockRead("Content-Length: 10\r\n"), |
| 892 | MockRead("Content-Length: 5\r\n\r\n"), |
| 893 | }; |
| 894 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 895 | arraysize(data_reads)); |
| 896 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 897 | } |
| 898 | } |
| 899 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 900 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 901 | MultipleContentLengthHeadersTransferEncoding) { |
| 902 | MockRead data_reads[] = { |
| 903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 904 | MockRead("Content-Length: 666\r\n"), |
| 905 | MockRead("Content-Length: 1337\r\n"), |
| 906 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 907 | MockRead("5\r\nHello\r\n"), |
| 908 | MockRead("1\r\n"), |
| 909 | MockRead(" \r\n"), |
| 910 | MockRead("5\r\nworld\r\n"), |
| 911 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 912 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 913 | }; |
| 914 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 915 | arraysize(data_reads)); |
| 916 | EXPECT_EQ(OK, out.rv); |
| 917 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 918 | EXPECT_EQ("Hello world", out.response_data); |
| 919 | } |
| 920 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 921 | // Next tests deal with http://crbug.com/98895. |
| 922 | |
| 923 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 924 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 925 | MockRead data_reads[] = { |
| 926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 927 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 928 | MockRead("Content-Length: 5\r\n\r\n"), |
| 929 | MockRead("Hello"), |
| 930 | }; |
| 931 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 932 | arraysize(data_reads)); |
| 933 | EXPECT_EQ(OK, out.rv); |
| 934 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 935 | EXPECT_EQ("Hello", out.response_data); |
| 936 | } |
| 937 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 938 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 939 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 940 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 941 | MockRead data_reads[] = { |
| 942 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 943 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 944 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 945 | MockRead("Content-Length: 5\r\n\r\n"), |
| 946 | MockRead("Hello"), |
| 947 | }; |
| 948 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 949 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 950 | EXPECT_EQ(OK, out.rv); |
| 951 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 952 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 956 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 957 | MockRead data_reads[] = { |
| 958 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 959 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 960 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 961 | MockRead("Content-Length: 5\r\n\r\n"), |
| 962 | MockRead("Hello"), |
| 963 | }; |
| 964 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 965 | arraysize(data_reads)); |
| 966 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 967 | } |
| 968 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 969 | // Checks that two identical Location headers result in no error. |
| 970 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 971 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 972 | MockRead data_reads[] = { |
| 973 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 974 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 975 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 978 | }; |
| 979 | |
| 980 | HttpRequestInfo request; |
| 981 | request.method = "GET"; |
| 982 | request.url = GURL("http://redirect.com/"); |
| 983 | request.load_flags = 0; |
| 984 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 985 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 986 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 987 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 988 | |
| 989 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 992 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 994 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 995 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 996 | |
| 997 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 998 | |
| 999 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1000 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1001 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1002 | std::string url; |
| 1003 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1004 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1005 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1008 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1009 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1010 | MockRead data_reads[] = { |
| 1011 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1012 | MockRead("Location: http://good.com/\r\n"), |
| 1013 | MockRead("Location: http://evil.com/\r\n"), |
| 1014 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1015 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1016 | }; |
| 1017 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1018 | arraysize(data_reads)); |
| 1019 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1020 | } |
| 1021 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1022 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1023 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1024 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1025 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1026 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1027 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1028 | request.load_flags = 0; |
| 1029 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1030 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1031 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1033 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1034 | trans->SetBeforeProxyHeadersSentCallback( |
| 1035 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1036 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1037 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1038 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1039 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1040 | "Host: www.example.org\r\n" |
| 1041 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1042 | }; |
| 1043 | MockRead data_reads1[] = { |
| 1044 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1045 | MockRead("Server: Blah\r\n"), |
| 1046 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1047 | |
| 1048 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1049 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1050 | }; |
| 1051 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1052 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1053 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1054 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1056 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1058 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1059 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1060 | |
| 1061 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1062 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1063 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1064 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1065 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1066 | |
| 1067 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1068 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1069 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1070 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1071 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1072 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | |
| 1074 | std::string server_header; |
| 1075 | void* iter = NULL; |
| 1076 | bool has_server_header = response->headers->EnumerateHeader( |
| 1077 | &iter, "Server", &server_header); |
| 1078 | EXPECT_TRUE(has_server_header); |
| 1079 | EXPECT_EQ("Blah", server_header); |
| 1080 | |
| 1081 | // Reading should give EOF right away, since there is no message body |
| 1082 | // (despite non-zero content-length). |
| 1083 | std::string response_data; |
| 1084 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1085 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1086 | EXPECT_EQ("", response_data); |
| 1087 | } |
| 1088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1089 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1090 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1091 | |
| 1092 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1093 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1094 | MockRead("hello"), |
| 1095 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1096 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1097 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1098 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1102 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1103 | "hello", "world" |
| 1104 | }; |
| 1105 | |
| 1106 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1109 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1110 | request.load_flags = 0; |
| 1111 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1112 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1115 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1117 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1118 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1119 | |
| 1120 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1121 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1122 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1123 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1124 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1125 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1126 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1127 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1128 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1129 | |
| 1130 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1131 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1132 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1133 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1137 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1138 | ScopedVector<UploadElementReader> element_readers; |
| 1139 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1140 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1141 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1142 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | request.method = "POST"; |
| 1144 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1145 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | request.load_flags = 0; |
| 1147 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1148 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1149 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1150 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1151 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1152 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1153 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1154 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1155 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1156 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1157 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1158 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1161 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1163 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1165 | |
| 1166 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1167 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1170 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1171 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1172 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1173 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1174 | |
| 1175 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1176 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1178 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1179 | } |
| 1180 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1181 | // This test is almost the same as Ignores100 above, but the response contains |
| 1182 | // 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] | 1183 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1184 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1185 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1186 | request.method = "GET"; |
| 1187 | request.url = GURL("http://www.foo.com/"); |
| 1188 | request.load_flags = 0; |
| 1189 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1190 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1191 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1192 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1193 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1194 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1195 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1196 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1197 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1198 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1199 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1200 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1203 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1205 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1206 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1207 | |
| 1208 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1209 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1210 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1211 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1212 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1213 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1214 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1215 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1216 | |
| 1217 | std::string response_data; |
| 1218 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1219 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1220 | EXPECT_EQ("hello world", response_data); |
| 1221 | } |
| 1222 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1223 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1224 | HttpRequestInfo request; |
| 1225 | request.method = "POST"; |
| 1226 | request.url = GURL("http://www.foo.com/"); |
| 1227 | request.load_flags = 0; |
| 1228 | |
| 1229 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1230 | scoped_ptr<HttpTransaction> trans( |
| 1231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1232 | |
| 1233 | MockRead data_reads[] = { |
| 1234 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1235 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1236 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1237 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1238 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1239 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1240 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1241 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1242 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1244 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1245 | rv = callback.WaitForResult(); |
| 1246 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1247 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1248 | std::string response_data; |
| 1249 | rv = ReadTransaction(trans.get(), &response_data); |
| 1250 | EXPECT_EQ(OK, rv); |
| 1251 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1252 | } |
| 1253 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1254 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1255 | HttpRequestInfo request; |
| 1256 | request.method = "POST"; |
| 1257 | request.url = GURL("http://www.foo.com/"); |
| 1258 | request.load_flags = 0; |
| 1259 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1260 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1261 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1262 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1263 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1264 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1265 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1266 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1270 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1272 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1274 | |
| 1275 | rv = callback.WaitForResult(); |
| 1276 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1277 | } |
| 1278 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1279 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1280 | const MockWrite* write_failure, |
| 1281 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1282 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1283 | request.method = "GET"; |
| 1284 | request.url = GURL("http://www.foo.com/"); |
| 1285 | request.load_flags = 0; |
| 1286 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1287 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1288 | session_deps_.net_log = &net_log; |
| 1289 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1290 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1291 | // Written data for successfully sending both requests. |
| 1292 | MockWrite data1_writes[] = { |
| 1293 | MockWrite("GET / HTTP/1.1\r\n" |
| 1294 | "Host: www.foo.com\r\n" |
| 1295 | "Connection: keep-alive\r\n\r\n"), |
| 1296 | MockWrite("GET / HTTP/1.1\r\n" |
| 1297 | "Host: www.foo.com\r\n" |
| 1298 | "Connection: keep-alive\r\n\r\n") |
| 1299 | }; |
| 1300 | |
| 1301 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1303 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1304 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1305 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1307 | |
| 1308 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1309 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1310 | data1_writes[1] = *write_failure; |
| 1311 | } else { |
| 1312 | ASSERT_TRUE(read_failure); |
| 1313 | data1_reads[2] = *read_failure; |
| 1314 | } |
| 1315 | |
| 1316 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1317 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1318 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
| 1320 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1321 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1322 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1323 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1325 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1326 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1328 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | "hello", "world" |
| 1330 | }; |
| 1331 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1332 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1334 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1335 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1336 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1337 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1339 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | |
| 1342 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1343 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1345 | LoadTimingInfo load_timing_info; |
| 1346 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1347 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1348 | if (i == 0) { |
| 1349 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1350 | } else { |
| 1351 | // The second request should be using a new socket. |
| 1352 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1353 | } |
| 1354 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1356 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1357 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1358 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1359 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
| 1361 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1362 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1363 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1364 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | } |
| 1366 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1367 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1368 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1369 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1370 | const MockRead* read_failure, |
| 1371 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1372 | HttpRequestInfo request; |
| 1373 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1374 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1375 | request.load_flags = 0; |
| 1376 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1377 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1378 | session_deps_.net_log = &net_log; |
| 1379 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1380 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1381 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1382 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1383 | if (use_spdy) { |
| 1384 | ssl1.SetNextProto(GetParam()); |
| 1385 | ssl2.SetNextProto(GetParam()); |
| 1386 | } |
| 1387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1389 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1390 | // SPDY versions of the request and response. |
| 1391 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1392 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1393 | scoped_ptr<SpdyFrame> spdy_response( |
| 1394 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1395 | scoped_ptr<SpdyFrame> spdy_data( |
| 1396 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1397 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1398 | // HTTP/1.1 versions of the request and response. |
| 1399 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1400 | "Host: www.foo.com\r\n" |
| 1401 | "Connection: keep-alive\r\n\r\n"; |
| 1402 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1403 | const char kHttpData[] = "hello"; |
| 1404 | |
| 1405 | std::vector<MockRead> data1_reads; |
| 1406 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1407 | if (write_failure) { |
| 1408 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1409 | data1_writes.push_back(*write_failure); |
| 1410 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1411 | } else { |
| 1412 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1413 | if (use_spdy) { |
| 1414 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1415 | } else { |
| 1416 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1417 | } |
| 1418 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1419 | } |
| 1420 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1421 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1422 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1423 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1424 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1425 | std::vector<MockRead> data2_reads; |
| 1426 | std::vector<MockWrite> data2_writes; |
| 1427 | |
| 1428 | if (use_spdy) { |
| 1429 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1430 | |
| 1431 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1432 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1433 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1434 | } else { |
| 1435 | data2_writes.push_back( |
| 1436 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1437 | |
| 1438 | data2_reads.push_back( |
| 1439 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1440 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1441 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1442 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1443 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1444 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1445 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1446 | |
| 1447 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1448 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1449 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1450 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1451 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1452 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1453 | // Wait for the preconnect to complete. |
| 1454 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1455 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1456 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1457 | |
| 1458 | // Make the request. |
| 1459 | TestCompletionCallback callback; |
| 1460 | |
| 1461 | scoped_ptr<HttpTransaction> trans( |
| 1462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1463 | |
| 1464 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1465 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1466 | |
| 1467 | rv = callback.WaitForResult(); |
| 1468 | EXPECT_EQ(OK, rv); |
| 1469 | |
| 1470 | LoadTimingInfo load_timing_info; |
| 1471 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1472 | TestLoadTimingNotReused( |
| 1473 | load_timing_info, |
| 1474 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1475 | |
| 1476 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1477 | ASSERT_TRUE(response != NULL); |
| 1478 | |
| 1479 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1480 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1481 | |
| 1482 | std::string response_data; |
| 1483 | rv = ReadTransaction(trans.get(), &response_data); |
| 1484 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1485 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1486 | } |
| 1487 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1488 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1489 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1490 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1491 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1492 | } |
| 1493 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1494 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1495 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1496 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1497 | } |
| 1498 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1499 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1500 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1501 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1502 | } |
| 1503 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1504 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1505 | // if the socket was a reused keep alive socket. |
| 1506 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1507 | MockRead read_failure(SYNCHRONOUS, |
| 1508 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1509 | "Connection: Keep-Alive\r\n" |
| 1510 | "Content-Length: 6\r\n\r\n" |
| 1511 | "Pickle"); |
| 1512 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1513 | } |
| 1514 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1515 | TEST_P(HttpNetworkTransactionTest, |
| 1516 | PreconnectErrorNotConnectedOnWrite) { |
| 1517 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1518 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1522 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1523 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1527 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1528 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1529 | } |
| 1530 | |
| 1531 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1532 | MockRead read_failure(ASYNC, OK); // EOF |
| 1533 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1534 | } |
| 1535 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1536 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1537 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1538 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1539 | MockRead read_failure(SYNCHRONOUS, |
| 1540 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1541 | "Connection: Keep-Alive\r\n" |
| 1542 | "Content-Length: 6\r\n\r\n" |
| 1543 | "Pickle"); |
| 1544 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1545 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1546 | } |
| 1547 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1548 | TEST_P(HttpNetworkTransactionTest, |
| 1549 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1550 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1551 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1552 | } |
| 1553 | |
| 1554 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1555 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1556 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1557 | } |
| 1558 | |
| 1559 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1560 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1561 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1562 | } |
| 1563 | |
| 1564 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1565 | MockRead read_failure(ASYNC, OK); // EOF |
| 1566 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1567 | } |
| 1568 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1569 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1570 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1572 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1573 | request.load_flags = 0; |
| 1574 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1575 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1576 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1577 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1578 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1579 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1580 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1581 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1582 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1584 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1585 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1588 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1590 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1592 | |
| 1593 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1594 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | // What do various browsers do when the server closes a non-keepalive |
| 1598 | // connection without sending any response header or body? |
| 1599 | // |
| 1600 | // IE7: error page |
| 1601 | // Safari 3.1.2 (Windows): error page |
| 1602 | // Firefox 3.0.1: blank page |
| 1603 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1604 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1605 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1606 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1607 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1608 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1609 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1610 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1611 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1612 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1613 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1614 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1615 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1616 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1617 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1618 | // Test that network access can be deferred and resumed. |
| 1619 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1620 | HttpRequestInfo request; |
| 1621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1622 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1623 | request.load_flags = 0; |
| 1624 | |
| 1625 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1626 | scoped_ptr<HttpTransaction> trans( |
| 1627 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1628 | |
| 1629 | // Defer on OnBeforeNetworkStart. |
| 1630 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1631 | trans->SetBeforeNetworkStartCallback( |
| 1632 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1633 | base::Unretained(&net_start_handler))); |
| 1634 | |
| 1635 | MockRead data_reads[] = { |
| 1636 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1637 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1638 | MockRead("hello"), |
| 1639 | MockRead(SYNCHRONOUS, 0), |
| 1640 | }; |
| 1641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1643 | |
| 1644 | TestCompletionCallback callback; |
| 1645 | |
| 1646 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1647 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1648 | base::MessageLoop::current()->RunUntilIdle(); |
| 1649 | |
| 1650 | // Should have deferred for network start. |
| 1651 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1652 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1653 | |
| 1654 | trans->ResumeNetworkStart(); |
| 1655 | rv = callback.WaitForResult(); |
| 1656 | EXPECT_EQ(OK, rv); |
| 1657 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1658 | |
| 1659 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1660 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1661 | if (rv == ERR_IO_PENDING) |
| 1662 | rv = callback.WaitForResult(); |
| 1663 | EXPECT_EQ(5, rv); |
| 1664 | trans.reset(); |
| 1665 | } |
| 1666 | |
| 1667 | // Test that network use can be deferred and canceled. |
| 1668 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1669 | HttpRequestInfo request; |
| 1670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1671 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1672 | request.load_flags = 0; |
| 1673 | |
| 1674 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1675 | scoped_ptr<HttpTransaction> trans( |
| 1676 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1677 | |
| 1678 | // Defer on OnBeforeNetworkStart. |
| 1679 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1680 | trans->SetBeforeNetworkStartCallback( |
| 1681 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1682 | base::Unretained(&net_start_handler))); |
| 1683 | |
| 1684 | TestCompletionCallback callback; |
| 1685 | |
| 1686 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1688 | base::MessageLoop::current()->RunUntilIdle(); |
| 1689 | |
| 1690 | // Should have deferred for network start. |
| 1691 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1692 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1693 | } |
| 1694 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1695 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1696 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1697 | // destructor in such situations. |
| 1698 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1699 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1700 | HttpRequestInfo request; |
| 1701 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1702 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1703 | request.load_flags = 0; |
| 1704 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1705 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1706 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1707 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1708 | |
| 1709 | MockRead data_reads[] = { |
| 1710 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1711 | MockRead("Connection: keep-alive\r\n"), |
| 1712 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1713 | MockRead("hello"), |
| 1714 | MockRead(SYNCHRONOUS, 0), |
| 1715 | }; |
| 1716 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1717 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1718 | |
| 1719 | TestCompletionCallback callback; |
| 1720 | |
| 1721 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1723 | |
| 1724 | rv = callback.WaitForResult(); |
| 1725 | EXPECT_EQ(OK, rv); |
| 1726 | |
| 1727 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1728 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1729 | if (rv == ERR_IO_PENDING) |
| 1730 | rv = callback.WaitForResult(); |
| 1731 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1732 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1733 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1734 | |
| 1735 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1736 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1737 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1738 | } |
| 1739 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1740 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1741 | HttpRequestInfo request; |
| 1742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1743 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1744 | request.load_flags = 0; |
| 1745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1746 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1747 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1748 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1749 | |
| 1750 | MockRead data_reads[] = { |
| 1751 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1752 | MockRead("Connection: keep-alive\r\n"), |
| 1753 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1754 | MockRead(SYNCHRONOUS, 0), |
| 1755 | }; |
| 1756 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1758 | |
| 1759 | TestCompletionCallback callback; |
| 1760 | |
| 1761 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1762 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1763 | |
| 1764 | rv = callback.WaitForResult(); |
| 1765 | EXPECT_EQ(OK, rv); |
| 1766 | |
| 1767 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1768 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1769 | if (rv == ERR_IO_PENDING) |
| 1770 | rv = callback.WaitForResult(); |
| 1771 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1772 | |
| 1773 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1774 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1775 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1776 | } |
| 1777 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1778 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1779 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1780 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1781 | HttpRequestInfo request; |
| 1782 | request.method = "GET"; |
| 1783 | request.url = GURL("http://www.foo.com/"); |
| 1784 | request.load_flags = 0; |
| 1785 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1787 | session_deps_.net_log = &net_log; |
| 1788 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1789 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1790 | // Note that because all these reads happen in the same |
| 1791 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1792 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1793 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1794 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1795 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1796 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1797 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1798 | "Content-Length: 0\r\n\r\n"), |
| 1799 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1800 | "Content-Length: 5\r\n\r\n" |
| 1801 | "hello"), |
| 1802 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1803 | "Content-Length: 0\r\n\r\n"), |
| 1804 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1805 | "Content-Length: 5\r\n\r\n" |
| 1806 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1807 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1808 | MockRead("hello"), |
| 1809 | }; |
| 1810 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1811 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1812 | |
| 1813 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1814 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1815 | }; |
| 1816 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1818 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1819 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1820 | std::string response_lines[kNumUnreadBodies]; |
| 1821 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1822 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1823 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1824 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1825 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1826 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1827 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1829 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1830 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1831 | |
| 1832 | rv = callback.WaitForResult(); |
| 1833 | EXPECT_EQ(OK, rv); |
| 1834 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1835 | LoadTimingInfo load_timing_info; |
| 1836 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1837 | if (i == 0) { |
| 1838 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1839 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1840 | } else { |
| 1841 | TestLoadTimingReused(load_timing_info); |
| 1842 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1843 | } |
| 1844 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1846 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1847 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1848 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1849 | response_lines[i] = response->headers->GetStatusLine(); |
| 1850 | |
| 1851 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1852 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1853 | |
| 1854 | const char* const kStatusLines[] = { |
| 1855 | "HTTP/1.1 204 No Content", |
| 1856 | "HTTP/1.1 205 Reset Content", |
| 1857 | "HTTP/1.1 304 Not Modified", |
| 1858 | "HTTP/1.1 302 Found", |
| 1859 | "HTTP/1.1 302 Found", |
| 1860 | "HTTP/1.1 301 Moved Permanently", |
| 1861 | "HTTP/1.1 301 Moved Permanently", |
| 1862 | }; |
| 1863 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1864 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1865 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1866 | |
| 1867 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1868 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1870 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1871 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1872 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1873 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1875 | rv = callback.WaitForResult(); |
| 1876 | EXPECT_EQ(OK, rv); |
| 1877 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1878 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1879 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1880 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1881 | std::string response_data; |
| 1882 | rv = ReadTransaction(trans.get(), &response_data); |
| 1883 | EXPECT_EQ(OK, rv); |
| 1884 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1885 | } |
| 1886 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1887 | // Test the request-challenge-retry sequence for basic auth. |
| 1888 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1889 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1890 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1892 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1893 | request.load_flags = 0; |
| 1894 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1895 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1896 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1897 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1898 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1900 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1901 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1902 | MockWrite( |
| 1903 | "GET / HTTP/1.1\r\n" |
| 1904 | "Host: www.example.org\r\n" |
| 1905 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1906 | }; |
| 1907 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1908 | MockRead data_reads1[] = { |
| 1909 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1910 | // Give a couple authenticate options (only the middle one is actually |
| 1911 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1912 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1913 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1914 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1915 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1916 | // Large content-length -- won't matter, as connection will be reset. |
| 1917 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1918 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1919 | }; |
| 1920 | |
| 1921 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1922 | // be issuing -- the final header line contains the credentials. |
| 1923 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1924 | MockWrite( |
| 1925 | "GET / HTTP/1.1\r\n" |
| 1926 | "Host: www.example.org\r\n" |
| 1927 | "Connection: keep-alive\r\n" |
| 1928 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1929 | }; |
| 1930 | |
| 1931 | // Lastly, the server responds with the actual content. |
| 1932 | MockRead data_reads2[] = { |
| 1933 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1934 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1935 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1936 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1937 | }; |
| 1938 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1939 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1940 | data_writes1, arraysize(data_writes1)); |
| 1941 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1942 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1943 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1944 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1946 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1948 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1949 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1950 | |
| 1951 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1952 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1953 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1954 | LoadTimingInfo load_timing_info1; |
| 1955 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1956 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1957 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1958 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1959 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1960 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1961 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1962 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1963 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1965 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1967 | rv = trans->RestartWithAuth( |
| 1968 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1970 | |
| 1971 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1972 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1973 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1974 | LoadTimingInfo load_timing_info2; |
| 1975 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1976 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1977 | // The load timing after restart should have a new socket ID, and times after |
| 1978 | // those of the first load timing. |
| 1979 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1980 | load_timing_info2.connect_timing.connect_start); |
| 1981 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1982 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1983 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1984 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1985 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1986 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1987 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1988 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1989 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1990 | } |
| 1991 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1992 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1993 | HttpRequestInfo request; |
| 1994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1995 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1996 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1997 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1998 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1999 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2001 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2002 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2003 | MockWrite( |
| 2004 | "GET / HTTP/1.1\r\n" |
| 2005 | "Host: www.example.org\r\n" |
| 2006 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2007 | }; |
| 2008 | |
| 2009 | MockRead data_reads[] = { |
| 2010 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2011 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2012 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2013 | // Large content-length -- won't matter, as connection will be reset. |
| 2014 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2015 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2016 | }; |
| 2017 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2019 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2021 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2023 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2024 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2025 | |
| 2026 | rv = callback.WaitForResult(); |
| 2027 | EXPECT_EQ(0, rv); |
| 2028 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2029 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2030 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2031 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2032 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2033 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2034 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2035 | } |
| 2036 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2037 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2038 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2039 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2040 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2042 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2043 | request.load_flags = 0; |
| 2044 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2045 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2046 | session_deps_.net_log = &log; |
| 2047 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2048 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2049 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2050 | MockWrite( |
| 2051 | "GET / HTTP/1.1\r\n" |
| 2052 | "Host: www.example.org\r\n" |
| 2053 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2054 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2055 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2056 | // be issuing -- the final header line contains the credentials. |
| 2057 | MockWrite( |
| 2058 | "GET / HTTP/1.1\r\n" |
| 2059 | "Host: www.example.org\r\n" |
| 2060 | "Connection: keep-alive\r\n" |
| 2061 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2062 | }; |
| 2063 | |
| 2064 | MockRead data_reads1[] = { |
| 2065 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2066 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2067 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2068 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2069 | MockRead("Unauthorized\r\n"), |
| 2070 | |
| 2071 | // Lastly, the server responds with the actual content. |
| 2072 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2073 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2074 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2075 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2076 | }; |
| 2077 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2078 | // If there is a regression where we disconnect a Keep-Alive |
| 2079 | // connection during an auth roundtrip, we'll end up reading this. |
| 2080 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2081 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2082 | }; |
| 2083 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2084 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2085 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2086 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2087 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2088 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2089 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2091 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2092 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2093 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2094 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2095 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2096 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2097 | |
| 2098 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2099 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2100 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2101 | LoadTimingInfo load_timing_info1; |
| 2102 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2103 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2104 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2105 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2106 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2107 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2109 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2111 | rv = trans->RestartWithAuth( |
| 2112 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2113 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2114 | |
| 2115 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2116 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2117 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2118 | LoadTimingInfo load_timing_info2; |
| 2119 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2120 | TestLoadTimingReused(load_timing_info2); |
| 2121 | // The load timing after restart should have the same socket ID, and times |
| 2122 | // those of the first load timing. |
| 2123 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2124 | load_timing_info2.send_start); |
| 2125 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2126 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2127 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2128 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2129 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2130 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2131 | |
| 2132 | std::string response_data; |
| 2133 | rv = ReadTransaction(trans.get(), &response_data); |
| 2134 | EXPECT_EQ(OK, rv); |
| 2135 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2136 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2140 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2141 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2142 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2143 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2144 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2145 | request.load_flags = 0; |
| 2146 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2147 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2148 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2149 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2150 | MockWrite( |
| 2151 | "GET / HTTP/1.1\r\n" |
| 2152 | "Host: www.example.org\r\n" |
| 2153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2154 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2155 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2156 | // be issuing -- the final header line contains the credentials. |
| 2157 | MockWrite( |
| 2158 | "GET / HTTP/1.1\r\n" |
| 2159 | "Host: www.example.org\r\n" |
| 2160 | "Connection: keep-alive\r\n" |
| 2161 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2162 | }; |
| 2163 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2164 | MockRead data_reads1[] = { |
| 2165 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2166 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2167 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2168 | |
| 2169 | // Lastly, the server responds with the actual content. |
| 2170 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2171 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2172 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2173 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2174 | }; |
| 2175 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2176 | // An incorrect reconnect would cause this to be read. |
| 2177 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2178 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2179 | }; |
| 2180 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2181 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2182 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2183 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2184 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2186 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2188 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2189 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2190 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2192 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2193 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2194 | |
| 2195 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2196 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2197 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2198 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2199 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2200 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2202 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2204 | rv = trans->RestartWithAuth( |
| 2205 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2206 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2207 | |
| 2208 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2209 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2210 | |
| 2211 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2212 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2213 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2214 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2218 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2219 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2220 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2221 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2222 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2223 | request.load_flags = 0; |
| 2224 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2225 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2226 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2227 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2228 | MockWrite( |
| 2229 | "GET / HTTP/1.1\r\n" |
| 2230 | "Host: www.example.org\r\n" |
| 2231 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2232 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2233 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2234 | // be issuing -- the final header line contains the credentials. |
| 2235 | MockWrite( |
| 2236 | "GET / HTTP/1.1\r\n" |
| 2237 | "Host: www.example.org\r\n" |
| 2238 | "Connection: keep-alive\r\n" |
| 2239 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2240 | }; |
| 2241 | |
| 2242 | // Respond with 5 kb of response body. |
| 2243 | std::string large_body_string("Unauthorized"); |
| 2244 | large_body_string.append(5 * 1024, ' '); |
| 2245 | large_body_string.append("\r\n"); |
| 2246 | |
| 2247 | MockRead data_reads1[] = { |
| 2248 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2249 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2250 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2251 | // 5134 = 12 + 5 * 1024 + 2 |
| 2252 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2253 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | |
| 2255 | // Lastly, the server responds with the actual content. |
| 2256 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2257 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2258 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2259 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2260 | }; |
| 2261 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2262 | // An incorrect reconnect would cause this to be read. |
| 2263 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2264 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2265 | }; |
| 2266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2268 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2269 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2270 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2271 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2272 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2274 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2275 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2276 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2278 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2279 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2280 | |
| 2281 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2282 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2283 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2284 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2285 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2286 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2288 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2290 | rv = trans->RestartWithAuth( |
| 2291 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2293 | |
| 2294 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2295 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2296 | |
| 2297 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2298 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2299 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2300 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2304 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2305 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2306 | HttpRequestInfo request; |
| 2307 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2308 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2309 | request.load_flags = 0; |
| 2310 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2311 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2312 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2313 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2314 | MockWrite( |
| 2315 | "GET / HTTP/1.1\r\n" |
| 2316 | "Host: www.example.org\r\n" |
| 2317 | "Connection: keep-alive\r\n\r\n"), |
| 2318 | // This simulates the seemingly successful write to a closed connection |
| 2319 | // if the bug is not fixed. |
| 2320 | MockWrite( |
| 2321 | "GET / HTTP/1.1\r\n" |
| 2322 | "Host: www.example.org\r\n" |
| 2323 | "Connection: keep-alive\r\n" |
| 2324 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2325 | }; |
| 2326 | |
| 2327 | MockRead data_reads1[] = { |
| 2328 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2329 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2330 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2331 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2332 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2333 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2334 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2335 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2336 | }; |
| 2337 | |
| 2338 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2339 | // be issuing -- the final header line contains the credentials. |
| 2340 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2341 | MockWrite( |
| 2342 | "GET / HTTP/1.1\r\n" |
| 2343 | "Host: www.example.org\r\n" |
| 2344 | "Connection: keep-alive\r\n" |
| 2345 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2346 | }; |
| 2347 | |
| 2348 | // Lastly, the server responds with the actual content. |
| 2349 | MockRead data_reads2[] = { |
| 2350 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2351 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2352 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2353 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2354 | }; |
| 2355 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2356 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2357 | data_writes1, arraysize(data_writes1)); |
| 2358 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2359 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2360 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2361 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2363 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2364 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2365 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2366 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2367 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2369 | |
| 2370 | rv = callback1.WaitForResult(); |
| 2371 | EXPECT_EQ(OK, rv); |
| 2372 | |
| 2373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2374 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2375 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2377 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2379 | rv = trans->RestartWithAuth( |
| 2380 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2381 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2382 | |
| 2383 | rv = callback2.WaitForResult(); |
| 2384 | EXPECT_EQ(OK, rv); |
| 2385 | |
| 2386 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2387 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2388 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2389 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2390 | } |
| 2391 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2392 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2393 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2394 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2395 | HttpRequestInfo request; |
| 2396 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2397 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2398 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2399 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2400 | |
| 2401 | // Configure against proxy server "myproxy:70". |
| 2402 | session_deps_.proxy_service.reset( |
| 2403 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2404 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2405 | session_deps_.net_log = log.bound().net_log(); |
| 2406 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2407 | |
| 2408 | // Since we have proxy, should try to establish tunnel. |
| 2409 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2410 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2411 | "Host: www.example.org\r\n" |
| 2412 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2413 | }; |
| 2414 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2415 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2416 | // connection. |
| 2417 | MockRead data_reads1[] = { |
| 2418 | // No credentials. |
| 2419 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2420 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2421 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2422 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2423 | // Since the first connection couldn't be reused, need to establish another |
| 2424 | // once given credentials. |
| 2425 | MockWrite data_writes2[] = { |
| 2426 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2427 | // be issuing -- the final header line contains the credentials. |
| 2428 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2429 | "Host: www.example.org\r\n" |
| 2430 | "Proxy-Connection: keep-alive\r\n" |
| 2431 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2432 | |
| 2433 | MockWrite("GET / HTTP/1.1\r\n" |
| 2434 | "Host: www.example.org\r\n" |
| 2435 | "Connection: keep-alive\r\n\r\n"), |
| 2436 | }; |
| 2437 | |
| 2438 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2439 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2440 | |
| 2441 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2442 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2443 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2444 | MockRead(SYNCHRONOUS, "hello"), |
| 2445 | }; |
| 2446 | |
| 2447 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2448 | data_writes1, arraysize(data_writes1)); |
| 2449 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2450 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2451 | data_writes2, arraysize(data_writes2)); |
| 2452 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2453 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2455 | |
| 2456 | TestCompletionCallback callback1; |
| 2457 | |
| 2458 | scoped_ptr<HttpTransaction> trans( |
| 2459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2460 | |
| 2461 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2463 | |
| 2464 | rv = callback1.WaitForResult(); |
| 2465 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2466 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2467 | log.GetEntries(&entries); |
| 2468 | size_t pos = ExpectLogContainsSomewhere( |
| 2469 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2470 | NetLog::PHASE_NONE); |
| 2471 | ExpectLogContainsSomewhere( |
| 2472 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2473 | NetLog::PHASE_NONE); |
| 2474 | |
| 2475 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2476 | ASSERT_TRUE(response != NULL); |
| 2477 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2478 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2479 | EXPECT_EQ(407, response->headers->response_code()); |
| 2480 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2481 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2482 | |
| 2483 | LoadTimingInfo load_timing_info; |
| 2484 | // CONNECT requests and responses are handled at the connect job level, so |
| 2485 | // the transaction does not yet have a connection. |
| 2486 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2487 | |
| 2488 | TestCompletionCallback callback2; |
| 2489 | |
| 2490 | rv = |
| 2491 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2493 | |
| 2494 | rv = callback2.WaitForResult(); |
| 2495 | EXPECT_EQ(OK, rv); |
| 2496 | |
| 2497 | response = trans->GetResponseInfo(); |
| 2498 | ASSERT_TRUE(response != NULL); |
| 2499 | |
| 2500 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2501 | EXPECT_EQ(200, response->headers->response_code()); |
| 2502 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2503 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2504 | |
| 2505 | // The password prompt info should not be set. |
| 2506 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2507 | |
| 2508 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2509 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2510 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2511 | |
| 2512 | trans.reset(); |
| 2513 | session->CloseAllConnections(); |
| 2514 | } |
| 2515 | |
| 2516 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2517 | // that requires a restart when setting up an SSL tunnel. |
| 2518 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2519 | HttpRequestInfo request; |
| 2520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2521 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2522 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2523 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2524 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2525 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2526 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2527 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2528 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2529 | session_deps_.net_log = log.bound().net_log(); |
| 2530 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2531 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2532 | // Since we have proxy, should try to establish tunnel. |
| 2533 | MockWrite data_writes1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2534 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2535 | "Host: www.example.org\r\n" |
| 2536 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2537 | }; |
| 2538 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2539 | // The proxy responds to the connect with a 407, using a non-persistent |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2540 | // connection. |
| 2541 | MockRead data_reads1[] = { |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2542 | // No credentials. |
| 2543 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2544 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2545 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2546 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2547 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2548 | MockWrite data_writes2[] = { |
| 2549 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2550 | // be issuing -- the final header line contains the credentials. |
| 2551 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2552 | "Host: www.example.org\r\n" |
| 2553 | "Proxy-Connection: keep-alive\r\n" |
| 2554 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2555 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2556 | MockWrite("GET / HTTP/1.1\r\n" |
| 2557 | "Host: www.example.org\r\n" |
| 2558 | "Connection: keep-alive\r\n\r\n"), |
| 2559 | }; |
| 2560 | |
| 2561 | MockRead data_reads2[] = { |
| 2562 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2563 | |
| 2564 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2566 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2567 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2568 | }; |
| 2569 | |
| 2570 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2571 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2572 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2573 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2574 | data_writes2, arraysize(data_writes2)); |
| 2575 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2576 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2579 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2580 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2581 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2582 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2584 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2586 | |
| 2587 | rv = callback1.WaitForResult(); |
| 2588 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2589 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2590 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2591 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2592 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2593 | NetLog::PHASE_NONE); |
| 2594 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2595 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2596 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2597 | NetLog::PHASE_NONE); |
| 2598 | |
| 2599 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2600 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2601 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2602 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2603 | EXPECT_EQ(407, response->headers->response_code()); |
| 2604 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2605 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2606 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2607 | LoadTimingInfo load_timing_info; |
| 2608 | // CONNECT requests and responses are handled at the connect job level, so |
| 2609 | // the transaction does not yet have a connection. |
| 2610 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2612 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2614 | rv = trans->RestartWithAuth( |
| 2615 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2616 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2617 | |
| 2618 | rv = callback2.WaitForResult(); |
| 2619 | EXPECT_EQ(OK, rv); |
| 2620 | |
| 2621 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2622 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2623 | |
| 2624 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2625 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2626 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2627 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2628 | |
| 2629 | // The password prompt info should not be set. |
| 2630 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2631 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2632 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2633 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2634 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2635 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2636 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2637 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2638 | } |
| 2639 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2640 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2641 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2642 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2643 | HttpRequestInfo request; |
| 2644 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2645 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2646 | // Ensure that proxy authentication is attempted even |
| 2647 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2648 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2649 | |
| 2650 | // Configure against proxy server "myproxy:70". |
| 2651 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2652 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2653 | session_deps_.net_log = log.bound().net_log(); |
| 2654 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2655 | |
| 2656 | scoped_ptr<HttpTransaction> trans( |
| 2657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2658 | |
| 2659 | // Since we have proxy, should try to establish tunnel. |
| 2660 | MockWrite data_writes1[] = { |
| 2661 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2662 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2663 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2664 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2665 | |
| 2666 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2667 | // be issuing -- the final header line contains the credentials. |
| 2668 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2669 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2670 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2671 | "Proxy-Connection: keep-alive\r\n" |
| 2672 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2673 | }; |
| 2674 | |
| 2675 | // The proxy responds to the connect with a 407, using a persistent |
| 2676 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2677 | MockRead data_reads1[] = { |
| 2678 | // No credentials. |
| 2679 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2680 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2681 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2682 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2683 | MockRead("0123456789"), |
| 2684 | |
| 2685 | // Wrong credentials (wrong password). |
| 2686 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2687 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2688 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2689 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2690 | // No response body because the test stops reading here. |
| 2691 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2692 | }; |
| 2693 | |
| 2694 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2695 | data_writes1, arraysize(data_writes1)); |
| 2696 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2697 | |
| 2698 | TestCompletionCallback callback1; |
| 2699 | |
| 2700 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2701 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2702 | |
| 2703 | rv = callback1.WaitForResult(); |
| 2704 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2705 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2706 | log.GetEntries(&entries); |
| 2707 | size_t pos = ExpectLogContainsSomewhere( |
| 2708 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2709 | NetLog::PHASE_NONE); |
| 2710 | ExpectLogContainsSomewhere( |
| 2711 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2712 | NetLog::PHASE_NONE); |
| 2713 | |
| 2714 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2715 | ASSERT_TRUE(response); |
| 2716 | ASSERT_TRUE(response->headers); |
| 2717 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2718 | EXPECT_EQ(407, response->headers->response_code()); |
| 2719 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2720 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2721 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2722 | |
| 2723 | TestCompletionCallback callback2; |
| 2724 | |
| 2725 | // Wrong password (should be "bar"). |
| 2726 | rv = |
| 2727 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2728 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2729 | |
| 2730 | rv = callback2.WaitForResult(); |
| 2731 | EXPECT_EQ(OK, rv); |
| 2732 | |
| 2733 | response = trans->GetResponseInfo(); |
| 2734 | ASSERT_TRUE(response); |
| 2735 | ASSERT_TRUE(response->headers); |
| 2736 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2737 | EXPECT_EQ(407, response->headers->response_code()); |
| 2738 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2739 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2740 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2741 | |
| 2742 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2743 | // out of scope. |
| 2744 | session->CloseAllConnections(); |
| 2745 | } |
| 2746 | |
| 2747 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2748 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2749 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2750 | HttpRequestInfo request; |
| 2751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2752 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2753 | // Ensure that proxy authentication is attempted even |
| 2754 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2755 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2756 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2757 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2758 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2759 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2760 | session_deps_.net_log = log.bound().net_log(); |
| 2761 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2762 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2763 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2764 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2765 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2766 | // Since we have proxy, should try to establish tunnel. |
| 2767 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2768 | MockWrite( |
| 2769 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2770 | "Host: www.example.org\r\n" |
| 2771 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2772 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2773 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2774 | // be issuing -- the final header line contains the credentials. |
| 2775 | MockWrite( |
| 2776 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2777 | "Host: www.example.org\r\n" |
| 2778 | "Proxy-Connection: keep-alive\r\n" |
| 2779 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | }; |
| 2781 | |
| 2782 | // The proxy responds to the connect with a 407, using a persistent |
| 2783 | // connection. |
| 2784 | MockRead data_reads1[] = { |
| 2785 | // No credentials. |
| 2786 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2787 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2788 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2789 | MockRead("0123456789"), |
| 2790 | |
| 2791 | // Wrong credentials (wrong password). |
| 2792 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2793 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2794 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2795 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2796 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | }; |
| 2798 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2799 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2800 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2803 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2805 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2806 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | |
| 2808 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2809 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2810 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2811 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2812 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2813 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2814 | NetLog::PHASE_NONE); |
| 2815 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2816 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2817 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2818 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2820 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2821 | ASSERT_TRUE(response); |
| 2822 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2823 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2824 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2825 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2826 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2827 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2829 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2830 | |
| 2831 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2832 | rv = trans->RestartWithAuth( |
| 2833 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2834 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2835 | |
| 2836 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2837 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
| 2839 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2840 | ASSERT_TRUE(response); |
| 2841 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2842 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2843 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2844 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2845 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2846 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2847 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2848 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2849 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2850 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2851 | } |
| 2852 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2853 | // Test the case a proxy closes a socket while the challenge body is being |
| 2854 | // drained. |
| 2855 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 2856 | HttpRequestInfo request; |
| 2857 | request.method = "GET"; |
| 2858 | request.url = GURL("https://www.example.org/"); |
| 2859 | // Ensure that proxy authentication is attempted even |
| 2860 | // when the no authentication data flag is set. |
| 2861 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2862 | |
| 2863 | // Configure against proxy server "myproxy:70". |
| 2864 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2865 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2866 | |
| 2867 | scoped_ptr<HttpTransaction> trans( |
| 2868 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2869 | |
| 2870 | // Since we have proxy, should try to establish tunnel. |
| 2871 | MockWrite data_writes1[] = { |
| 2872 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2873 | "Host: www.example.org\r\n" |
| 2874 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2875 | }; |
| 2876 | |
| 2877 | // The proxy responds to the connect with a 407, using a persistent |
| 2878 | // connection. |
| 2879 | MockRead data_reads1[] = { |
| 2880 | // No credentials. |
| 2881 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2882 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2883 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 2884 | // Server hands up in the middle of the body. |
| 2885 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 2886 | }; |
| 2887 | |
| 2888 | MockWrite data_writes2[] = { |
| 2889 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2890 | // be issuing -- the final header line contains the credentials. |
| 2891 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2892 | "Host: www.example.org\r\n" |
| 2893 | "Proxy-Connection: keep-alive\r\n" |
| 2894 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2895 | |
| 2896 | MockWrite("GET / HTTP/1.1\r\n" |
| 2897 | "Host: www.example.org\r\n" |
| 2898 | "Connection: keep-alive\r\n\r\n"), |
| 2899 | }; |
| 2900 | |
| 2901 | MockRead data_reads2[] = { |
| 2902 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2903 | |
| 2904 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2905 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2906 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2907 | MockRead(SYNCHRONOUS, "hello"), |
| 2908 | }; |
| 2909 | |
| 2910 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2911 | data_writes1, arraysize(data_writes1)); |
| 2912 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2913 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2914 | data_writes2, arraysize(data_writes2)); |
| 2915 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2916 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2918 | |
| 2919 | TestCompletionCallback callback; |
| 2920 | |
| 2921 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2922 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2923 | |
| 2924 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2925 | ASSERT_TRUE(response); |
| 2926 | ASSERT_TRUE(response->headers); |
| 2927 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2928 | EXPECT_EQ(407, response->headers->response_code()); |
| 2929 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2930 | |
| 2931 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 2932 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 2933 | |
| 2934 | response = trans->GetResponseInfo(); |
| 2935 | ASSERT_TRUE(response); |
| 2936 | ASSERT_TRUE(response->headers); |
| 2937 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2938 | EXPECT_EQ(200, response->headers->response_code()); |
| 2939 | std::string body; |
| 2940 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 2941 | EXPECT_EQ("hello", body); |
| 2942 | } |
| 2943 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2944 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2945 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2946 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2947 | HttpRequestInfo request; |
| 2948 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2949 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2950 | request.load_flags = 0; |
| 2951 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2952 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2953 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2954 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2955 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2956 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2957 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2958 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2959 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2960 | // Since we have proxy, should try to establish tunnel. |
| 2961 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2962 | MockWrite( |
| 2963 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2964 | "Host: www.example.org\r\n" |
| 2965 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2966 | }; |
| 2967 | |
| 2968 | // The proxy responds to the connect with a 407. |
| 2969 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2970 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2971 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2972 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2973 | MockRead("0123456789"), // Should not be reached. |
| 2974 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2975 | }; |
| 2976 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2978 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2981 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2983 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2984 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2985 | |
| 2986 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2987 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2988 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2990 | ASSERT_TRUE(response); |
| 2991 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2992 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2993 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2994 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2995 | |
| 2996 | std::string response_data; |
| 2997 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2998 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2999 | |
| 3000 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3001 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3002 | } |
| 3003 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3004 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3005 | // caller when the proxy responds to CONNECT with 407. |
| 3006 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3007 | HttpRequestInfo request; |
| 3008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3009 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3010 | request.load_flags = 0; |
| 3011 | |
| 3012 | // Configure against proxy server "myproxy:70". |
| 3013 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 3014 | |
| 3015 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3016 | |
| 3017 | scoped_ptr<HttpTransaction> trans( |
| 3018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3019 | |
| 3020 | // Since we have proxy, should try to establish tunnel. |
| 3021 | MockWrite data_writes[] = { |
| 3022 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3023 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3024 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3025 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3026 | }; |
| 3027 | |
| 3028 | // The proxy responds to the connect with a 407. |
| 3029 | MockRead data_reads[] = { |
| 3030 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3031 | MockRead("X-Foo: bar\r\n"), |
| 3032 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3033 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3034 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3035 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3036 | }; |
| 3037 | |
| 3038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3039 | arraysize(data_writes)); |
| 3040 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3041 | |
| 3042 | TestCompletionCallback callback; |
| 3043 | |
| 3044 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3046 | |
| 3047 | rv = callback.WaitForResult(); |
| 3048 | EXPECT_EQ(OK, rv); |
| 3049 | |
| 3050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3051 | ASSERT_TRUE(response); |
| 3052 | ASSERT_TRUE(response->headers); |
| 3053 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3054 | EXPECT_EQ(407, response->headers->response_code()); |
| 3055 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3056 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3057 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3058 | |
| 3059 | std::string response_data; |
| 3060 | rv = ReadTransaction(trans.get(), &response_data); |
| 3061 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3062 | |
| 3063 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3064 | session->CloseAllConnections(); |
| 3065 | } |
| 3066 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3067 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3068 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3069 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3070 | HttpRequestInfo request; |
| 3071 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3072 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3073 | request.load_flags = 0; |
| 3074 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3075 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 3076 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3077 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3079 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3080 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3081 | MockWrite( |
| 3082 | "GET / HTTP/1.1\r\n" |
| 3083 | "Host: www.example.org\r\n" |
| 3084 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3085 | }; |
| 3086 | |
| 3087 | MockRead data_reads1[] = { |
| 3088 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3089 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3090 | // Large content-length -- won't matter, as connection will be reset. |
| 3091 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3092 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3093 | }; |
| 3094 | |
| 3095 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3096 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3097 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3099 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3101 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3103 | |
| 3104 | rv = callback.WaitForResult(); |
| 3105 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3106 | } |
| 3107 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3108 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3109 | // through a non-authenticating proxy. The request should fail with |
| 3110 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3111 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3112 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3113 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3114 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3115 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3116 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3117 | HttpRequestInfo request; |
| 3118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3119 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3120 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3121 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3122 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3123 | session_deps_.net_log = log.bound().net_log(); |
| 3124 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3125 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3126 | // Since we have proxy, should try to establish tunnel. |
| 3127 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3128 | MockWrite( |
| 3129 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3130 | "Host: www.example.org\r\n" |
| 3131 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3132 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3133 | MockWrite( |
| 3134 | "GET / HTTP/1.1\r\n" |
| 3135 | "Host: www.example.org\r\n" |
| 3136 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3137 | }; |
| 3138 | |
| 3139 | MockRead data_reads1[] = { |
| 3140 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3141 | |
| 3142 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3143 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3144 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3145 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3146 | }; |
| 3147 | |
| 3148 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3149 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3150 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3151 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3153 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3154 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3155 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3156 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3159 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3161 | |
| 3162 | rv = callback1.WaitForResult(); |
| 3163 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3164 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3165 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3166 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3167 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3168 | NetLog::PHASE_NONE); |
| 3169 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3170 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3171 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3172 | NetLog::PHASE_NONE); |
| 3173 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3174 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3175 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3176 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3177 | HttpRequestInfo request1; |
| 3178 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3179 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3180 | |
| 3181 | HttpRequestInfo request2; |
| 3182 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3183 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3184 | |
| 3185 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3186 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3187 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3188 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3189 | session_deps_.net_log = log.bound().net_log(); |
| 3190 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3191 | |
| 3192 | // Since we have proxy, should try to establish tunnel. |
| 3193 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3194 | MockWrite( |
| 3195 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3196 | "Host: www.example.org\r\n" |
| 3197 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3199 | MockWrite( |
| 3200 | "GET /1 HTTP/1.1\r\n" |
| 3201 | "Host: www.example.org\r\n" |
| 3202 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3203 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3204 | MockWrite( |
| 3205 | "GET /2 HTTP/1.1\r\n" |
| 3206 | "Host: www.example.org\r\n" |
| 3207 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3208 | }; |
| 3209 | |
| 3210 | // The proxy responds to the connect with a 407, using a persistent |
| 3211 | // connection. |
| 3212 | MockRead data_reads1[] = { |
| 3213 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3214 | |
| 3215 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3216 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3217 | MockRead(SYNCHRONOUS, "1"), |
| 3218 | |
| 3219 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3220 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3221 | MockRead(SYNCHRONOUS, "22"), |
| 3222 | }; |
| 3223 | |
| 3224 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3225 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3226 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3227 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3228 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3229 | |
| 3230 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3231 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3233 | |
| 3234 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3236 | |
| 3237 | rv = callback1.WaitForResult(); |
| 3238 | EXPECT_EQ(OK, rv); |
| 3239 | |
| 3240 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3241 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3242 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3243 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3244 | |
| 3245 | LoadTimingInfo load_timing_info1; |
| 3246 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3247 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3248 | |
| 3249 | trans1.reset(); |
| 3250 | |
| 3251 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3252 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3253 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3254 | |
| 3255 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3257 | |
| 3258 | rv = callback2.WaitForResult(); |
| 3259 | EXPECT_EQ(OK, rv); |
| 3260 | |
| 3261 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3262 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3263 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3264 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3265 | |
| 3266 | LoadTimingInfo load_timing_info2; |
| 3267 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3268 | TestLoadTimingReused(load_timing_info2); |
| 3269 | |
| 3270 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3271 | |
| 3272 | trans2.reset(); |
| 3273 | session->CloseAllConnections(); |
| 3274 | } |
| 3275 | |
| 3276 | // 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] | 3277 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3278 | HttpRequestInfo request1; |
| 3279 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3280 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3281 | |
| 3282 | HttpRequestInfo request2; |
| 3283 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3284 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3285 | |
| 3286 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3287 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3288 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3289 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3290 | session_deps_.net_log = log.bound().net_log(); |
| 3291 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3292 | |
| 3293 | // Since we have proxy, should try to establish tunnel. |
| 3294 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3295 | MockWrite( |
| 3296 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3297 | "Host: www.example.org\r\n" |
| 3298 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3299 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3300 | MockWrite( |
| 3301 | "GET /1 HTTP/1.1\r\n" |
| 3302 | "Host: www.example.org\r\n" |
| 3303 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3304 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3305 | MockWrite( |
| 3306 | "GET /2 HTTP/1.1\r\n" |
| 3307 | "Host: www.example.org\r\n" |
| 3308 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3309 | }; |
| 3310 | |
| 3311 | // The proxy responds to the connect with a 407, using a persistent |
| 3312 | // connection. |
| 3313 | MockRead data_reads1[] = { |
| 3314 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3315 | |
| 3316 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3317 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3318 | MockRead(SYNCHRONOUS, "1"), |
| 3319 | |
| 3320 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3321 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3322 | MockRead(SYNCHRONOUS, "22"), |
| 3323 | }; |
| 3324 | |
| 3325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3326 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3328 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3329 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3330 | |
| 3331 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3332 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3334 | |
| 3335 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3337 | |
| 3338 | rv = callback1.WaitForResult(); |
| 3339 | EXPECT_EQ(OK, rv); |
| 3340 | |
| 3341 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3342 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3343 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3344 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3345 | |
| 3346 | LoadTimingInfo load_timing_info1; |
| 3347 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3348 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3349 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3350 | |
| 3351 | trans1.reset(); |
| 3352 | |
| 3353 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3354 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3356 | |
| 3357 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3359 | |
| 3360 | rv = callback2.WaitForResult(); |
| 3361 | EXPECT_EQ(OK, rv); |
| 3362 | |
| 3363 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3364 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3365 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3366 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3367 | |
| 3368 | LoadTimingInfo load_timing_info2; |
| 3369 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3370 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3371 | |
| 3372 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3373 | |
| 3374 | trans2.reset(); |
| 3375 | session->CloseAllConnections(); |
| 3376 | } |
| 3377 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3378 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3379 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3380 | HttpRequestInfo request; |
| 3381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3382 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3383 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3384 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3385 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3386 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3387 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3388 | session_deps_.net_log = log.bound().net_log(); |
| 3389 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3390 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3391 | // Since we have proxy, should use full url |
| 3392 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3393 | MockWrite( |
| 3394 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3395 | "Host: www.example.org\r\n" |
| 3396 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3397 | }; |
| 3398 | |
| 3399 | MockRead data_reads1[] = { |
| 3400 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3402 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3403 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3404 | }; |
| 3405 | |
| 3406 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3407 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3408 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3409 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3411 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3412 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3413 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3414 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3415 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3417 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3418 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3419 | |
| 3420 | rv = callback1.WaitForResult(); |
| 3421 | EXPECT_EQ(OK, rv); |
| 3422 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3423 | LoadTimingInfo load_timing_info; |
| 3424 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3425 | TestLoadTimingNotReused(load_timing_info, |
| 3426 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3427 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3428 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3429 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3430 | |
| 3431 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3432 | EXPECT_EQ(200, response->headers->response_code()); |
| 3433 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3434 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3435 | |
| 3436 | // The password prompt info should not be set. |
| 3437 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3438 | } |
| 3439 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3440 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3441 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3442 | HttpRequestInfo request; |
| 3443 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3444 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3445 | request.load_flags = 0; |
| 3446 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3447 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3448 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3449 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3450 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3451 | session_deps_.net_log = log.bound().net_log(); |
| 3452 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3453 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3454 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3455 | scoped_ptr<SpdyFrame> req( |
| 3456 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3457 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3458 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3459 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3460 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3461 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3462 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3463 | }; |
| 3464 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3465 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3466 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3467 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3468 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3469 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3470 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3473 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3474 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3475 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3478 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3479 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3480 | |
| 3481 | rv = callback1.WaitForResult(); |
| 3482 | EXPECT_EQ(OK, rv); |
| 3483 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3484 | LoadTimingInfo load_timing_info; |
| 3485 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3486 | TestLoadTimingNotReused(load_timing_info, |
| 3487 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3488 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3490 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3491 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3492 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3493 | |
| 3494 | std::string response_data; |
| 3495 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3496 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3497 | } |
| 3498 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3499 | // Verifies that a session which races and wins against the owning transaction |
| 3500 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3501 | // Regression test for crbug.com/334413. |
| 3502 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3503 | HttpRequestInfo request; |
| 3504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3505 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3506 | request.load_flags = 0; |
| 3507 | |
| 3508 | // Configure SPDY proxy server "proxy:70". |
| 3509 | session_deps_.proxy_service.reset( |
| 3510 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3511 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3512 | session_deps_.net_log = log.bound().net_log(); |
| 3513 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3514 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3515 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3516 | scoped_ptr<SpdyFrame> req( |
| 3517 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3518 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3519 | |
| 3520 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3521 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3522 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3523 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3524 | }; |
| 3525 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3526 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3527 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3528 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3529 | |
| 3530 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3531 | ssl.SetNextProto(GetParam()); |
| 3532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3533 | |
| 3534 | TestCompletionCallback callback1; |
| 3535 | |
| 3536 | scoped_ptr<HttpTransaction> trans( |
| 3537 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3538 | |
| 3539 | // Stall the hostname resolution begun by the transaction. |
| 3540 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3541 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3542 | |
| 3543 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3544 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3545 | |
| 3546 | // Race a session to the proxy, which completes first. |
| 3547 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3548 | SpdySessionKey key( |
| 3549 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3550 | base::WeakPtr<SpdySession> spdy_session = |
| 3551 | CreateSecureSpdySession(session, key, log.bound()); |
| 3552 | |
| 3553 | // Unstall the resolution begun by the transaction. |
| 3554 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3555 | session_deps_.host_resolver->ResolveAllPending(); |
| 3556 | |
| 3557 | EXPECT_FALSE(callback1.have_result()); |
| 3558 | rv = callback1.WaitForResult(); |
| 3559 | EXPECT_EQ(OK, rv); |
| 3560 | |
| 3561 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3562 | ASSERT_TRUE(response != NULL); |
| 3563 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3564 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3565 | |
| 3566 | std::string response_data; |
| 3567 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3568 | EXPECT_EQ(kUploadData, response_data); |
| 3569 | } |
| 3570 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3571 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3572 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3573 | HttpRequestInfo request; |
| 3574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3575 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3576 | request.load_flags = 0; |
| 3577 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3578 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3579 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3580 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3581 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3582 | session_deps_.net_log = log.bound().net_log(); |
| 3583 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3584 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3585 | // The first request will be a bare GET, the second request will be a |
| 3586 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3587 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3588 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3589 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3590 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3591 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3592 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3593 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3594 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3595 | false, |
| 3596 | 3, |
| 3597 | LOWEST, |
| 3598 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3599 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3600 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3601 | }; |
| 3602 | |
| 3603 | // The first response is a 407 proxy authentication challenge, and the second |
| 3604 | // response will be a 200 response since the second request includes a valid |
| 3605 | // Authorization header. |
| 3606 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3607 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3608 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3609 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3610 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3611 | "407 Proxy Authentication Required", |
| 3612 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3613 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3614 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3615 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3616 | scoped_ptr<SpdyFrame> resp_data( |
| 3617 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3618 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3619 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3620 | CreateMockRead(*resp_authentication, 1), |
| 3621 | CreateMockRead(*body_authentication, 2), |
| 3622 | CreateMockRead(*resp_data, 4), |
| 3623 | CreateMockRead(*body_data, 5), |
| 3624 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3625 | }; |
| 3626 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3627 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3628 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3630 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3631 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3632 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3635 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3636 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3637 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3638 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3640 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3642 | |
| 3643 | rv = callback1.WaitForResult(); |
| 3644 | EXPECT_EQ(OK, rv); |
| 3645 | |
| 3646 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3647 | |
| 3648 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3649 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3650 | EXPECT_EQ(407, response->headers->response_code()); |
| 3651 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3652 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3654 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3656 | rv = trans->RestartWithAuth( |
| 3657 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3659 | |
| 3660 | rv = callback2.WaitForResult(); |
| 3661 | EXPECT_EQ(OK, rv); |
| 3662 | |
| 3663 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3664 | |
| 3665 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3666 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3667 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3668 | // The password prompt info should not be set. |
| 3669 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3670 | } |
| 3671 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3672 | // 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] | 3673 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3674 | HttpRequestInfo request; |
| 3675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3676 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3677 | request.load_flags = 0; |
| 3678 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3679 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3680 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3681 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3682 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3683 | session_deps_.net_log = log.bound().net_log(); |
| 3684 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3685 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3686 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3688 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3689 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3690 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3691 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3692 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3693 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3694 | const char get[] = |
| 3695 | "GET / HTTP/1.1\r\n" |
| 3696 | "Host: www.example.org\r\n" |
| 3697 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3698 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3699 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3700 | scoped_ptr<SpdyFrame> conn_resp( |
| 3701 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3702 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3703 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3704 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3705 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3706 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3707 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3708 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3709 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3710 | |
| 3711 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3712 | CreateMockWrite(*connect, 0), |
| 3713 | CreateMockWrite(*wrapped_get, 2), |
| 3714 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3715 | }; |
| 3716 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3717 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3718 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3719 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3720 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3721 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3722 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3723 | }; |
| 3724 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3725 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3726 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3727 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3728 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3729 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3730 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3732 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3735 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3737 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3738 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3739 | |
| 3740 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3741 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3742 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3743 | LoadTimingInfo load_timing_info; |
| 3744 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3745 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3746 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3748 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3749 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3750 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3751 | |
| 3752 | std::string response_data; |
| 3753 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3754 | EXPECT_EQ("1234567890", response_data); |
| 3755 | } |
| 3756 | |
| 3757 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3758 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3759 | HttpRequestInfo request; |
| 3760 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3761 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3762 | request.load_flags = 0; |
| 3763 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3764 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3765 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3766 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3767 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3768 | session_deps_.net_log = log.bound().net_log(); |
| 3769 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3770 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3771 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3772 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3773 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3774 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3775 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3776 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3777 | // fetch https://www.example.org/ via SPDY |
| 3778 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3779 | scoped_ptr<SpdyFrame> get( |
| 3780 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3781 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3782 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3783 | scoped_ptr<SpdyFrame> conn_resp( |
| 3784 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3785 | scoped_ptr<SpdyFrame> get_resp( |
| 3786 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3787 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3788 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3789 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3790 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3791 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3792 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3793 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3794 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3795 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3796 | |
| 3797 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3798 | CreateMockWrite(*connect, 0), |
| 3799 | CreateMockWrite(*wrapped_get, 2), |
| 3800 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3801 | CreateMockWrite(*window_update_body, 7), |
| 3802 | }; |
| 3803 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3804 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3805 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3806 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3807 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3808 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3809 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3810 | }; |
| 3811 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3812 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3813 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3814 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3815 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3816 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3817 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3819 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3820 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3821 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3823 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3825 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3826 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3827 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3828 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3829 | base::MessageLoop::current()->RunUntilIdle(); |
| 3830 | // Now allow the read of the response to complete. |
| 3831 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3832 | rv = callback1.WaitForResult(); |
| 3833 | EXPECT_EQ(OK, rv); |
| 3834 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3835 | LoadTimingInfo load_timing_info; |
| 3836 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3837 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3838 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3839 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3840 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3841 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3842 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3843 | |
| 3844 | std::string response_data; |
| 3845 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3846 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3850 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3851 | HttpRequestInfo request; |
| 3852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3853 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3854 | request.load_flags = 0; |
| 3855 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3856 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3857 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3858 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3859 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3860 | session_deps_.net_log = log.bound().net_log(); |
| 3861 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3862 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3865 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3866 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3867 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3868 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3869 | scoped_ptr<SpdyFrame> get( |
| 3870 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3871 | |
| 3872 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3873 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3874 | }; |
| 3875 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3876 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3877 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3878 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3879 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3880 | }; |
| 3881 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3882 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3883 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3884 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3885 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3886 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3887 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3888 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3889 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3890 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3893 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3894 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3895 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3897 | |
| 3898 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3899 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3900 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3901 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3902 | } |
| 3903 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3904 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3905 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3906 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3907 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3908 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3909 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3910 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3911 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3912 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3913 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3914 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3915 | |
| 3916 | HttpRequestInfo request1; |
| 3917 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3918 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3919 | request1.load_flags = 0; |
| 3920 | |
| 3921 | HttpRequestInfo request2; |
| 3922 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3923 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3924 | request2.load_flags = 0; |
| 3925 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3926 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3927 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3928 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3929 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3930 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3931 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3932 | // Fetch https://www.example.org/ via HTTP. |
| 3933 | const char get1[] = |
| 3934 | "GET / HTTP/1.1\r\n" |
| 3935 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3936 | "Connection: keep-alive\r\n\r\n"; |
| 3937 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3938 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3939 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3940 | "Content-Length: 1\r\n\r\n"; |
| 3941 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3942 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3943 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3944 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3945 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3946 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3947 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3948 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3949 | SpdyHeaderBlock connect2_block; |
| 3950 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 3951 | if (GetParam() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3952 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 3953 | } else { |
| 3954 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
| 3955 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
| 3956 | } |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3957 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3958 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3959 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3960 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3961 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3962 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3963 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3964 | // Fetch https://mail.example.org/ via HTTP. |
| 3965 | const char get2[] = |
| 3966 | "GET / HTTP/1.1\r\n" |
| 3967 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3968 | "Connection: keep-alive\r\n\r\n"; |
| 3969 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3970 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3971 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3972 | "Content-Length: 2\r\n\r\n"; |
| 3973 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3974 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3975 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3976 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3977 | |
| 3978 | MockWrite spdy_writes[] = { |
| 3979 | CreateMockWrite(*connect1, 0), |
| 3980 | CreateMockWrite(*wrapped_get1, 2), |
| 3981 | CreateMockWrite(*connect2, 5), |
| 3982 | CreateMockWrite(*wrapped_get2, 7), |
| 3983 | }; |
| 3984 | |
| 3985 | MockRead spdy_reads[] = { |
| 3986 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3987 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3988 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3989 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3990 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3991 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3992 | MockRead(ASYNC, 0, 10), |
| 3993 | }; |
| 3994 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3995 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3996 | arraysize(spdy_writes)); |
| 3997 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3998 | |
| 3999 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4000 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4002 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4003 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4004 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4006 | |
| 4007 | TestCompletionCallback callback; |
| 4008 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4009 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4010 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4011 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4012 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4013 | |
| 4014 | LoadTimingInfo load_timing_info; |
| 4015 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4016 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4017 | |
| 4018 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4019 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4020 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4021 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4022 | |
| 4023 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4024 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4025 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4026 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4027 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4028 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4030 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4031 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4032 | |
| 4033 | LoadTimingInfo load_timing_info2; |
| 4034 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4035 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4036 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4037 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4038 | |
| 4039 | // The requests should have different IDs, since they each are using their own |
| 4040 | // separate stream. |
| 4041 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4042 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4043 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4044 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4048 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4049 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4050 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4051 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4052 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4053 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4054 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4055 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4056 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4057 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4058 | |
| 4059 | HttpRequestInfo request1; |
| 4060 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4061 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4062 | request1.load_flags = 0; |
| 4063 | |
| 4064 | HttpRequestInfo request2; |
| 4065 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4066 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4067 | request2.load_flags = 0; |
| 4068 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4069 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4070 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4071 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4072 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4073 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4074 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4075 | // Fetch https://www.example.org/ via HTTP. |
| 4076 | const char get1[] = |
| 4077 | "GET / HTTP/1.1\r\n" |
| 4078 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4079 | "Connection: keep-alive\r\n\r\n"; |
| 4080 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4081 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4082 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4083 | "Content-Length: 1\r\n\r\n"; |
| 4084 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4085 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4086 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4087 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4088 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4089 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4090 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4091 | // Fetch https://www.example.org/2 via HTTP. |
| 4092 | const char get2[] = |
| 4093 | "GET /2 HTTP/1.1\r\n" |
| 4094 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4095 | "Connection: keep-alive\r\n\r\n"; |
| 4096 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4097 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4098 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4099 | "Content-Length: 2\r\n\r\n"; |
| 4100 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4101 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4102 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4103 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4104 | |
| 4105 | MockWrite spdy_writes[] = { |
| 4106 | CreateMockWrite(*connect1, 0), |
| 4107 | CreateMockWrite(*wrapped_get1, 2), |
| 4108 | CreateMockWrite(*wrapped_get2, 5), |
| 4109 | }; |
| 4110 | |
| 4111 | MockRead spdy_reads[] = { |
| 4112 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4113 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4114 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4115 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4116 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4117 | MockRead(ASYNC, 0, 8), |
| 4118 | }; |
| 4119 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4120 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4121 | arraysize(spdy_writes)); |
| 4122 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4123 | |
| 4124 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4125 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4127 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4128 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4129 | |
| 4130 | TestCompletionCallback callback; |
| 4131 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4132 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4134 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4136 | |
| 4137 | rv = callback.WaitForResult(); |
| 4138 | EXPECT_EQ(OK, rv); |
| 4139 | |
| 4140 | LoadTimingInfo load_timing_info; |
| 4141 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4142 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4143 | |
| 4144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4145 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4146 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4147 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4148 | |
| 4149 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4150 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4151 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4152 | trans.reset(); |
| 4153 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4154 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4156 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4157 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4158 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4159 | rv = callback.WaitForResult(); |
| 4160 | EXPECT_EQ(OK, rv); |
| 4161 | |
| 4162 | LoadTimingInfo load_timing_info2; |
| 4163 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4164 | TestLoadTimingReused(load_timing_info2); |
| 4165 | |
| 4166 | // The requests should have the same ID. |
| 4167 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4168 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4169 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4173 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4174 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4175 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4176 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4177 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4178 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4179 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4180 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4181 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4182 | |
| 4183 | HttpRequestInfo request1; |
| 4184 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4185 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4186 | request1.load_flags = 0; |
| 4187 | |
| 4188 | HttpRequestInfo request2; |
| 4189 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4190 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4191 | request2.load_flags = 0; |
| 4192 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4193 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4194 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4195 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4196 | scoped_ptr<SpdyFrame> get1( |
| 4197 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4198 | scoped_ptr<SpdyFrame> get_resp1( |
| 4199 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4200 | scoped_ptr<SpdyFrame> body1( |
| 4201 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4202 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4203 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4204 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4205 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4206 | scoped_ptr<SpdyFrame> get2( |
| 4207 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4208 | scoped_ptr<SpdyFrame> get_resp2( |
| 4209 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4210 | scoped_ptr<SpdyFrame> body2( |
| 4211 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4212 | |
| 4213 | MockWrite spdy_writes[] = { |
| 4214 | CreateMockWrite(*get1, 0), |
| 4215 | CreateMockWrite(*get2, 3), |
| 4216 | }; |
| 4217 | |
| 4218 | MockRead spdy_reads[] = { |
| 4219 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4220 | CreateMockRead(*body1, 2, ASYNC), |
| 4221 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4222 | CreateMockRead(*body2, 5, ASYNC), |
| 4223 | MockRead(ASYNC, 0, 6), |
| 4224 | }; |
| 4225 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4226 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4227 | arraysize(spdy_writes)); |
| 4228 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4229 | |
| 4230 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4231 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4233 | |
| 4234 | TestCompletionCallback callback; |
| 4235 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4236 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4238 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4239 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4240 | |
| 4241 | LoadTimingInfo load_timing_info; |
| 4242 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4243 | TestLoadTimingNotReused(load_timing_info, |
| 4244 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4245 | |
| 4246 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4247 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4248 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4249 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4250 | |
| 4251 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4252 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4253 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4254 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4255 | // Delete the first request, so the second one can reuse the socket. |
| 4256 | trans.reset(); |
| 4257 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4258 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4260 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4261 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4262 | |
| 4263 | LoadTimingInfo load_timing_info2; |
| 4264 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4265 | TestLoadTimingReused(load_timing_info2); |
| 4266 | |
| 4267 | // The requests should have the same ID. |
| 4268 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4269 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4270 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4271 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4272 | } |
| 4273 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4274 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4275 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4276 | HttpRequestInfo request; |
| 4277 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4278 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4279 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4280 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4281 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4282 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4283 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4284 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4285 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4286 | session_deps_.net_log = log.bound().net_log(); |
| 4287 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4288 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4289 | // Since we have proxy, should use full url |
| 4290 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4291 | MockWrite( |
| 4292 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4293 | "Host: www.example.org\r\n" |
| 4294 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4295 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4296 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4297 | // be issuing -- the final header line contains the credentials. |
| 4298 | MockWrite( |
| 4299 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4300 | "Host: www.example.org\r\n" |
| 4301 | "Proxy-Connection: keep-alive\r\n" |
| 4302 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4303 | }; |
| 4304 | |
| 4305 | // The proxy responds to the GET with a 407, using a persistent |
| 4306 | // connection. |
| 4307 | MockRead data_reads1[] = { |
| 4308 | // No credentials. |
| 4309 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4310 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4311 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4312 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4313 | |
| 4314 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4315 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4316 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4317 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4318 | }; |
| 4319 | |
| 4320 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4321 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4323 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4326 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4327 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4328 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4331 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4332 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4333 | |
| 4334 | rv = callback1.WaitForResult(); |
| 4335 | EXPECT_EQ(OK, rv); |
| 4336 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4337 | LoadTimingInfo load_timing_info; |
| 4338 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4339 | TestLoadTimingNotReused(load_timing_info, |
| 4340 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4341 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4342 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4343 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4344 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4345 | EXPECT_EQ(407, response->headers->response_code()); |
| 4346 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4347 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4349 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4351 | rv = trans->RestartWithAuth( |
| 4352 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4354 | |
| 4355 | rv = callback2.WaitForResult(); |
| 4356 | EXPECT_EQ(OK, rv); |
| 4357 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4358 | load_timing_info = LoadTimingInfo(); |
| 4359 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4360 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4361 | TestLoadTimingReused(load_timing_info); |
| 4362 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4363 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4364 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4365 | |
| 4366 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4367 | EXPECT_EQ(200, response->headers->response_code()); |
| 4368 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4369 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4370 | |
| 4371 | // The password prompt info should not be set. |
| 4372 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4373 | } |
| 4374 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4375 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4376 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4377 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4378 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4379 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4380 | request.load_flags = 0; |
| 4381 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4382 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4383 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4384 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4385 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4386 | // Since we have proxy, should try to establish tunnel. |
| 4387 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4388 | MockWrite( |
| 4389 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4390 | "Host: www.example.org\r\n" |
| 4391 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4392 | }; |
| 4393 | |
| 4394 | MockRead data_reads[] = { |
| 4395 | status, |
| 4396 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4397 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4398 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4399 | }; |
| 4400 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4402 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4405 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4406 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4407 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4408 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4410 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4411 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4412 | |
| 4413 | rv = callback.WaitForResult(); |
| 4414 | EXPECT_EQ(expected_status, rv); |
| 4415 | } |
| 4416 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4417 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4418 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4419 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4420 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4421 | } |
| 4422 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4423 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4424 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4425 | } |
| 4426 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4427 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4428 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4429 | } |
| 4430 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4431 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4432 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4433 | } |
| 4434 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4435 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4436 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4437 | } |
| 4438 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4439 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4440 | ConnectStatusHelper( |
| 4441 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4442 | } |
| 4443 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4444 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4445 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4446 | } |
| 4447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4448 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4449 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4450 | } |
| 4451 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4452 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4453 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4454 | } |
| 4455 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4456 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4457 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4458 | } |
| 4459 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4460 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4461 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4462 | } |
| 4463 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4464 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4465 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4466 | } |
| 4467 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4468 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4469 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4470 | } |
| 4471 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4472 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4473 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4474 | } |
| 4475 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4476 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4477 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4478 | } |
| 4479 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4480 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4481 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4482 | } |
| 4483 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4484 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4485 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4486 | } |
| 4487 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4488 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4489 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4490 | } |
| 4491 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4492 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4493 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4494 | } |
| 4495 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4496 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4497 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4498 | } |
| 4499 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4500 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4501 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4502 | } |
| 4503 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4504 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4505 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4506 | } |
| 4507 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4508 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4509 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4510 | } |
| 4511 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4512 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4513 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4514 | } |
| 4515 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4516 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4517 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4518 | } |
| 4519 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4520 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4521 | ConnectStatusHelperWithExpectedStatus( |
| 4522 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4523 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4524 | } |
| 4525 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4526 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4527 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4528 | } |
| 4529 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4530 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4531 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4532 | } |
| 4533 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4534 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4535 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4536 | } |
| 4537 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4538 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4539 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4540 | } |
| 4541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4542 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4543 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4544 | } |
| 4545 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4546 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4547 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4548 | } |
| 4549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4550 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4551 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4552 | } |
| 4553 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4554 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4555 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4556 | } |
| 4557 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4558 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4559 | ConnectStatusHelper( |
| 4560 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4561 | } |
| 4562 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4563 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4564 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4565 | } |
| 4566 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4567 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4568 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4569 | } |
| 4570 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4571 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4572 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4573 | } |
| 4574 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4575 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4576 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4577 | } |
| 4578 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4579 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4580 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4581 | } |
| 4582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4583 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4584 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4585 | } |
| 4586 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4587 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4588 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4589 | } |
| 4590 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4591 | // Test the flow when both the proxy server AND origin server require |
| 4592 | // authentication. Again, this uses basic auth for both since that is |
| 4593 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4594 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4595 | HttpRequestInfo request; |
| 4596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4597 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4598 | request.load_flags = 0; |
| 4599 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4600 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4601 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4602 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4603 | |
| 4604 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4606 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4607 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4608 | MockWrite( |
| 4609 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4610 | "Host: www.example.org\r\n" |
| 4611 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4612 | }; |
| 4613 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4614 | MockRead data_reads1[] = { |
| 4615 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4616 | // Give a couple authenticate options (only the middle one is actually |
| 4617 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4618 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4619 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4620 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4621 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4622 | // Large content-length -- won't matter, as connection will be reset. |
| 4623 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4624 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4625 | }; |
| 4626 | |
| 4627 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4628 | // request we should be issuing -- the final header line contains the |
| 4629 | // proxy's credentials. |
| 4630 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4631 | MockWrite( |
| 4632 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4633 | "Host: www.example.org\r\n" |
| 4634 | "Proxy-Connection: keep-alive\r\n" |
| 4635 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4636 | }; |
| 4637 | |
| 4638 | // Now the proxy server lets the request pass through to origin server. |
| 4639 | // The origin server responds with a 401. |
| 4640 | MockRead data_reads2[] = { |
| 4641 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4642 | // Note: We are using the same realm-name as the proxy server. This is |
| 4643 | // completely valid, as realms are unique across hosts. |
| 4644 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4645 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4646 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4647 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4648 | }; |
| 4649 | |
| 4650 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4651 | // the credentials for both the proxy and origin server. |
| 4652 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4653 | MockWrite( |
| 4654 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4655 | "Host: www.example.org\r\n" |
| 4656 | "Proxy-Connection: keep-alive\r\n" |
| 4657 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4658 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4659 | }; |
| 4660 | |
| 4661 | // Lastly we get the desired content. |
| 4662 | MockRead data_reads3[] = { |
| 4663 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4665 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4667 | }; |
| 4668 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4669 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4670 | data_writes1, arraysize(data_writes1)); |
| 4671 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4672 | data_writes2, arraysize(data_writes2)); |
| 4673 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4674 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4675 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4676 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4677 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4679 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4681 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4682 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4683 | |
| 4684 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4685 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4686 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4687 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4688 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4689 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4691 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4693 | rv = trans->RestartWithAuth( |
| 4694 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4696 | |
| 4697 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4698 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4699 | |
| 4700 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4701 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4702 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4704 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4706 | rv = trans->RestartWithAuth( |
| 4707 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4708 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4709 | |
| 4710 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4711 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4712 | |
| 4713 | response = trans->GetResponseInfo(); |
| 4714 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4715 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4716 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4717 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4718 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4719 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4720 | // authorization headers. |
| 4721 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4722 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4723 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4724 | // bytes in the debugger. |
| 4725 | |
| 4726 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4727 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4728 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4729 | request.method = "GET"; |
| 4730 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4731 | |
| 4732 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4733 | // to other auth schemes. |
| 4734 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4735 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4736 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4737 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4738 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4739 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4740 | MockWrite data_writes1[] = { |
| 4741 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4742 | "Host: 172.22.68.17\r\n" |
| 4743 | "Connection: keep-alive\r\n\r\n"), |
| 4744 | }; |
| 4745 | |
| 4746 | MockRead data_reads1[] = { |
| 4747 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4748 | // Negotiate and NTLM are often requested together. However, we only want |
| 4749 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4750 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4751 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4752 | MockRead("Connection: close\r\n"), |
| 4753 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4754 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4755 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4756 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4757 | }; |
| 4758 | |
| 4759 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4760 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4761 | // request we should be issuing -- the final header line contains a Type |
| 4762 | // 1 message. |
| 4763 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4764 | "Host: 172.22.68.17\r\n" |
| 4765 | "Connection: keep-alive\r\n" |
| 4766 | "Authorization: NTLM " |
| 4767 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4768 | |
| 4769 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4770 | // (the credentials for the origin server). The second request continues |
| 4771 | // on the same connection. |
| 4772 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4773 | "Host: 172.22.68.17\r\n" |
| 4774 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4775 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4776 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4777 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4778 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4779 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4780 | }; |
| 4781 | |
| 4782 | MockRead data_reads2[] = { |
| 4783 | // The origin server responds with a Type 2 message. |
| 4784 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4785 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4786 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4787 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4788 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4789 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4790 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4791 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4792 | "BtAAAAAAA=\r\n"), |
| 4793 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4794 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4795 | MockRead("You are not authorized to view this page\r\n"), |
| 4796 | |
| 4797 | // Lastly we get the desired content. |
| 4798 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4799 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4800 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4801 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4802 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4803 | }; |
| 4804 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4805 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4806 | data_writes1, arraysize(data_writes1)); |
| 4807 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4808 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4810 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4812 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4813 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4814 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4815 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4817 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4819 | |
| 4820 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4821 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4822 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4823 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4824 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4826 | ASSERT_FALSE(response == NULL); |
| 4827 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4829 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4830 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4831 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4832 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4834 | |
| 4835 | rv = callback2.WaitForResult(); |
| 4836 | EXPECT_EQ(OK, rv); |
| 4837 | |
| 4838 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4839 | |
| 4840 | response = trans->GetResponseInfo(); |
| 4841 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4842 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4844 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4846 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4847 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4848 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4849 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4850 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4851 | |
| 4852 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4853 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4854 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4855 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4856 | } |
| 4857 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4858 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4859 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4860 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4861 | request.method = "GET"; |
| 4862 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4863 | request.load_flags = 0; |
| 4864 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4865 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4866 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4867 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4868 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4869 | MockWrite data_writes1[] = { |
| 4870 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4871 | "Host: 172.22.68.17\r\n" |
| 4872 | "Connection: keep-alive\r\n\r\n"), |
| 4873 | }; |
| 4874 | |
| 4875 | MockRead data_reads1[] = { |
| 4876 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4877 | // Negotiate and NTLM are often requested together. However, we only want |
| 4878 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4879 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4880 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4881 | MockRead("Connection: close\r\n"), |
| 4882 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4883 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4884 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4885 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4886 | }; |
| 4887 | |
| 4888 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4889 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4890 | // request we should be issuing -- the final header line contains a Type |
| 4891 | // 1 message. |
| 4892 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4893 | "Host: 172.22.68.17\r\n" |
| 4894 | "Connection: keep-alive\r\n" |
| 4895 | "Authorization: NTLM " |
| 4896 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4897 | |
| 4898 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4899 | // (the credentials for the origin server). The second request continues |
| 4900 | // on the same connection. |
| 4901 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4902 | "Host: 172.22.68.17\r\n" |
| 4903 | "Connection: keep-alive\r\n" |
| 4904 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4905 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4906 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4907 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4908 | "4Ww7b7E=\r\n\r\n"), |
| 4909 | }; |
| 4910 | |
| 4911 | MockRead data_reads2[] = { |
| 4912 | // The origin server responds with a Type 2 message. |
| 4913 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4914 | MockRead("WWW-Authenticate: NTLM " |
| 4915 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4916 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4917 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4918 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4919 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4920 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4921 | "BtAAAAAAA=\r\n"), |
| 4922 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4923 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4924 | MockRead("You are not authorized to view this page\r\n"), |
| 4925 | |
| 4926 | // Wrong password. |
| 4927 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4928 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4929 | MockRead("Connection: close\r\n"), |
| 4930 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4931 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4932 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4933 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4934 | }; |
| 4935 | |
| 4936 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4937 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4938 | // request we should be issuing -- the final header line contains a Type |
| 4939 | // 1 message. |
| 4940 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4941 | "Host: 172.22.68.17\r\n" |
| 4942 | "Connection: keep-alive\r\n" |
| 4943 | "Authorization: NTLM " |
| 4944 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4945 | |
| 4946 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4947 | // (the credentials for the origin server). The second request continues |
| 4948 | // on the same connection. |
| 4949 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4950 | "Host: 172.22.68.17\r\n" |
| 4951 | "Connection: keep-alive\r\n" |
| 4952 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4953 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4954 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4955 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4956 | "+4MUm7c=\r\n\r\n"), |
| 4957 | }; |
| 4958 | |
| 4959 | MockRead data_reads3[] = { |
| 4960 | // The origin server responds with a Type 2 message. |
| 4961 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4962 | MockRead("WWW-Authenticate: NTLM " |
| 4963 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4964 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4965 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4966 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4967 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4968 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4969 | "BtAAAAAAA=\r\n"), |
| 4970 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4971 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4972 | MockRead("You are not authorized to view this page\r\n"), |
| 4973 | |
| 4974 | // Lastly we get the desired content. |
| 4975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4976 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4977 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4978 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4980 | }; |
| 4981 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4982 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4983 | data_writes1, arraysize(data_writes1)); |
| 4984 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4985 | data_writes2, arraysize(data_writes2)); |
| 4986 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4987 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4990 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4992 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4993 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4997 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4998 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4999 | |
| 5000 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5001 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5002 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5003 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5004 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5005 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5006 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5007 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5008 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5009 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5010 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5011 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5012 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5013 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5015 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5016 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5017 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5018 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5019 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5020 | TestCompletionCallback callback3; |
| 5021 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5022 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5023 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5024 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5025 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5026 | |
| 5027 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5028 | ASSERT_FALSE(response == NULL); |
| 5029 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5031 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5032 | |
| 5033 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5034 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5035 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5036 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5037 | |
| 5038 | rv = callback4.WaitForResult(); |
| 5039 | EXPECT_EQ(OK, rv); |
| 5040 | |
| 5041 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5043 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5044 | |
| 5045 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5046 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5048 | |
| 5049 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5050 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5051 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5052 | response = trans->GetResponseInfo(); |
| 5053 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5054 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5055 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5056 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5057 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5058 | // Test reading a server response which has only headers, and no body. |
| 5059 | // After some maximum number of bytes is consumed, the transaction should |
| 5060 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5061 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5062 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5063 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5064 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5065 | request.load_flags = 0; |
| 5066 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5067 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5068 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5069 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5070 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5071 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5072 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5073 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5074 | |
| 5075 | MockRead data_reads[] = { |
| 5076 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5077 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5078 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5079 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5080 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5081 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5082 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5084 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5086 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5087 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5088 | |
| 5089 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5090 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5091 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5092 | |
| 5093 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5094 | // establish tunnel. |
| 5095 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5096 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5097 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5098 | HttpRequestInfo request; |
| 5099 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5100 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5101 | request.load_flags = 0; |
| 5102 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5103 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5104 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5105 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5106 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5107 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5108 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5109 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5110 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5111 | // Since we have proxy, should try to establish tunnel. |
| 5112 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5113 | MockWrite( |
| 5114 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5115 | "Host: www.example.org\r\n" |
| 5116 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5117 | }; |
| 5118 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5119 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5120 | // connection. Usually a proxy would return 501 (not implemented), |
| 5121 | // or 200 (tunnel established). |
| 5122 | MockRead data_reads1[] = { |
| 5123 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5124 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5125 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5126 | }; |
| 5127 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5128 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5129 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5130 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5132 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5134 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5136 | |
| 5137 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5138 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5139 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5140 | // Empty the current queue. This is necessary because idle sockets are |
| 5141 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5142 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5143 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5144 | // We now check to make sure the TCPClientSocket was not added back to |
| 5145 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5146 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5147 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5148 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5149 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5150 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5151 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5152 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5153 | // 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] | 5154 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5155 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5157 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5158 | request.load_flags = 0; |
| 5159 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5160 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5161 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5162 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5164 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5165 | MockRead data_reads[] = { |
| 5166 | // A part of the response body is received with the response headers. |
| 5167 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5168 | // The rest of the response body is received in two parts. |
| 5169 | MockRead("lo"), |
| 5170 | MockRead(" world"), |
| 5171 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5172 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5173 | }; |
| 5174 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5178 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5180 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5182 | |
| 5183 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5184 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5185 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5187 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5188 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5189 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5190 | std::string status_line = response->headers->GetStatusLine(); |
| 5191 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5192 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5193 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5194 | |
| 5195 | std::string response_data; |
| 5196 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5197 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5198 | EXPECT_EQ("hello world", response_data); |
| 5199 | |
| 5200 | // Empty the current queue. This is necessary because idle sockets are |
| 5201 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5202 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5203 | |
| 5204 | // 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] | 5205 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5206 | } |
| 5207 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5208 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5209 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5210 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5211 | HttpRequestInfo request; |
| 5212 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5213 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5214 | request.load_flags = 0; |
| 5215 | |
| 5216 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5217 | MockWrite( |
| 5218 | "GET / HTTP/1.1\r\n" |
| 5219 | "Host: www.example.org\r\n" |
| 5220 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5221 | }; |
| 5222 | |
| 5223 | MockRead data_reads[] = { |
| 5224 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5225 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5226 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5227 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5228 | }; |
| 5229 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5230 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5232 | |
| 5233 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5234 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5235 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5237 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5238 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5239 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5240 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5243 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5244 | |
| 5245 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5246 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5247 | |
| 5248 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5249 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5250 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5251 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5252 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5253 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5254 | |
| 5255 | std::string response_data; |
| 5256 | rv = ReadTransaction(trans.get(), &response_data); |
| 5257 | EXPECT_EQ(OK, rv); |
| 5258 | EXPECT_EQ("hello world", response_data); |
| 5259 | |
| 5260 | // Empty the current queue. This is necessary because idle sockets are |
| 5261 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5262 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5263 | |
| 5264 | // 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] | 5265 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5269 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5270 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5271 | HttpRequestInfo request; |
| 5272 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5273 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5274 | request.load_flags = 0; |
| 5275 | |
| 5276 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5277 | MockWrite( |
| 5278 | "GET / HTTP/1.1\r\n" |
| 5279 | "Host: www.example.org\r\n" |
| 5280 | "Connection: keep-alive\r\n\r\n"), |
| 5281 | MockWrite( |
| 5282 | "GET / HTTP/1.1\r\n" |
| 5283 | "Host: www.example.org\r\n" |
| 5284 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5285 | }; |
| 5286 | |
| 5287 | MockRead data_reads[] = { |
| 5288 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5289 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5290 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5291 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5292 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5293 | }; |
| 5294 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5295 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5296 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5299 | |
| 5300 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5301 | data_writes, arraysize(data_writes)); |
| 5302 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5303 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5304 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5305 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5307 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5308 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5310 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5313 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5314 | |
| 5315 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5316 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5317 | |
| 5318 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5319 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5320 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5321 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5322 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5323 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5324 | |
| 5325 | std::string response_data; |
| 5326 | rv = ReadTransaction(trans.get(), &response_data); |
| 5327 | EXPECT_EQ(OK, rv); |
| 5328 | EXPECT_EQ("hello world", response_data); |
| 5329 | |
| 5330 | // Empty the current queue. This is necessary because idle sockets are |
| 5331 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5332 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5333 | |
| 5334 | // 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] | 5335 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5336 | |
| 5337 | // Now start the second transaction, which should reuse the previous socket. |
| 5338 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5339 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5341 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5342 | |
| 5343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5344 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5345 | |
| 5346 | response = trans->GetResponseInfo(); |
| 5347 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5348 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5349 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5350 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5351 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5352 | |
| 5353 | rv = ReadTransaction(trans.get(), &response_data); |
| 5354 | EXPECT_EQ(OK, rv); |
| 5355 | EXPECT_EQ("hello world", response_data); |
| 5356 | |
| 5357 | // Empty the current queue. This is necessary because idle sockets are |
| 5358 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5359 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5360 | |
| 5361 | // 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] | 5362 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5363 | } |
| 5364 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5365 | // Make sure that we recycle a socket after a zero-length response. |
| 5366 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5367 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5368 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5370 | request.url = GURL( |
| 5371 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5372 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5373 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5374 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5375 | request.load_flags = 0; |
| 5376 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5377 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5378 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5379 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5380 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5381 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5382 | MockRead data_reads[] = { |
| 5383 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5384 | "Content-Length: 0\r\n" |
| 5385 | "Content-Type: text/html\r\n\r\n"), |
| 5386 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5387 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5388 | }; |
| 5389 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5390 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5391 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5393 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5395 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5396 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5397 | |
| 5398 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5399 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5400 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5401 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5402 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5403 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5404 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5405 | std::string status_line = response->headers->GetStatusLine(); |
| 5406 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5407 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5408 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5409 | |
| 5410 | std::string response_data; |
| 5411 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5412 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5413 | EXPECT_EQ("", response_data); |
| 5414 | |
| 5415 | // Empty the current queue. This is necessary because idle sockets are |
| 5416 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5417 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5418 | |
| 5419 | // 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] | 5420 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5421 | } |
| 5422 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5423 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5424 | ScopedVector<UploadElementReader> element_readers; |
| 5425 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5426 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5427 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5428 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5429 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5430 | // after use. |
| 5431 | request[0].method = "GET"; |
| 5432 | request[0].url = GURL("http://www.google.com/"); |
| 5433 | request[0].load_flags = 0; |
| 5434 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5435 | // transaction 1. The first attempts fails when writing the POST data. |
| 5436 | // This causes the transaction to retry with a new socket. The second |
| 5437 | // attempt succeeds. |
| 5438 | request[1].method = "POST"; |
| 5439 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5440 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5441 | request[1].load_flags = 0; |
| 5442 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5443 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5444 | |
| 5445 | // The first socket is used for transaction 1 and the first attempt of |
| 5446 | // transaction 2. |
| 5447 | |
| 5448 | // The response of transaction 1. |
| 5449 | MockRead data_reads1[] = { |
| 5450 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5451 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5452 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5453 | }; |
| 5454 | // The mock write results of transaction 1 and the first attempt of |
| 5455 | // transaction 2. |
| 5456 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5457 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5458 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5459 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5460 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5461 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5462 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5463 | |
| 5464 | // The second socket is used for the second attempt of transaction 2. |
| 5465 | |
| 5466 | // The response of transaction 2. |
| 5467 | MockRead data_reads2[] = { |
| 5468 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5469 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5470 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5471 | }; |
| 5472 | // The mock write results of the second attempt of transaction 2. |
| 5473 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5474 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5475 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5476 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5477 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5478 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5479 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5480 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5481 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5482 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5483 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5484 | "hello world", "welcome" |
| 5485 | }; |
| 5486 | |
| 5487 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5488 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5491 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5493 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5494 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5495 | |
| 5496 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5497 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5498 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5499 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5500 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5501 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5502 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5503 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5504 | |
| 5505 | std::string response_data; |
| 5506 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5508 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5509 | } |
| 5510 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5511 | |
| 5512 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5513 | // 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] | 5514 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5515 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5516 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5518 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5519 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5520 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5521 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5522 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5523 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5524 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5525 | // The password contains an escaped character -- for this test to pass it |
| 5526 | // will need to be unescaped by HttpNetworkTransaction. |
| 5527 | EXPECT_EQ("b%40r", request.url.password()); |
| 5528 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5529 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5530 | MockWrite( |
| 5531 | "GET / HTTP/1.1\r\n" |
| 5532 | "Host: www.example.org\r\n" |
| 5533 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5534 | }; |
| 5535 | |
| 5536 | MockRead data_reads1[] = { |
| 5537 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5538 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5539 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5540 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5541 | }; |
| 5542 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5543 | // After the challenge above, the transaction will be restarted using the |
| 5544 | // identity from the url (foo, b@r) to answer the challenge. |
| 5545 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5546 | MockWrite( |
| 5547 | "GET / HTTP/1.1\r\n" |
| 5548 | "Host: www.example.org\r\n" |
| 5549 | "Connection: keep-alive\r\n" |
| 5550 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5551 | }; |
| 5552 | |
| 5553 | MockRead data_reads2[] = { |
| 5554 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5555 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5556 | MockRead(SYNCHRONOUS, OK), |
| 5557 | }; |
| 5558 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5559 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5560 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5561 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5562 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5563 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5564 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5566 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5567 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5568 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5569 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5570 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5571 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5572 | |
| 5573 | TestCompletionCallback callback2; |
| 5574 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5575 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5576 | rv = callback2.WaitForResult(); |
| 5577 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5578 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5579 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5580 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5581 | ASSERT_TRUE(response != NULL); |
| 5582 | |
| 5583 | // There is no challenge info, since the identity in URL worked. |
| 5584 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5585 | |
| 5586 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5587 | |
| 5588 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5589 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5593 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5594 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5595 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5596 | HttpRequestInfo request; |
| 5597 | request.method = "GET"; |
| 5598 | // Note: the URL has a username:password in it. The password "baz" is |
| 5599 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5600 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5601 | |
| 5602 | request.load_flags = LOAD_NORMAL; |
| 5603 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5604 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5605 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5607 | |
| 5608 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5609 | MockWrite( |
| 5610 | "GET / HTTP/1.1\r\n" |
| 5611 | "Host: www.example.org\r\n" |
| 5612 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5613 | }; |
| 5614 | |
| 5615 | MockRead data_reads1[] = { |
| 5616 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5617 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5618 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5619 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5620 | }; |
| 5621 | |
| 5622 | // After the challenge above, the transaction will be restarted using the |
| 5623 | // identity from the url (foo, baz) to answer the challenge. |
| 5624 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5625 | MockWrite( |
| 5626 | "GET / HTTP/1.1\r\n" |
| 5627 | "Host: www.example.org\r\n" |
| 5628 | "Connection: keep-alive\r\n" |
| 5629 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5630 | }; |
| 5631 | |
| 5632 | MockRead data_reads2[] = { |
| 5633 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5634 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5635 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5636 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5637 | }; |
| 5638 | |
| 5639 | // After the challenge above, the transaction will be restarted using the |
| 5640 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5641 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5642 | MockWrite( |
| 5643 | "GET / HTTP/1.1\r\n" |
| 5644 | "Host: www.example.org\r\n" |
| 5645 | "Connection: keep-alive\r\n" |
| 5646 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5647 | }; |
| 5648 | |
| 5649 | MockRead data_reads3[] = { |
| 5650 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5651 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5652 | MockRead(SYNCHRONOUS, OK), |
| 5653 | }; |
| 5654 | |
| 5655 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5656 | data_writes1, arraysize(data_writes1)); |
| 5657 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5658 | data_writes2, arraysize(data_writes2)); |
| 5659 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5660 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5661 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5662 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5663 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5664 | |
| 5665 | TestCompletionCallback callback1; |
| 5666 | |
| 5667 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5668 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5669 | |
| 5670 | rv = callback1.WaitForResult(); |
| 5671 | EXPECT_EQ(OK, rv); |
| 5672 | |
| 5673 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5674 | TestCompletionCallback callback2; |
| 5675 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5677 | rv = callback2.WaitForResult(); |
| 5678 | EXPECT_EQ(OK, rv); |
| 5679 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5680 | |
| 5681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5682 | ASSERT_TRUE(response != NULL); |
| 5683 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5684 | |
| 5685 | TestCompletionCallback callback3; |
| 5686 | rv = trans->RestartWithAuth( |
| 5687 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5688 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5689 | rv = callback3.WaitForResult(); |
| 5690 | EXPECT_EQ(OK, rv); |
| 5691 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5692 | |
| 5693 | response = trans->GetResponseInfo(); |
| 5694 | ASSERT_TRUE(response != NULL); |
| 5695 | |
| 5696 | // There is no challenge info, since the identity worked. |
| 5697 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5698 | |
| 5699 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5700 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5701 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5702 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5703 | } |
| 5704 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5705 | |
| 5706 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5707 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5708 | // from the URL should never be used. |
| 5709 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5710 | HttpRequestInfo request; |
| 5711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5712 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5713 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5714 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5715 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5716 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5718 | |
| 5719 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5720 | MockWrite( |
| 5721 | "GET / HTTP/1.1\r\n" |
| 5722 | "Host: www.example.org\r\n" |
| 5723 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5724 | }; |
| 5725 | |
| 5726 | MockRead data_reads1[] = { |
| 5727 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5728 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5729 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5730 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5731 | }; |
| 5732 | |
| 5733 | // After the challenge above, the transaction will be restarted using the |
| 5734 | // identity supplied by the user, not the one in the URL, to answer the |
| 5735 | // challenge. |
| 5736 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5737 | MockWrite( |
| 5738 | "GET / HTTP/1.1\r\n" |
| 5739 | "Host: www.example.org\r\n" |
| 5740 | "Connection: keep-alive\r\n" |
| 5741 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5742 | }; |
| 5743 | |
| 5744 | MockRead data_reads3[] = { |
| 5745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5746 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5747 | MockRead(SYNCHRONOUS, OK), |
| 5748 | }; |
| 5749 | |
| 5750 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5751 | data_writes1, arraysize(data_writes1)); |
| 5752 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5753 | data_writes3, arraysize(data_writes3)); |
| 5754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5755 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5756 | |
| 5757 | TestCompletionCallback callback1; |
| 5758 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5759 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5760 | rv = callback1.WaitForResult(); |
| 5761 | EXPECT_EQ(OK, rv); |
| 5762 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5763 | |
| 5764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5765 | ASSERT_TRUE(response != NULL); |
| 5766 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5767 | |
| 5768 | TestCompletionCallback callback3; |
| 5769 | rv = trans->RestartWithAuth( |
| 5770 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5771 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5772 | rv = callback3.WaitForResult(); |
| 5773 | EXPECT_EQ(OK, rv); |
| 5774 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5775 | |
| 5776 | response = trans->GetResponseInfo(); |
| 5777 | ASSERT_TRUE(response != NULL); |
| 5778 | |
| 5779 | // There is no challenge info, since the identity worked. |
| 5780 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5781 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5782 | |
| 5783 | // Empty the current queue. |
| 5784 | base::MessageLoop::current()->RunUntilIdle(); |
| 5785 | } |
| 5786 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5787 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5788 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5789 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5790 | |
| 5791 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5792 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5793 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5794 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5795 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5796 | request.load_flags = 0; |
| 5797 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5798 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5800 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5801 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5802 | MockWrite( |
| 5803 | "GET /x/y/z HTTP/1.1\r\n" |
| 5804 | "Host: www.example.org\r\n" |
| 5805 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5806 | }; |
| 5807 | |
| 5808 | MockRead data_reads1[] = { |
| 5809 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5810 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5811 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5812 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5813 | }; |
| 5814 | |
| 5815 | // Resend with authorization (username=foo, password=bar) |
| 5816 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5817 | MockWrite( |
| 5818 | "GET /x/y/z HTTP/1.1\r\n" |
| 5819 | "Host: www.example.org\r\n" |
| 5820 | "Connection: keep-alive\r\n" |
| 5821 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5822 | }; |
| 5823 | |
| 5824 | // Sever accepts the authorization. |
| 5825 | MockRead data_reads2[] = { |
| 5826 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5827 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5829 | }; |
| 5830 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5831 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5832 | data_writes1, arraysize(data_writes1)); |
| 5833 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5834 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5835 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5836 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5838 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5840 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5841 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5842 | |
| 5843 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5844 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5845 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5846 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5847 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5848 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5850 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5852 | rv = trans->RestartWithAuth( |
| 5853 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5854 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5855 | |
| 5856 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5857 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5858 | |
| 5859 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5860 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5861 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5862 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5863 | } |
| 5864 | |
| 5865 | // ------------------------------------------------------------------------ |
| 5866 | |
| 5867 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5868 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5869 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5870 | request.method = "GET"; |
| 5871 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5872 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5873 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5874 | request.load_flags = 0; |
| 5875 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5876 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5878 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5879 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5880 | MockWrite( |
| 5881 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5882 | "Host: www.example.org\r\n" |
| 5883 | "Connection: keep-alive\r\n" |
| 5884 | // Send preemptive authorization for MyRealm1 |
| 5885 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5886 | }; |
| 5887 | |
| 5888 | // The server didn't like the preemptive authorization, and |
| 5889 | // challenges us for a different realm (MyRealm2). |
| 5890 | MockRead data_reads1[] = { |
| 5891 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5892 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5893 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5894 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5895 | }; |
| 5896 | |
| 5897 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5898 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5899 | MockWrite( |
| 5900 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5901 | "Host: www.example.org\r\n" |
| 5902 | "Connection: keep-alive\r\n" |
| 5903 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5904 | }; |
| 5905 | |
| 5906 | // Sever accepts the authorization. |
| 5907 | MockRead data_reads2[] = { |
| 5908 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5909 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5911 | }; |
| 5912 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5913 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5914 | data_writes1, arraysize(data_writes1)); |
| 5915 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5916 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5917 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5918 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5920 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5922 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5924 | |
| 5925 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5926 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5927 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5928 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5929 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5930 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5931 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5932 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5933 | response->auth_challenge->challenger.ToString()); |
| 5934 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5935 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5937 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5939 | rv = trans->RestartWithAuth( |
| 5940 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5942 | |
| 5943 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5944 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5945 | |
| 5946 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5947 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5948 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5949 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5950 | } |
| 5951 | |
| 5952 | // ------------------------------------------------------------------------ |
| 5953 | |
| 5954 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5955 | // succeed with preemptive authorization. |
| 5956 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5957 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5959 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5960 | request.load_flags = 0; |
| 5961 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5962 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5963 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5964 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5965 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5966 | MockWrite( |
| 5967 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 5968 | "Host: www.example.org\r\n" |
| 5969 | "Connection: keep-alive\r\n" |
| 5970 | // The authorization for MyRealm1 gets sent preemptively |
| 5971 | // (since the url is in the same protection space) |
| 5972 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5973 | }; |
| 5974 | |
| 5975 | // Sever accepts the preemptive authorization |
| 5976 | MockRead data_reads1[] = { |
| 5977 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5978 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5980 | }; |
| 5981 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5982 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5983 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5984 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5986 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5988 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5989 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5990 | |
| 5991 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5992 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5993 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5994 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5995 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5996 | |
| 5997 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5998 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5999 | } |
| 6000 | |
| 6001 | // ------------------------------------------------------------------------ |
| 6002 | |
| 6003 | // Transaction 4: request another URL in MyRealm (however the |
| 6004 | // url is not known to belong to the protection space, so no pre-auth). |
| 6005 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6006 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6008 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6009 | request.load_flags = 0; |
| 6010 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6011 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6012 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6013 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6014 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6015 | MockWrite( |
| 6016 | "GET /x/1 HTTP/1.1\r\n" |
| 6017 | "Host: www.example.org\r\n" |
| 6018 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6019 | }; |
| 6020 | |
| 6021 | MockRead data_reads1[] = { |
| 6022 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6023 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6024 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6025 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6026 | }; |
| 6027 | |
| 6028 | // Resend with authorization from MyRealm's cache. |
| 6029 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6030 | MockWrite( |
| 6031 | "GET /x/1 HTTP/1.1\r\n" |
| 6032 | "Host: www.example.org\r\n" |
| 6033 | "Connection: keep-alive\r\n" |
| 6034 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6035 | }; |
| 6036 | |
| 6037 | // Sever accepts the authorization. |
| 6038 | MockRead data_reads2[] = { |
| 6039 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6040 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6041 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6042 | }; |
| 6043 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6044 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6045 | data_writes1, arraysize(data_writes1)); |
| 6046 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6047 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6048 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6049 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6053 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6055 | |
| 6056 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6057 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6058 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6059 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6060 | TestCompletionCallback callback2; |
| 6061 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6062 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6063 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6064 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6065 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6066 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6067 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6068 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6069 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6070 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6071 | } |
| 6072 | |
| 6073 | // ------------------------------------------------------------------------ |
| 6074 | |
| 6075 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6076 | // cached identity. Should invalidate and re-prompt. |
| 6077 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6078 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6079 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6080 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6081 | request.load_flags = 0; |
| 6082 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6083 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6084 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6085 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6086 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6087 | MockWrite( |
| 6088 | "GET /p/q/t HTTP/1.1\r\n" |
| 6089 | "Host: www.example.org\r\n" |
| 6090 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6091 | }; |
| 6092 | |
| 6093 | MockRead data_reads1[] = { |
| 6094 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6095 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6096 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6097 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6098 | }; |
| 6099 | |
| 6100 | // Resend with authorization from cache for MyRealm. |
| 6101 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6102 | MockWrite( |
| 6103 | "GET /p/q/t HTTP/1.1\r\n" |
| 6104 | "Host: www.example.org\r\n" |
| 6105 | "Connection: keep-alive\r\n" |
| 6106 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6107 | }; |
| 6108 | |
| 6109 | // Sever rejects the authorization. |
| 6110 | MockRead data_reads2[] = { |
| 6111 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6112 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6113 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6114 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6115 | }; |
| 6116 | |
| 6117 | // At this point we should prompt for new credentials for MyRealm. |
| 6118 | // Restart with username=foo3, password=foo4. |
| 6119 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6120 | MockWrite( |
| 6121 | "GET /p/q/t HTTP/1.1\r\n" |
| 6122 | "Host: www.example.org\r\n" |
| 6123 | "Connection: keep-alive\r\n" |
| 6124 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6125 | }; |
| 6126 | |
| 6127 | // Sever accepts the authorization. |
| 6128 | MockRead data_reads3[] = { |
| 6129 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6130 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6131 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6132 | }; |
| 6133 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6134 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6135 | data_writes1, arraysize(data_writes1)); |
| 6136 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6137 | data_writes2, arraysize(data_writes2)); |
| 6138 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6139 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6140 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6141 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6142 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6144 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6145 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6146 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6147 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6148 | |
| 6149 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6150 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6151 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6152 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6153 | TestCompletionCallback callback2; |
| 6154 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6155 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6156 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6157 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6158 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6159 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6160 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6161 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6162 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6164 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6166 | rv = trans->RestartWithAuth( |
| 6167 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6168 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6169 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6170 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6171 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6172 | |
| 6173 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6174 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6175 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6176 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6177 | } |
| 6178 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6179 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6180 | // Tests that nonce count increments when multiple auth attempts |
| 6181 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6182 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6183 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6184 | new HttpAuthHandlerDigest::Factory(); |
| 6185 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6186 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6187 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6188 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6190 | |
| 6191 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6192 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6193 | HttpRequestInfo request; |
| 6194 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6195 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6196 | request.load_flags = 0; |
| 6197 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6198 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6200 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6201 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6202 | MockWrite( |
| 6203 | "GET /x/y/z HTTP/1.1\r\n" |
| 6204 | "Host: www.example.org\r\n" |
| 6205 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6206 | }; |
| 6207 | |
| 6208 | MockRead data_reads1[] = { |
| 6209 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6210 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6211 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6213 | }; |
| 6214 | |
| 6215 | // Resend with authorization (username=foo, password=bar) |
| 6216 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6217 | MockWrite( |
| 6218 | "GET /x/y/z HTTP/1.1\r\n" |
| 6219 | "Host: www.example.org\r\n" |
| 6220 | "Connection: keep-alive\r\n" |
| 6221 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6222 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6223 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6224 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6225 | }; |
| 6226 | |
| 6227 | // Sever accepts the authorization. |
| 6228 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6229 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6230 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6231 | }; |
| 6232 | |
| 6233 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6234 | data_writes1, arraysize(data_writes1)); |
| 6235 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6236 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6237 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6238 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6240 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6242 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6244 | |
| 6245 | rv = callback1.WaitForResult(); |
| 6246 | EXPECT_EQ(OK, rv); |
| 6247 | |
| 6248 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6249 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6250 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6254 | rv = trans->RestartWithAuth( |
| 6255 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6257 | |
| 6258 | rv = callback2.WaitForResult(); |
| 6259 | EXPECT_EQ(OK, rv); |
| 6260 | |
| 6261 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6262 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6263 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6264 | } |
| 6265 | |
| 6266 | // ------------------------------------------------------------------------ |
| 6267 | |
| 6268 | // Transaction 2: Request another resource in digestive's protection space. |
| 6269 | // This will preemptively add an Authorization header which should have an |
| 6270 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6271 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6272 | HttpRequestInfo request; |
| 6273 | request.method = "GET"; |
| 6274 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6275 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6276 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6277 | request.load_flags = 0; |
| 6278 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6279 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6281 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6282 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6283 | MockWrite( |
| 6284 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6285 | "Host: www.example.org\r\n" |
| 6286 | "Connection: keep-alive\r\n" |
| 6287 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6288 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6289 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6290 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6291 | }; |
| 6292 | |
| 6293 | // Sever accepts the authorization. |
| 6294 | MockRead data_reads1[] = { |
| 6295 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6296 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6297 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6298 | }; |
| 6299 | |
| 6300 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6301 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6302 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6304 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6306 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6307 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6308 | |
| 6309 | rv = callback1.WaitForResult(); |
| 6310 | EXPECT_EQ(OK, rv); |
| 6311 | |
| 6312 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6313 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6314 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6315 | } |
| 6316 | } |
| 6317 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6318 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6319 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6320 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6321 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6322 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6323 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6324 | |
| 6325 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6326 | trans->read_buf_ = new IOBuffer(15); |
| 6327 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6328 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6329 | |
| 6330 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6331 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6332 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6333 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6334 | response->response_time = base::Time::Now(); |
| 6335 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6336 | |
| 6337 | { // Setup state for response_.vary_data |
| 6338 | HttpRequestInfo request; |
| 6339 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6340 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6341 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6342 | request.extra_headers.SetHeader("Foo", "1"); |
| 6343 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6344 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | // Cause the above state to be reset. |
| 6348 | trans->ResetStateForRestart(); |
| 6349 | |
| 6350 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6351 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6352 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6353 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6354 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6355 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6356 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6357 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6358 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6359 | } |
| 6360 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6361 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6362 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6363 | HttpRequestInfo request; |
| 6364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6365 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6366 | request.load_flags = 0; |
| 6367 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6368 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6369 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6370 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6371 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6372 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6373 | MockWrite( |
| 6374 | "GET / HTTP/1.1\r\n" |
| 6375 | "Host: www.example.org\r\n" |
| 6376 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6377 | }; |
| 6378 | |
| 6379 | MockRead data_reads[] = { |
| 6380 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6381 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6382 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6383 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6384 | }; |
| 6385 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6386 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6388 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6389 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6390 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6391 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6392 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6393 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6397 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6399 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6401 | |
| 6402 | rv = callback.WaitForResult(); |
| 6403 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6405 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6406 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6407 | |
| 6408 | rv = callback.WaitForResult(); |
| 6409 | EXPECT_EQ(OK, rv); |
| 6410 | |
| 6411 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6412 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6413 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6414 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6415 | } |
| 6416 | |
| 6417 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6418 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6419 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6420 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6421 | |
| 6422 | HttpRequestInfo request; |
| 6423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6424 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6425 | request.load_flags = 0; |
| 6426 | |
| 6427 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6428 | MockWrite( |
| 6429 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6430 | "Host: www.example.org\r\n" |
| 6431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6432 | }; |
| 6433 | |
| 6434 | MockRead proxy_reads[] = { |
| 6435 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6436 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6437 | }; |
| 6438 | |
| 6439 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6440 | MockWrite( |
| 6441 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6442 | "Host: www.example.org\r\n" |
| 6443 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6444 | MockWrite( |
| 6445 | "GET / HTTP/1.1\r\n" |
| 6446 | "Host: www.example.org\r\n" |
| 6447 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6448 | }; |
| 6449 | |
| 6450 | MockRead data_reads[] = { |
| 6451 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6452 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6454 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6455 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6456 | }; |
| 6457 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6458 | StaticSocketDataProvider ssl_bad_certificate( |
| 6459 | proxy_reads, arraysize(proxy_reads), |
| 6460 | proxy_writes, arraysize(proxy_writes)); |
| 6461 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6462 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6463 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6464 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6465 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6466 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6471 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6472 | |
| 6473 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6474 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6475 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6476 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6477 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6478 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6480 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6482 | |
| 6483 | rv = callback.WaitForResult(); |
| 6484 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6486 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6487 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6488 | |
| 6489 | rv = callback.WaitForResult(); |
| 6490 | EXPECT_EQ(OK, rv); |
| 6491 | |
| 6492 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6493 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6494 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6495 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6496 | } |
| 6497 | } |
| 6498 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6499 | |
| 6500 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6501 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6502 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6503 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6504 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6505 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6506 | |
| 6507 | HttpRequestInfo request; |
| 6508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6509 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6510 | request.load_flags = 0; |
| 6511 | |
| 6512 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6513 | MockWrite( |
| 6514 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6515 | "Host: www.example.org\r\n" |
| 6516 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6517 | MockWrite( |
| 6518 | "GET / HTTP/1.1\r\n" |
| 6519 | "Host: www.example.org\r\n" |
| 6520 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6521 | }; |
| 6522 | |
| 6523 | MockRead data_reads[] = { |
| 6524 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6525 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6527 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6528 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6529 | }; |
| 6530 | |
| 6531 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6532 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6533 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6534 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6535 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6536 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6537 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6540 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6541 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6542 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6543 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6544 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6546 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6547 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6548 | |
| 6549 | rv = callback.WaitForResult(); |
| 6550 | EXPECT_EQ(OK, rv); |
| 6551 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6552 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6553 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6554 | |
| 6555 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6556 | EXPECT_EQ(200, response->headers->response_code()); |
| 6557 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6558 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6559 | |
| 6560 | LoadTimingInfo load_timing_info; |
| 6561 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6562 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6563 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6564 | } |
| 6565 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6566 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6567 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6568 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6569 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6570 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6571 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6572 | |
| 6573 | HttpRequestInfo request; |
| 6574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6575 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6576 | request.load_flags = 0; |
| 6577 | |
| 6578 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6579 | MockWrite( |
| 6580 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6581 | "Host: www.example.org\r\n" |
| 6582 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6583 | }; |
| 6584 | |
| 6585 | MockRead data_reads[] = { |
| 6586 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6587 | MockRead("Location: http://login.example.com/\r\n"), |
| 6588 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6590 | }; |
| 6591 | |
| 6592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6593 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6594 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6595 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6599 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6600 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6601 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6602 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6603 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6606 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6607 | |
| 6608 | rv = callback.WaitForResult(); |
| 6609 | EXPECT_EQ(OK, rv); |
| 6610 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6611 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6612 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6613 | |
| 6614 | EXPECT_EQ(302, response->headers->response_code()); |
| 6615 | std::string url; |
| 6616 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6617 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6618 | |
| 6619 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6620 | // timing for the proxy connection instead of the connection to the host, |
| 6621 | // and no send / receive times. |
| 6622 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6623 | LoadTimingInfo load_timing_info; |
| 6624 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6625 | |
| 6626 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6627 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6628 | |
| 6629 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6630 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6631 | load_timing_info.proxy_resolve_end); |
| 6632 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6633 | load_timing_info.connect_timing.connect_start); |
| 6634 | ExpectConnectTimingHasTimes( |
| 6635 | load_timing_info.connect_timing, |
| 6636 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6637 | |
| 6638 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6639 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6640 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6644 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6645 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6646 | ProxyService::CreateFixed("https://proxy:70")); |
| 6647 | |
| 6648 | HttpRequestInfo request; |
| 6649 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6650 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6651 | request.load_flags = 0; |
| 6652 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6653 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6654 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6655 | scoped_ptr<SpdyFrame> goaway( |
| 6656 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6657 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6658 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6659 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6660 | }; |
| 6661 | |
| 6662 | static const char* const kExtraHeaders[] = { |
| 6663 | "location", |
| 6664 | "http://login.example.com/", |
| 6665 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6666 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6667 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6668 | arraysize(kExtraHeaders)/2, 1)); |
| 6669 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6670 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6671 | }; |
| 6672 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6673 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6674 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6675 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6676 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6677 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6681 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6682 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6683 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6684 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6687 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6688 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6689 | |
| 6690 | rv = callback.WaitForResult(); |
| 6691 | EXPECT_EQ(OK, rv); |
| 6692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6693 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6694 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6695 | |
| 6696 | EXPECT_EQ(302, response->headers->response_code()); |
| 6697 | std::string url; |
| 6698 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6699 | EXPECT_EQ("http://login.example.com/", url); |
| 6700 | } |
| 6701 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6702 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6703 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6704 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6705 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6706 | ProxyService::CreateFixed("https://proxy:70")); |
| 6707 | |
| 6708 | HttpRequestInfo request; |
| 6709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6710 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6711 | request.load_flags = 0; |
| 6712 | |
| 6713 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6714 | MockWrite( |
| 6715 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6716 | "Host: www.example.org\r\n" |
| 6717 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6718 | }; |
| 6719 | |
| 6720 | MockRead data_reads[] = { |
| 6721 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6722 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6723 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6725 | }; |
| 6726 | |
| 6727 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6728 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6729 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6730 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6732 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6734 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6735 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6736 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6737 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6738 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6740 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6741 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6742 | |
| 6743 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6744 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6745 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6746 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6747 | } |
| 6748 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6749 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6750 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6751 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6752 | session_deps_.proxy_service.reset( |
| 6753 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6754 | |
| 6755 | HttpRequestInfo request; |
| 6756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6757 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6758 | request.load_flags = 0; |
| 6759 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6760 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6761 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6762 | scoped_ptr<SpdyFrame> rst( |
| 6763 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6764 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6765 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6766 | }; |
| 6767 | |
| 6768 | static const char* const kExtraHeaders[] = { |
| 6769 | "location", |
| 6770 | "http://login.example.com/", |
| 6771 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6772 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6773 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6774 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6775 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6776 | spdy_util_.ConstructSpdyBodyFrame( |
| 6777 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6778 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6779 | CreateMockRead(*resp.get(), 1), |
| 6780 | CreateMockRead(*body.get(), 2), |
| 6781 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6782 | }; |
| 6783 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6784 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6785 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6786 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6787 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6788 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6790 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6792 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6793 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6794 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6795 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6796 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6798 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6799 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6800 | |
| 6801 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6802 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6803 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6804 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6805 | } |
| 6806 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6807 | // Test the request-challenge-retry sequence for basic auth, through |
| 6808 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6809 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6810 | HttpRequestInfo request; |
| 6811 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6812 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6813 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6814 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6815 | |
| 6816 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6817 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6818 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6819 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6820 | session_deps_.net_log = log.bound().net_log(); |
| 6821 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6822 | |
| 6823 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6824 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6825 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6826 | scoped_ptr<SpdyFrame> rst( |
| 6827 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6828 | |
| 6829 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6830 | // be issuing -- the final header line contains the credentials. |
| 6831 | const char* const kAuthCredentials[] = { |
| 6832 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6833 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6834 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6835 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6836 | HostPortPair("www.example.org", 443))); |
| 6837 | // fetch https://www.example.org/ via HTTP |
| 6838 | const char get[] = |
| 6839 | "GET / HTTP/1.1\r\n" |
| 6840 | "Host: www.example.org\r\n" |
| 6841 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6842 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6843 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6844 | |
| 6845 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6846 | CreateMockWrite(*req, 0, ASYNC), |
| 6847 | CreateMockWrite(*rst, 2, ASYNC), |
| 6848 | CreateMockWrite(*connect2, 3), |
| 6849 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6850 | }; |
| 6851 | |
| 6852 | // The proxy responds to the connect with a 407, using a persistent |
| 6853 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6854 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6855 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6856 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6857 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6858 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6859 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6860 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6861 | scoped_ptr<SpdyFrame> conn_resp( |
| 6862 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6863 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6864 | "Content-Length: 5\r\n\r\n"; |
| 6865 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6866 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6867 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6868 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6869 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6870 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6871 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6872 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6873 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6874 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6875 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6876 | }; |
| 6877 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6878 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6879 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6880 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6881 | // Negotiate SPDY to the proxy |
| 6882 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6883 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6885 | // Vanilla SSL to the server |
| 6886 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6887 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6888 | |
| 6889 | TestCompletionCallback callback1; |
| 6890 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6891 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6893 | |
| 6894 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6895 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6896 | |
| 6897 | rv = callback1.WaitForResult(); |
| 6898 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6899 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6900 | log.GetEntries(&entries); |
| 6901 | size_t pos = ExpectLogContainsSomewhere( |
| 6902 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6903 | NetLog::PHASE_NONE); |
| 6904 | ExpectLogContainsSomewhere( |
| 6905 | entries, pos, |
| 6906 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6907 | NetLog::PHASE_NONE); |
| 6908 | |
| 6909 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6910 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6911 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6912 | EXPECT_EQ(407, response->headers->response_code()); |
| 6913 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6914 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6915 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6916 | |
| 6917 | TestCompletionCallback callback2; |
| 6918 | |
| 6919 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6920 | callback2.callback()); |
| 6921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6922 | |
| 6923 | rv = callback2.WaitForResult(); |
| 6924 | EXPECT_EQ(OK, rv); |
| 6925 | |
| 6926 | response = trans->GetResponseInfo(); |
| 6927 | ASSERT_TRUE(response != NULL); |
| 6928 | |
| 6929 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6930 | EXPECT_EQ(200, response->headers->response_code()); |
| 6931 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6932 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6933 | |
| 6934 | // The password prompt info should not be set. |
| 6935 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6936 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6937 | LoadTimingInfo load_timing_info; |
| 6938 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6939 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6940 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6941 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6942 | trans.reset(); |
| 6943 | session->CloseAllConnections(); |
| 6944 | } |
| 6945 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6946 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6947 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6948 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6949 | HttpRequestInfo request; |
| 6950 | HttpRequestInfo push_request; |
| 6951 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6953 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6954 | push_request.method = "GET"; |
| 6955 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6956 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6957 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6958 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6959 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6960 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6961 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6962 | |
| 6963 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6964 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6965 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6966 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6967 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6968 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6969 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6970 | |
| 6971 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6972 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6973 | }; |
| 6974 | |
| 6975 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6976 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6977 | |
| 6978 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6979 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6980 | |
| 6981 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6982 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6983 | 0, |
| 6984 | 2, |
| 6985 | 1, |
| 6986 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6987 | const char kPushedData[] = "pushed"; |
| 6988 | scoped_ptr<SpdyFrame> stream2_body( |
| 6989 | spdy_util_.ConstructSpdyBodyFrame( |
| 6990 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6991 | |
| 6992 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6993 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 6994 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 6995 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 6996 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 6997 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6998 | }; |
| 6999 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7000 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7001 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7002 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7003 | // Negotiate SPDY to the proxy |
| 7004 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7005 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7007 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7008 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7009 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7010 | TestCompletionCallback callback; |
| 7011 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7012 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7013 | |
| 7014 | rv = callback.WaitForResult(); |
| 7015 | EXPECT_EQ(OK, rv); |
| 7016 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7017 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7018 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7020 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7021 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7022 | |
| 7023 | rv = callback.WaitForResult(); |
| 7024 | EXPECT_EQ(OK, rv); |
| 7025 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7026 | |
| 7027 | ASSERT_TRUE(response != NULL); |
| 7028 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7029 | |
| 7030 | EXPECT_EQ(200, response->headers->response_code()); |
| 7031 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7032 | |
| 7033 | std::string response_data; |
| 7034 | rv = ReadTransaction(trans.get(), &response_data); |
| 7035 | EXPECT_EQ(OK, rv); |
| 7036 | EXPECT_EQ("hello!", response_data); |
| 7037 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7038 | LoadTimingInfo load_timing_info; |
| 7039 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7040 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7041 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7042 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7043 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7044 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7045 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7046 | |
| 7047 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7048 | EXPECT_EQ(OK, rv); |
| 7049 | EXPECT_EQ("pushed", response_data); |
| 7050 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7051 | LoadTimingInfo push_load_timing_info; |
| 7052 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7053 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7054 | // The transactions should share a socket ID, despite being for different |
| 7055 | // origins. |
| 7056 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7057 | push_load_timing_info.socket_log_id); |
| 7058 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7059 | trans.reset(); |
| 7060 | push_trans.reset(); |
| 7061 | session->CloseAllConnections(); |
| 7062 | } |
| 7063 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7064 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7065 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7066 | HttpRequestInfo request; |
| 7067 | |
| 7068 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7069 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7070 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7071 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7072 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7073 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7074 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7075 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7076 | |
| 7077 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7078 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7079 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7080 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7081 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7082 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7083 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7084 | |
| 7085 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7086 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7087 | |
| 7088 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7089 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7090 | }; |
| 7091 | |
| 7092 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7093 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7094 | |
| 7095 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7096 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7097 | |
| 7098 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7099 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7100 | 0, |
| 7101 | 2, |
| 7102 | 1, |
| 7103 | "https://www.another-origin.com/foo.dat")); |
| 7104 | |
| 7105 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7106 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7107 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7108 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7109 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7110 | }; |
| 7111 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7112 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7113 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7114 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7115 | // Negotiate SPDY to the proxy |
| 7116 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7117 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7119 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7120 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7122 | TestCompletionCallback callback; |
| 7123 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7125 | |
| 7126 | rv = callback.WaitForResult(); |
| 7127 | EXPECT_EQ(OK, rv); |
| 7128 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7129 | |
| 7130 | ASSERT_TRUE(response != NULL); |
| 7131 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7132 | |
| 7133 | EXPECT_EQ(200, response->headers->response_code()); |
| 7134 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7135 | |
| 7136 | std::string response_data; |
| 7137 | rv = ReadTransaction(trans.get(), &response_data); |
| 7138 | EXPECT_EQ(OK, rv); |
| 7139 | EXPECT_EQ("hello!", response_data); |
| 7140 | |
| 7141 | trans.reset(); |
| 7142 | session->CloseAllConnections(); |
| 7143 | } |
| 7144 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7145 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7146 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7147 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7148 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7149 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7150 | |
| 7151 | HttpRequestInfo request; |
| 7152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7153 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7154 | request.load_flags = 0; |
| 7155 | |
| 7156 | // Attempt to fetch the URL from a server with a bad cert |
| 7157 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7158 | MockWrite( |
| 7159 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7160 | "Host: www.example.org\r\n" |
| 7161 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7162 | }; |
| 7163 | |
| 7164 | MockRead bad_cert_reads[] = { |
| 7165 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7166 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7167 | }; |
| 7168 | |
| 7169 | // Attempt to fetch the URL with a good cert |
| 7170 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7171 | MockWrite( |
| 7172 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7173 | "Host: www.example.org\r\n" |
| 7174 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7175 | MockWrite( |
| 7176 | "GET / HTTP/1.1\r\n" |
| 7177 | "Host: www.example.org\r\n" |
| 7178 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7179 | }; |
| 7180 | |
| 7181 | MockRead good_cert_reads[] = { |
| 7182 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7183 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7184 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7185 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7186 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7187 | }; |
| 7188 | |
| 7189 | StaticSocketDataProvider ssl_bad_certificate( |
| 7190 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7191 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7192 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7193 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7194 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7195 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7196 | |
| 7197 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7199 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7200 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7201 | |
| 7202 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7207 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7208 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7209 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7210 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7213 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7214 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7215 | |
| 7216 | rv = callback.WaitForResult(); |
| 7217 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7219 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7220 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7221 | |
| 7222 | rv = callback.WaitForResult(); |
| 7223 | EXPECT_EQ(OK, rv); |
| 7224 | |
| 7225 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7226 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7227 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7228 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7229 | } |
| 7230 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7231 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7232 | HttpRequestInfo request; |
| 7233 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7234 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7235 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7236 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7237 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7238 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7239 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7241 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7242 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7243 | MockWrite( |
| 7244 | "GET / HTTP/1.1\r\n" |
| 7245 | "Host: www.example.org\r\n" |
| 7246 | "Connection: keep-alive\r\n" |
| 7247 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7248 | }; |
| 7249 | |
| 7250 | // Lastly, the server responds with the actual content. |
| 7251 | MockRead data_reads[] = { |
| 7252 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7253 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7254 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7255 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7256 | }; |
| 7257 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7258 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7259 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7260 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7262 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7264 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7266 | |
| 7267 | rv = callback.WaitForResult(); |
| 7268 | EXPECT_EQ(OK, rv); |
| 7269 | } |
| 7270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7271 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7272 | HttpRequestInfo request; |
| 7273 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7274 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7275 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7276 | "Chromium Ultra Awesome X Edition"); |
| 7277 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7278 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7279 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7280 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7282 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7283 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7284 | MockWrite( |
| 7285 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7286 | "Host: www.example.org\r\n" |
| 7287 | "Proxy-Connection: keep-alive\r\n" |
| 7288 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7289 | }; |
| 7290 | MockRead data_reads[] = { |
| 7291 | // Return an error, so the transaction stops here (this test isn't |
| 7292 | // interested in the rest). |
| 7293 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7294 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7295 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7296 | }; |
| 7297 | |
| 7298 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7299 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7302 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7304 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7306 | |
| 7307 | rv = callback.WaitForResult(); |
| 7308 | EXPECT_EQ(OK, rv); |
| 7309 | } |
| 7310 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7311 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7312 | HttpRequestInfo request; |
| 7313 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7314 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7315 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7316 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7317 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7318 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7319 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7320 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7321 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7322 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7323 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7324 | MockWrite( |
| 7325 | "GET / HTTP/1.1\r\n" |
| 7326 | "Host: www.example.org\r\n" |
| 7327 | "Connection: keep-alive\r\n" |
| 7328 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7329 | }; |
| 7330 | |
| 7331 | // Lastly, the server responds with the actual content. |
| 7332 | MockRead data_reads[] = { |
| 7333 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7335 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7337 | }; |
| 7338 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7340 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7341 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7343 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7345 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7346 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7347 | |
| 7348 | rv = callback.WaitForResult(); |
| 7349 | EXPECT_EQ(OK, rv); |
| 7350 | } |
| 7351 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7352 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7353 | HttpRequestInfo request; |
| 7354 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7355 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7356 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7357 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7358 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7360 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7361 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7362 | MockWrite( |
| 7363 | "POST / HTTP/1.1\r\n" |
| 7364 | "Host: www.example.org\r\n" |
| 7365 | "Connection: keep-alive\r\n" |
| 7366 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7367 | }; |
| 7368 | |
| 7369 | // Lastly, the server responds with the actual content. |
| 7370 | MockRead data_reads[] = { |
| 7371 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7372 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7373 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7374 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7375 | }; |
| 7376 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7377 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7378 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7381 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7385 | |
| 7386 | rv = callback.WaitForResult(); |
| 7387 | EXPECT_EQ(OK, rv); |
| 7388 | } |
| 7389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7390 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7391 | HttpRequestInfo request; |
| 7392 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7393 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7394 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7395 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7396 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7397 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7398 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7399 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7400 | MockWrite( |
| 7401 | "PUT / HTTP/1.1\r\n" |
| 7402 | "Host: www.example.org\r\n" |
| 7403 | "Connection: keep-alive\r\n" |
| 7404 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7405 | }; |
| 7406 | |
| 7407 | // Lastly, the server responds with the actual content. |
| 7408 | MockRead data_reads[] = { |
| 7409 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7410 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7411 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7412 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7413 | }; |
| 7414 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7415 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7416 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7417 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7419 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7421 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7423 | |
| 7424 | rv = callback.WaitForResult(); |
| 7425 | EXPECT_EQ(OK, rv); |
| 7426 | } |
| 7427 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7428 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7429 | HttpRequestInfo request; |
| 7430 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7431 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7432 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7433 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7434 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7436 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7437 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 7438 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7439 | "Host: www.example.org\r\n" |
| 7440 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7441 | }; |
| 7442 | |
| 7443 | // Lastly, the server responds with the actual content. |
| 7444 | MockRead data_reads[] = { |
| 7445 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7446 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7447 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7448 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7449 | }; |
| 7450 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7451 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7452 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7455 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7457 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7458 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7459 | |
| 7460 | rv = callback.WaitForResult(); |
| 7461 | EXPECT_EQ(OK, rv); |
| 7462 | } |
| 7463 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7464 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7465 | HttpRequestInfo request; |
| 7466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7467 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7468 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7469 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7470 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7471 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7472 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7473 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7474 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7475 | MockWrite( |
| 7476 | "GET / HTTP/1.1\r\n" |
| 7477 | "Host: www.example.org\r\n" |
| 7478 | "Connection: keep-alive\r\n" |
| 7479 | "Pragma: no-cache\r\n" |
| 7480 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7481 | }; |
| 7482 | |
| 7483 | // Lastly, the server responds with the actual content. |
| 7484 | MockRead data_reads[] = { |
| 7485 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7487 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7488 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7489 | }; |
| 7490 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7491 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7492 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7495 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7497 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7499 | |
| 7500 | rv = callback.WaitForResult(); |
| 7501 | EXPECT_EQ(OK, rv); |
| 7502 | } |
| 7503 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7504 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7505 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7506 | HttpRequestInfo request; |
| 7507 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7508 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7509 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7510 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7511 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7512 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7514 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7515 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7516 | MockWrite( |
| 7517 | "GET / HTTP/1.1\r\n" |
| 7518 | "Host: www.example.org\r\n" |
| 7519 | "Connection: keep-alive\r\n" |
| 7520 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7521 | }; |
| 7522 | |
| 7523 | // Lastly, the server responds with the actual content. |
| 7524 | MockRead data_reads[] = { |
| 7525 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7527 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7528 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7529 | }; |
| 7530 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7531 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7532 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7537 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7539 | |
| 7540 | rv = callback.WaitForResult(); |
| 7541 | EXPECT_EQ(OK, rv); |
| 7542 | } |
| 7543 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7544 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7545 | HttpRequestInfo request; |
| 7546 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7547 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7548 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7549 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7550 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7551 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7553 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7554 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7555 | MockWrite( |
| 7556 | "GET / HTTP/1.1\r\n" |
| 7557 | "Host: www.example.org\r\n" |
| 7558 | "Connection: keep-alive\r\n" |
| 7559 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7560 | }; |
| 7561 | |
| 7562 | // Lastly, the server responds with the actual content. |
| 7563 | MockRead data_reads[] = { |
| 7564 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7566 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7567 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7568 | }; |
| 7569 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7570 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7571 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7574 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7576 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7577 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7578 | |
| 7579 | rv = callback.WaitForResult(); |
| 7580 | EXPECT_EQ(OK, rv); |
| 7581 | } |
| 7582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7583 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7584 | HttpRequestInfo request; |
| 7585 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7586 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7587 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7588 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7589 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7590 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7591 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7592 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7593 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7594 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7595 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7596 | MockWrite( |
| 7597 | "GET / HTTP/1.1\r\n" |
| 7598 | "Host: www.example.org\r\n" |
| 7599 | "Connection: keep-alive\r\n" |
| 7600 | "referer: www.foo.com\r\n" |
| 7601 | "hEllo: Kitty\r\n" |
| 7602 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7603 | }; |
| 7604 | |
| 7605 | // Lastly, the server responds with the actual content. |
| 7606 | MockRead data_reads[] = { |
| 7607 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7608 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7609 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7610 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7611 | }; |
| 7612 | |
| 7613 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7614 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7616 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7617 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7619 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7620 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7621 | |
| 7622 | rv = callback.WaitForResult(); |
| 7623 | EXPECT_EQ(OK, rv); |
| 7624 | } |
| 7625 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7626 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7627 | HttpRequestInfo request; |
| 7628 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7629 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7630 | request.load_flags = 0; |
| 7631 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7632 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7633 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7634 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7635 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7636 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7637 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7638 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7640 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7641 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7642 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7643 | |
| 7644 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7645 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7646 | MockWrite( |
| 7647 | "GET / HTTP/1.1\r\n" |
| 7648 | "Host: www.example.org\r\n" |
| 7649 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7650 | |
| 7651 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7652 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7653 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7654 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7655 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7656 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7657 | }; |
| 7658 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7659 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7660 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7663 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7664 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7665 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7666 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7667 | |
| 7668 | rv = callback.WaitForResult(); |
| 7669 | EXPECT_EQ(OK, rv); |
| 7670 | |
| 7671 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7672 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7673 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7674 | LoadTimingInfo load_timing_info; |
| 7675 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7676 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7677 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7678 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7679 | std::string response_text; |
| 7680 | rv = ReadTransaction(trans.get(), &response_text); |
| 7681 | EXPECT_EQ(OK, rv); |
| 7682 | EXPECT_EQ("Payload", response_text); |
| 7683 | } |
| 7684 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7685 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7686 | HttpRequestInfo request; |
| 7687 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7688 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7689 | request.load_flags = 0; |
| 7690 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7691 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7692 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7693 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7694 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7695 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7697 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7698 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7699 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7700 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7701 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7702 | |
| 7703 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7704 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7705 | arraysize(write_buffer)), |
| 7706 | MockWrite( |
| 7707 | "GET / HTTP/1.1\r\n" |
| 7708 | "Host: www.example.org\r\n" |
| 7709 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7710 | |
| 7711 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7712 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7713 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7714 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7715 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7716 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7717 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7718 | }; |
| 7719 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7720 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7721 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7722 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7723 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7724 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7727 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7729 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7731 | |
| 7732 | rv = callback.WaitForResult(); |
| 7733 | EXPECT_EQ(OK, rv); |
| 7734 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7735 | LoadTimingInfo load_timing_info; |
| 7736 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7737 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7738 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7739 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7740 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7741 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7742 | |
| 7743 | std::string response_text; |
| 7744 | rv = ReadTransaction(trans.get(), &response_text); |
| 7745 | EXPECT_EQ(OK, rv); |
| 7746 | EXPECT_EQ("Payload", response_text); |
| 7747 | } |
| 7748 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7749 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7750 | HttpRequestInfo request; |
| 7751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7752 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7753 | request.load_flags = 0; |
| 7754 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7755 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7756 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7757 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7758 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7759 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7760 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7761 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7763 | |
| 7764 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7765 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7766 | |
| 7767 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7768 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7769 | MockWrite( |
| 7770 | "GET / HTTP/1.1\r\n" |
| 7771 | "Host: www.example.org\r\n" |
| 7772 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7773 | |
| 7774 | MockRead data_reads[] = { |
| 7775 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7776 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7777 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7778 | MockRead("Payload"), |
| 7779 | MockRead(SYNCHRONOUS, OK) |
| 7780 | }; |
| 7781 | |
| 7782 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7783 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7785 | |
| 7786 | TestCompletionCallback callback; |
| 7787 | |
| 7788 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7789 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7790 | |
| 7791 | rv = callback.WaitForResult(); |
| 7792 | EXPECT_EQ(OK, rv); |
| 7793 | |
| 7794 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7795 | ASSERT_TRUE(response != NULL); |
| 7796 | |
| 7797 | LoadTimingInfo load_timing_info; |
| 7798 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7799 | TestLoadTimingNotReused(load_timing_info, |
| 7800 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7801 | |
| 7802 | std::string response_text; |
| 7803 | rv = ReadTransaction(trans.get(), &response_text); |
| 7804 | EXPECT_EQ(OK, rv); |
| 7805 | EXPECT_EQ("Payload", response_text); |
| 7806 | } |
| 7807 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7808 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7809 | HttpRequestInfo request; |
| 7810 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7811 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7812 | request.load_flags = 0; |
| 7813 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7814 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7815 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7816 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7817 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7818 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7819 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7820 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7821 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7822 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7823 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7824 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7825 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7826 | 0x05, // Version |
| 7827 | 0x01, // Command (CONNECT) |
| 7828 | 0x00, // Reserved. |
| 7829 | 0x03, // Address type (DOMAINNAME). |
| 7830 | 0x0F, // Length of domain (15) |
| 7831 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7832 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7833 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7834 | const char kSOCKS5OkResponse[] = |
| 7835 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7836 | |
| 7837 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7838 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7839 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7840 | MockWrite( |
| 7841 | "GET / HTTP/1.1\r\n" |
| 7842 | "Host: www.example.org\r\n" |
| 7843 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7844 | |
| 7845 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7846 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7847 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7848 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7849 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7850 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7851 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7852 | }; |
| 7853 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7854 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7855 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7858 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7860 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7861 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7862 | |
| 7863 | rv = callback.WaitForResult(); |
| 7864 | EXPECT_EQ(OK, rv); |
| 7865 | |
| 7866 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7867 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7868 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7869 | LoadTimingInfo load_timing_info; |
| 7870 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7871 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7872 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7873 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7874 | std::string response_text; |
| 7875 | rv = ReadTransaction(trans.get(), &response_text); |
| 7876 | EXPECT_EQ(OK, rv); |
| 7877 | EXPECT_EQ("Payload", response_text); |
| 7878 | } |
| 7879 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7880 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7881 | HttpRequestInfo request; |
| 7882 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7883 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7884 | request.load_flags = 0; |
| 7885 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7886 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7887 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7888 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7889 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7890 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7891 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7892 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7894 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7895 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7896 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7897 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7898 | 0x05, // Version |
| 7899 | 0x01, // Command (CONNECT) |
| 7900 | 0x00, // Reserved. |
| 7901 | 0x03, // Address type (DOMAINNAME). |
| 7902 | 0x0F, // Length of domain (15) |
| 7903 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7904 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7905 | }; |
| 7906 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7907 | const char kSOCKS5OkResponse[] = |
| 7908 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7909 | |
| 7910 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7911 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7912 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7913 | arraysize(kSOCKS5OkRequest)), |
| 7914 | MockWrite( |
| 7915 | "GET / HTTP/1.1\r\n" |
| 7916 | "Host: www.example.org\r\n" |
| 7917 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7918 | |
| 7919 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7920 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7921 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7922 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7923 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7924 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7925 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7926 | }; |
| 7927 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7928 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7929 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7931 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7932 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7935 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7937 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7938 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7939 | |
| 7940 | rv = callback.WaitForResult(); |
| 7941 | EXPECT_EQ(OK, rv); |
| 7942 | |
| 7943 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7944 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7945 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7946 | LoadTimingInfo load_timing_info; |
| 7947 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7948 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7949 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7950 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7951 | std::string response_text; |
| 7952 | rv = ReadTransaction(trans.get(), &response_text); |
| 7953 | EXPECT_EQ(OK, rv); |
| 7954 | EXPECT_EQ("Payload", response_text); |
| 7955 | } |
| 7956 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7957 | namespace { |
| 7958 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7959 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7960 | |
| 7961 | struct GroupNameTest { |
| 7962 | std::string proxy_server; |
| 7963 | std::string url; |
| 7964 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7965 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7966 | }; |
| 7967 | |
| 7968 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7969 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7970 | SpdySessionDependencies* session_deps_) { |
| 7971 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7972 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7973 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7974 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7975 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7976 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7977 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7978 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7979 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 7980 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7981 | |
| 7982 | return session; |
| 7983 | } |
| 7984 | |
| 7985 | int GroupNameTransactionHelper( |
| 7986 | const std::string& url, |
| 7987 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7988 | HttpRequestInfo request; |
| 7989 | request.method = "GET"; |
| 7990 | request.url = GURL(url); |
| 7991 | request.load_flags = 0; |
| 7992 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7993 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7994 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7996 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7997 | |
| 7998 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7999 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8000 | } |
| 8001 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8002 | } // namespace |
| 8003 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8004 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8005 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8006 | { |
| 8007 | "", // unused |
| 8008 | "http://www.example.org/direct", |
| 8009 | "www.example.org:80", |
| 8010 | false, |
| 8011 | }, |
| 8012 | { |
| 8013 | "", // unused |
| 8014 | "http://[2001:1418:13:1::25]/direct", |
| 8015 | "[2001:1418:13:1::25]:80", |
| 8016 | false, |
| 8017 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8018 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8019 | // SSL Tests |
| 8020 | { |
| 8021 | "", // unused |
| 8022 | "https://www.example.org/direct_ssl", |
| 8023 | "ssl/www.example.org:443", |
| 8024 | true, |
| 8025 | }, |
| 8026 | { |
| 8027 | "", // unused |
| 8028 | "https://[2001:1418:13:1::25]/direct", |
| 8029 | "ssl/[2001:1418:13:1::25]:443", |
| 8030 | true, |
| 8031 | }, |
| 8032 | { |
| 8033 | "", // unused |
| 8034 | "http://host.with.alternate/direct", |
| 8035 | "ssl/host.with.alternate:443", |
| 8036 | true, |
| 8037 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8038 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8039 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8040 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8041 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8042 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8043 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8044 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8045 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8046 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8047 | |
| 8048 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8049 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8050 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8051 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8052 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8053 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8054 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8055 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8056 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8057 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8058 | |
| 8059 | EXPECT_EQ(ERR_IO_PENDING, |
| 8060 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8061 | if (tests[i].ssl) |
| 8062 | EXPECT_EQ(tests[i].expected_group_name, |
| 8063 | ssl_conn_pool->last_group_name_received()); |
| 8064 | else |
| 8065 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8066 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8067 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8068 | } |
| 8069 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8070 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8071 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8072 | { |
| 8073 | "http_proxy", |
| 8074 | "http://www.example.org/http_proxy_normal", |
| 8075 | "www.example.org:80", |
| 8076 | false, |
| 8077 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8078 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8079 | // SSL Tests |
| 8080 | { |
| 8081 | "http_proxy", |
| 8082 | "https://www.example.org/http_connect_ssl", |
| 8083 | "ssl/www.example.org:443", |
| 8084 | true, |
| 8085 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8086 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8087 | { |
| 8088 | "http_proxy", |
| 8089 | "http://host.with.alternate/direct", |
| 8090 | "ssl/host.with.alternate:443", |
| 8091 | true, |
| 8092 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8093 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8094 | { |
| 8095 | "http_proxy", |
| 8096 | "ftp://ftp.google.com/http_proxy_normal", |
| 8097 | "ftp/ftp.google.com:21", |
| 8098 | false, |
| 8099 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8100 | }; |
| 8101 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8102 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8103 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8104 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8105 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8106 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8107 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8108 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8109 | |
| 8110 | HttpNetworkSessionPeer peer(session); |
| 8111 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8112 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8113 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8114 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8115 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8116 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8117 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8118 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8119 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8120 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8121 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8122 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8123 | |
| 8124 | EXPECT_EQ(ERR_IO_PENDING, |
| 8125 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8126 | if (tests[i].ssl) |
| 8127 | EXPECT_EQ(tests[i].expected_group_name, |
| 8128 | ssl_conn_pool->last_group_name_received()); |
| 8129 | else |
| 8130 | EXPECT_EQ(tests[i].expected_group_name, |
| 8131 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8132 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8133 | } |
| 8134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8135 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8136 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8137 | { |
| 8138 | "socks4://socks_proxy:1080", |
| 8139 | "http://www.example.org/socks4_direct", |
| 8140 | "socks4/www.example.org:80", |
| 8141 | false, |
| 8142 | }, |
| 8143 | { |
| 8144 | "socks5://socks_proxy:1080", |
| 8145 | "http://www.example.org/socks5_direct", |
| 8146 | "socks5/www.example.org:80", |
| 8147 | false, |
| 8148 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8149 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8150 | // SSL Tests |
| 8151 | { |
| 8152 | "socks4://socks_proxy:1080", |
| 8153 | "https://www.example.org/socks4_ssl", |
| 8154 | "socks4/ssl/www.example.org:443", |
| 8155 | true, |
| 8156 | }, |
| 8157 | { |
| 8158 | "socks5://socks_proxy:1080", |
| 8159 | "https://www.example.org/socks5_ssl", |
| 8160 | "socks5/ssl/www.example.org:443", |
| 8161 | true, |
| 8162 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8163 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8164 | { |
| 8165 | "socks4://socks_proxy:1080", |
| 8166 | "http://host.with.alternate/direct", |
| 8167 | "socks4/ssl/host.with.alternate:443", |
| 8168 | true, |
| 8169 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8170 | }; |
| 8171 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8172 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8173 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8174 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8175 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8176 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8177 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8178 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8179 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8180 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8181 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8182 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8183 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8184 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8185 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8186 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8187 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8188 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8189 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8190 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8191 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8192 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8193 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8194 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8196 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8197 | EXPECT_EQ(ERR_IO_PENDING, |
| 8198 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8199 | if (tests[i].ssl) |
| 8200 | EXPECT_EQ(tests[i].expected_group_name, |
| 8201 | ssl_conn_pool->last_group_name_received()); |
| 8202 | else |
| 8203 | EXPECT_EQ(tests[i].expected_group_name, |
| 8204 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8205 | } |
| 8206 | } |
| 8207 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8208 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8209 | HttpRequestInfo request; |
| 8210 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8211 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8212 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8213 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8214 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8215 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8216 | // This simulates failure resolving all hostnames; that means we will fail |
| 8217 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8218 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8219 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8220 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8221 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8222 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8224 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8226 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8227 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8228 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8229 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8230 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8231 | } |
| 8232 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8233 | // Base test to make sure that when the load flags for a request specify to |
| 8234 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8235 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8236 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8237 | // Issue a request, asking to bypass the cache(s). |
| 8238 | HttpRequestInfo request; |
| 8239 | request.method = "GET"; |
| 8240 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8241 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8242 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8243 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8244 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8245 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8246 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8247 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8249 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8250 | // 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] | 8251 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8252 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8253 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8254 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8255 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8257 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8258 | EXPECT_EQ(OK, rv); |
| 8259 | |
| 8260 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8261 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8262 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8263 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8264 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8265 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8266 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8267 | // 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] | 8268 | // we can tell if the next lookup hit the cache, or the "network". |
| 8269 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8270 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8271 | |
| 8272 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8273 | // 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] | 8274 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8275 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8276 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8277 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8278 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8279 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8280 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8281 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8282 | |
| 8283 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8284 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8285 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8286 | } |
| 8287 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8288 | // There are multiple load flags that should trigger the host cache bypass. |
| 8289 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8290 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8291 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8292 | } |
| 8293 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8294 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8295 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8296 | } |
| 8297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8298 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8299 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8300 | } |
| 8301 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8302 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8303 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8304 | HttpRequestInfo request; |
| 8305 | request.method = "GET"; |
| 8306 | request.url = GURL("http://www.foo.com/"); |
| 8307 | request.load_flags = 0; |
| 8308 | |
| 8309 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8310 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8311 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8312 | StaticSocketDataProvider data(NULL, 0, |
| 8313 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8315 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8317 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8318 | |
| 8319 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8320 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8322 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8323 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8324 | |
| 8325 | rv = callback.WaitForResult(); |
| 8326 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8327 | } |
| 8328 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8329 | // Check that a connection closed after the start of the headers finishes ok. |
| 8330 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8331 | HttpRequestInfo request; |
| 8332 | request.method = "GET"; |
| 8333 | request.url = GURL("http://www.foo.com/"); |
| 8334 | request.load_flags = 0; |
| 8335 | |
| 8336 | MockRead data_reads[] = { |
| 8337 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8338 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8339 | }; |
| 8340 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8341 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8342 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8345 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8346 | |
| 8347 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8348 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8350 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8352 | |
| 8353 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8354 | EXPECT_EQ(OK, rv); |
| 8355 | |
| 8356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8357 | ASSERT_TRUE(response != NULL); |
| 8358 | |
| 8359 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8360 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8361 | |
| 8362 | std::string response_data; |
| 8363 | rv = ReadTransaction(trans.get(), &response_data); |
| 8364 | EXPECT_EQ(OK, rv); |
| 8365 | EXPECT_EQ("", response_data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | // Make sure that a dropped connection while draining the body for auth |
| 8369 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8370 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8371 | HttpRequestInfo request; |
| 8372 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8373 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8374 | request.load_flags = 0; |
| 8375 | |
| 8376 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8377 | MockWrite( |
| 8378 | "GET / HTTP/1.1\r\n" |
| 8379 | "Host: www.example.org\r\n" |
| 8380 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8381 | }; |
| 8382 | |
| 8383 | MockRead data_reads1[] = { |
| 8384 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8385 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8386 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8387 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8388 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8389 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8390 | }; |
| 8391 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8392 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8393 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8394 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8395 | |
| 8396 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8397 | // be issuing -- the final header line contains the credentials. |
| 8398 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8399 | MockWrite( |
| 8400 | "GET / HTTP/1.1\r\n" |
| 8401 | "Host: www.example.org\r\n" |
| 8402 | "Connection: keep-alive\r\n" |
| 8403 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8404 | }; |
| 8405 | |
| 8406 | // Lastly, the server responds with the actual content. |
| 8407 | MockRead data_reads2[] = { |
| 8408 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8409 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8410 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8411 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8412 | }; |
| 8413 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8414 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8415 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8416 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8417 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8419 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8420 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8421 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8422 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8424 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8426 | |
| 8427 | rv = callback1.WaitForResult(); |
| 8428 | EXPECT_EQ(OK, rv); |
| 8429 | |
| 8430 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8431 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8432 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8434 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8436 | rv = trans->RestartWithAuth( |
| 8437 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8439 | |
| 8440 | rv = callback2.WaitForResult(); |
| 8441 | EXPECT_EQ(OK, rv); |
| 8442 | |
| 8443 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8444 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8445 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8446 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8447 | } |
| 8448 | |
| 8449 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8450 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8451 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8452 | |
| 8453 | HttpRequestInfo request; |
| 8454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8455 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8456 | request.load_flags = 0; |
| 8457 | |
| 8458 | MockRead proxy_reads[] = { |
| 8459 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8460 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8461 | }; |
| 8462 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8463 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8464 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8465 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8469 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8470 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8471 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8472 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8473 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8474 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8477 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8478 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8479 | |
| 8480 | rv = callback.WaitForResult(); |
| 8481 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8482 | } |
| 8483 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8484 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8485 | HttpRequestInfo request; |
| 8486 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8487 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8488 | request.load_flags = 0; |
| 8489 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8490 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8491 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8492 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8493 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8494 | MockRead data_reads[] = { |
| 8495 | 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] | 8496 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8497 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8498 | |
| 8499 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8502 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8503 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8504 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8505 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8506 | |
| 8507 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8508 | |
| 8509 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8510 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8511 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8512 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8513 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8514 | |
| 8515 | std::string response_data; |
| 8516 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8517 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8518 | } |
| 8519 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8520 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8521 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8522 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8523 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8524 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8525 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8526 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8527 | ScopedVector<UploadElementReader> element_readers; |
| 8528 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8529 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8530 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8531 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8532 | |
| 8533 | HttpRequestInfo request; |
| 8534 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8535 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8536 | request.upload_data_stream = &upload_data_stream; |
| 8537 | request.load_flags = 0; |
| 8538 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8539 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8540 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8541 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8542 | |
| 8543 | MockRead data_reads[] = { |
| 8544 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8545 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8546 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8547 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8548 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8549 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8551 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8553 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8555 | |
| 8556 | rv = callback.WaitForResult(); |
| 8557 | EXPECT_EQ(OK, rv); |
| 8558 | |
| 8559 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8560 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8561 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8562 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8563 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8564 | |
| 8565 | std::string response_data; |
| 8566 | rv = ReadTransaction(trans.get(), &response_data); |
| 8567 | EXPECT_EQ(OK, rv); |
| 8568 | EXPECT_EQ("hello world", response_data); |
| 8569 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8570 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8571 | } |
| 8572 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8573 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8574 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8575 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8576 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8577 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8578 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8579 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8580 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8581 | ScopedVector<UploadElementReader> element_readers; |
| 8582 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8583 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8584 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8585 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8586 | |
| 8587 | HttpRequestInfo request; |
| 8588 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8589 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8590 | request.upload_data_stream = &upload_data_stream; |
| 8591 | request.load_flags = 0; |
| 8592 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8593 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8594 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8595 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8597 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8598 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8599 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8601 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8603 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8605 | |
| 8606 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8607 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8608 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8609 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8610 | } |
| 8611 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8612 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8613 | class FakeUploadElementReader : public UploadElementReader { |
| 8614 | public: |
| 8615 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8616 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8617 | |
| 8618 | const CompletionCallback& callback() const { return callback_; } |
| 8619 | |
| 8620 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8621 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8622 | callback_ = callback; |
| 8623 | return ERR_IO_PENDING; |
| 8624 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8625 | uint64 GetContentLength() const override { return 0; } |
| 8626 | uint64 BytesRemaining() const override { return 0; } |
| 8627 | int Read(IOBuffer* buf, |
| 8628 | int buf_length, |
| 8629 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8630 | return ERR_FAILED; |
| 8631 | } |
| 8632 | |
| 8633 | private: |
| 8634 | CompletionCallback callback_; |
| 8635 | }; |
| 8636 | |
| 8637 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8638 | ScopedVector<UploadElementReader> element_readers; |
| 8639 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8640 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8641 | |
| 8642 | HttpRequestInfo request; |
| 8643 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8644 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8645 | request.upload_data_stream = &upload_data_stream; |
| 8646 | request.load_flags = 0; |
| 8647 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8648 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8649 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8650 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8651 | |
| 8652 | StaticSocketDataProvider data; |
| 8653 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8654 | |
| 8655 | TestCompletionCallback callback; |
| 8656 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8657 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8658 | base::MessageLoop::current()->RunUntilIdle(); |
| 8659 | |
| 8660 | // Transaction is pending on request body initialization. |
| 8661 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8662 | |
| 8663 | // Return Init()'s result after the transaction gets destroyed. |
| 8664 | trans.reset(); |
| 8665 | fake_reader->callback().Run(OK); // Should not crash. |
| 8666 | } |
| 8667 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8668 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8669 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8670 | HttpRequestInfo request; |
| 8671 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8672 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8673 | request.load_flags = 0; |
| 8674 | |
| 8675 | // First transaction will request a resource and receive a Basic challenge |
| 8676 | // with realm="first_realm". |
| 8677 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8678 | MockWrite( |
| 8679 | "GET / HTTP/1.1\r\n" |
| 8680 | "Host: www.example.org\r\n" |
| 8681 | "Connection: keep-alive\r\n" |
| 8682 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8683 | }; |
| 8684 | MockRead data_reads1[] = { |
| 8685 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8686 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8687 | "\r\n"), |
| 8688 | }; |
| 8689 | |
| 8690 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8691 | // for first_realm. The server will reject and provide a challenge with |
| 8692 | // second_realm. |
| 8693 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8694 | MockWrite( |
| 8695 | "GET / HTTP/1.1\r\n" |
| 8696 | "Host: www.example.org\r\n" |
| 8697 | "Connection: keep-alive\r\n" |
| 8698 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8699 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8700 | }; |
| 8701 | MockRead data_reads2[] = { |
| 8702 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8703 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8704 | "\r\n"), |
| 8705 | }; |
| 8706 | |
| 8707 | // This again fails, and goes back to first_realm. Make sure that the |
| 8708 | // entry is removed from cache. |
| 8709 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8710 | MockWrite( |
| 8711 | "GET / HTTP/1.1\r\n" |
| 8712 | "Host: www.example.org\r\n" |
| 8713 | "Connection: keep-alive\r\n" |
| 8714 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8715 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8716 | }; |
| 8717 | MockRead data_reads3[] = { |
| 8718 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8719 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8720 | "\r\n"), |
| 8721 | }; |
| 8722 | |
| 8723 | // Try one last time (with the correct password) and get the resource. |
| 8724 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8725 | MockWrite( |
| 8726 | "GET / HTTP/1.1\r\n" |
| 8727 | "Host: www.example.org\r\n" |
| 8728 | "Connection: keep-alive\r\n" |
| 8729 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8730 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8731 | }; |
| 8732 | MockRead data_reads4[] = { |
| 8733 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8734 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8735 | "Content-Length: 5\r\n" |
| 8736 | "\r\n" |
| 8737 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8738 | }; |
| 8739 | |
| 8740 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8741 | data_writes1, arraysize(data_writes1)); |
| 8742 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8743 | data_writes2, arraysize(data_writes2)); |
| 8744 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8745 | data_writes3, arraysize(data_writes3)); |
| 8746 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8747 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8748 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8749 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8750 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8751 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8753 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8754 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8755 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8756 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8757 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8758 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8759 | // Issue the first request with Authorize headers. There should be a |
| 8760 | // password prompt for first_realm waiting to be filled in after the |
| 8761 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8762 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8763 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8764 | rv = callback1.WaitForResult(); |
| 8765 | EXPECT_EQ(OK, rv); |
| 8766 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8767 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8768 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8769 | ASSERT_FALSE(challenge == NULL); |
| 8770 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8771 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8772 | EXPECT_EQ("first_realm", challenge->realm); |
| 8773 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8774 | |
| 8775 | // Issue the second request with an incorrect password. There should be a |
| 8776 | // password prompt for second_realm waiting to be filled in after the |
| 8777 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8778 | TestCompletionCallback callback2; |
| 8779 | rv = trans->RestartWithAuth( |
| 8780 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8781 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8782 | rv = callback2.WaitForResult(); |
| 8783 | EXPECT_EQ(OK, rv); |
| 8784 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8785 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8786 | challenge = response->auth_challenge.get(); |
| 8787 | ASSERT_FALSE(challenge == NULL); |
| 8788 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8789 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8790 | EXPECT_EQ("second_realm", challenge->realm); |
| 8791 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8792 | |
| 8793 | // Issue the third request with another incorrect password. There should be |
| 8794 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8795 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8796 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8797 | TestCompletionCallback callback3; |
| 8798 | rv = trans->RestartWithAuth( |
| 8799 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8801 | rv = callback3.WaitForResult(); |
| 8802 | EXPECT_EQ(OK, rv); |
| 8803 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8804 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8805 | challenge = response->auth_challenge.get(); |
| 8806 | ASSERT_FALSE(challenge == NULL); |
| 8807 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8808 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8809 | EXPECT_EQ("first_realm", challenge->realm); |
| 8810 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8811 | |
| 8812 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8813 | TestCompletionCallback callback4; |
| 8814 | rv = trans->RestartWithAuth( |
| 8815 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8816 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8817 | rv = callback4.WaitForResult(); |
| 8818 | EXPECT_EQ(OK, rv); |
| 8819 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8820 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8821 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8822 | } |
| 8823 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8824 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 8825 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8826 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8827 | |
| 8828 | std::string alternative_service_http_header = |
| 8829 | GetAlternativeServiceHttpHeader(); |
| 8830 | |
| 8831 | MockRead data_reads[] = { |
| 8832 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8833 | MockRead(alternative_service_http_header.c_str()), |
| 8834 | MockRead("\r\n"), |
| 8835 | MockRead("hello world"), |
| 8836 | MockRead(SYNCHRONOUS, OK), |
| 8837 | }; |
| 8838 | |
| 8839 | HttpRequestInfo request; |
| 8840 | request.method = "GET"; |
| 8841 | request.url = GURL("http://www.example.org/"); |
| 8842 | request.load_flags = 0; |
| 8843 | |
| 8844 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8845 | |
| 8846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8847 | |
| 8848 | TestCompletionCallback callback; |
| 8849 | |
| 8850 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8851 | scoped_ptr<HttpTransaction> trans( |
| 8852 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8853 | |
| 8854 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8856 | |
| 8857 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8858 | HttpServerProperties& http_server_properties = |
| 8859 | *session->http_server_properties(); |
| 8860 | AlternativeServiceVector alternative_service_vector = |
| 8861 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8862 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8863 | |
| 8864 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8865 | |
| 8866 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8867 | ASSERT_TRUE(response != NULL); |
| 8868 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8869 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8870 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8871 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8872 | |
| 8873 | std::string response_data; |
| 8874 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8875 | EXPECT_EQ("hello world", response_data); |
| 8876 | |
| 8877 | alternative_service_vector = |
| 8878 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8879 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8880 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8881 | alternative_service_vector[0].protocol); |
| 8882 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8883 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8884 | } |
| 8885 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8886 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 8887 | // is false. |
| 8888 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 8889 | session_deps_.next_protos = SpdyNextProtos(); |
| 8890 | session_deps_.use_alternative_services = false; |
| 8891 | |
| 8892 | std::string alternative_service_http_header = |
| 8893 | GetAlternativeServiceHttpHeader(); |
| 8894 | |
| 8895 | MockRead data_reads[] = { |
| 8896 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8897 | MockRead(alternative_service_http_header.c_str()), |
| 8898 | MockRead("\r\n"), |
| 8899 | MockRead("hello world"), |
| 8900 | MockRead(SYNCHRONOUS, OK), |
| 8901 | }; |
| 8902 | |
| 8903 | HttpRequestInfo request; |
| 8904 | request.method = "GET"; |
| 8905 | request.url = GURL("http://www.example.org/"); |
| 8906 | request.load_flags = 0; |
| 8907 | |
| 8908 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 8909 | |
| 8910 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8911 | |
| 8912 | TestCompletionCallback callback; |
| 8913 | |
| 8914 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8915 | scoped_ptr<HttpTransaction> trans( |
| 8916 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8917 | |
| 8918 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8920 | |
| 8921 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8922 | HttpServerProperties& http_server_properties = |
| 8923 | *session->http_server_properties(); |
| 8924 | AlternativeServiceVector alternative_service_vector = |
| 8925 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8926 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8927 | |
| 8928 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8929 | |
| 8930 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8931 | ASSERT_TRUE(response != nullptr); |
| 8932 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 8933 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8934 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8935 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8936 | |
| 8937 | std::string response_data; |
| 8938 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8939 | EXPECT_EQ("hello world", response_data); |
| 8940 | |
| 8941 | alternative_service_vector = |
| 8942 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8943 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8944 | } |
| 8945 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8946 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 8947 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8948 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8949 | |
| 8950 | MockRead data_reads[] = { |
| 8951 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8952 | MockRead("Alt-Svc: "), |
| 8953 | MockRead(GetAlternateProtocolFromParam()), |
| 8954 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 8955 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 8956 | MockRead("hello world"), |
| 8957 | MockRead(SYNCHRONOUS, OK), |
| 8958 | }; |
| 8959 | |
| 8960 | HttpRequestInfo request; |
| 8961 | request.method = "GET"; |
| 8962 | request.url = GURL("http://www.example.org/"); |
| 8963 | request.load_flags = 0; |
| 8964 | |
| 8965 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8966 | |
| 8967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8968 | |
| 8969 | TestCompletionCallback callback; |
| 8970 | |
| 8971 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8972 | scoped_ptr<HttpTransaction> trans( |
| 8973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8974 | |
| 8975 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8977 | |
| 8978 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8979 | HttpServerProperties& http_server_properties = |
| 8980 | *session->http_server_properties(); |
| 8981 | AlternativeServiceVector alternative_service_vector = |
| 8982 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8983 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8984 | |
| 8985 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8986 | |
| 8987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8988 | ASSERT_TRUE(response != NULL); |
| 8989 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8990 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8991 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8992 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8993 | |
| 8994 | std::string response_data; |
| 8995 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8996 | EXPECT_EQ("hello world", response_data); |
| 8997 | |
| 8998 | alternative_service_vector = |
| 8999 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9000 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 9001 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9002 | alternative_service_vector[0].protocol); |
| 9003 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9004 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9005 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9006 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9007 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9008 | } |
| 9009 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9010 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9011 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9012 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9013 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9014 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9015 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9016 | std::string alternate_protocol_http_header = |
| 9017 | GetAlternateProtocolHttpHeader(); |
| 9018 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9019 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9021 | MockRead(alternate_protocol_http_header.c_str()), |
| 9022 | MockRead("\r\n"), |
| 9023 | MockRead("hello world"), |
| 9024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9025 | }; |
| 9026 | |
| 9027 | HttpRequestInfo request; |
| 9028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9029 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9030 | request.load_flags = 0; |
| 9031 | |
| 9032 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9033 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9034 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9035 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9036 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9037 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9038 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9039 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9040 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9044 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9045 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9046 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9047 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9048 | AlternativeServiceVector alternative_service_vector = |
| 9049 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9050 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9051 | |
| 9052 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9053 | |
| 9054 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9055 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9056 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9057 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9058 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9059 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9060 | |
| 9061 | std::string response_data; |
| 9062 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9063 | EXPECT_EQ("hello world", response_data); |
| 9064 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9065 | alternative_service_vector = |
| 9066 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9067 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9068 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9069 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9070 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9071 | } |
| 9072 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9073 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9074 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9075 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9076 | |
| 9077 | MockRead data_reads[] = { |
| 9078 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9079 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9080 | MockRead("hello world"), |
| 9081 | MockRead(SYNCHRONOUS, OK), |
| 9082 | }; |
| 9083 | |
| 9084 | HttpRequestInfo request; |
| 9085 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9086 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9087 | request.load_flags = 0; |
| 9088 | |
| 9089 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9090 | |
| 9091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9092 | |
| 9093 | TestCompletionCallback callback; |
| 9094 | |
| 9095 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9096 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9097 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9098 | HttpServerProperties& http_server_properties = |
| 9099 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9100 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9101 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9102 | http_server_properties.SetAlternativeService( |
| 9103 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9104 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9105 | AlternativeServiceVector alternative_service_vector = |
| 9106 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9107 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9108 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9109 | |
| 9110 | scoped_ptr<HttpTransaction> trans( |
| 9111 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9112 | |
| 9113 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9114 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9115 | |
| 9116 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9117 | |
| 9118 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9119 | ASSERT_TRUE(response != NULL); |
| 9120 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9121 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9122 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9123 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9124 | |
| 9125 | std::string response_data; |
| 9126 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9127 | EXPECT_EQ("hello world", response_data); |
| 9128 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9129 | alternative_service_vector = |
| 9130 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9131 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9132 | } |
| 9133 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9134 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9135 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9136 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9137 | |
| 9138 | std::string alternative_service_http_header = |
| 9139 | GetAlternativeServiceHttpHeader(); |
| 9140 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9141 | |
| 9142 | MockRead data_reads[] = { |
| 9143 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9144 | MockRead(alternative_service_http_header.c_str()), |
| 9145 | MockRead(alternate_protocol_http_header.c_str()), |
| 9146 | MockRead("\r\n"), |
| 9147 | MockRead("hello world"), |
| 9148 | MockRead(SYNCHRONOUS, OK), |
| 9149 | }; |
| 9150 | |
| 9151 | HttpRequestInfo request; |
| 9152 | request.method = "GET"; |
| 9153 | request.url = GURL("http://www.example.org/"); |
| 9154 | request.load_flags = 0; |
| 9155 | |
| 9156 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9157 | |
| 9158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9159 | |
| 9160 | TestCompletionCallback callback; |
| 9161 | |
| 9162 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9163 | scoped_ptr<HttpTransaction> trans( |
| 9164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9165 | |
| 9166 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9167 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9168 | |
| 9169 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9170 | HttpServerProperties& http_server_properties = |
| 9171 | *session->http_server_properties(); |
| 9172 | AlternativeServiceVector alternative_service_vector = |
| 9173 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9174 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9175 | |
| 9176 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9177 | |
| 9178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9179 | ASSERT_TRUE(response != NULL); |
| 9180 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9181 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9182 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9183 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9184 | |
| 9185 | std::string response_data; |
| 9186 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9187 | EXPECT_EQ("hello world", response_data); |
| 9188 | |
| 9189 | alternative_service_vector = |
| 9190 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9191 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9192 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9193 | alternative_service_vector[0].protocol); |
| 9194 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9195 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9196 | } |
| 9197 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9198 | // When |use_alternative_services| is false, do not observe alternative service |
| 9199 | // entries that point to a different host. |
| 9200 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9201 | session_deps_.use_alternative_services = false; |
| 9202 | |
| 9203 | HttpRequestInfo request; |
| 9204 | request.method = "GET"; |
| 9205 | request.url = GURL("http://www.example.org/"); |
| 9206 | request.load_flags = 0; |
| 9207 | |
| 9208 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9209 | StaticSocketDataProvider first_data; |
| 9210 | first_data.set_connect_data(mock_connect); |
| 9211 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9212 | |
| 9213 | MockRead data_reads[] = { |
| 9214 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9215 | MockRead(ASYNC, OK), |
| 9216 | }; |
| 9217 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9218 | nullptr, 0); |
| 9219 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9220 | |
| 9221 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9222 | |
| 9223 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9224 | session->http_server_properties(); |
| 9225 | AlternativeService alternative_service( |
| 9226 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9227 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9228 | http_server_properties->SetAlternativeService( |
| 9229 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9230 | |
| 9231 | scoped_ptr<HttpTransaction> trans( |
| 9232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9233 | TestCompletionCallback callback; |
| 9234 | |
| 9235 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9236 | // The connetion to origin was refused, and the alternative service should not |
| 9237 | // be used (even though mock data are there), therefore the request should |
| 9238 | // fail. |
| 9239 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9240 | } |
| 9241 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9242 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9243 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9244 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9245 | |
| 9246 | HttpRequestInfo request; |
| 9247 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9248 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9249 | request.load_flags = 0; |
| 9250 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9251 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9252 | StaticSocketDataProvider first_data; |
| 9253 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9254 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9255 | |
| 9256 | MockRead data_reads[] = { |
| 9257 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9258 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9259 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9260 | }; |
| 9261 | StaticSocketDataProvider second_data( |
| 9262 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9263 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9264 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9266 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9267 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9268 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9269 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9270 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9271 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9272 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9273 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9274 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9275 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9276 | http_server_properties->SetAlternativeService( |
| 9277 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9278 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9279 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9281 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9283 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9284 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9285 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9286 | |
| 9287 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9288 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9289 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9290 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9291 | |
| 9292 | std::string response_data; |
| 9293 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9294 | EXPECT_EQ("hello world", response_data); |
| 9295 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9296 | const AlternativeServiceVector alternative_service_vector = |
| 9297 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9298 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9299 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9300 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9301 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9302 | } |
| 9303 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9304 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9305 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9306 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9307 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9308 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9309 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9310 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9311 | |
| 9312 | HttpRequestInfo restricted_port_request; |
| 9313 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9314 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9315 | restricted_port_request.load_flags = 0; |
| 9316 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9317 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9318 | StaticSocketDataProvider first_data; |
| 9319 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9320 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9321 | |
| 9322 | MockRead data_reads[] = { |
| 9323 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9324 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9325 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9326 | }; |
| 9327 | StaticSocketDataProvider second_data( |
| 9328 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9329 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9330 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9332 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9333 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9334 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9335 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9336 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9337 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9338 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9339 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9340 | http_server_properties->SetAlternativeService( |
| 9341 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9342 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9343 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9344 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9348 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9349 | &restricted_port_request, |
| 9350 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9352 | // Invalid change to unrestricted port should fail. |
| 9353 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9354 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9355 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9356 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9357 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9358 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9359 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9360 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9361 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9362 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9363 | |
| 9364 | HttpRequestInfo restricted_port_request; |
| 9365 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9366 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9367 | restricted_port_request.load_flags = 0; |
| 9368 | |
| 9369 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9370 | StaticSocketDataProvider first_data; |
| 9371 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9372 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9373 | |
| 9374 | MockRead data_reads[] = { |
| 9375 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9376 | MockRead("hello world"), |
| 9377 | MockRead(ASYNC, OK), |
| 9378 | }; |
| 9379 | StaticSocketDataProvider second_data( |
| 9380 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9381 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9382 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9383 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9384 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9385 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9386 | session->http_server_properties(); |
| 9387 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9388 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9389 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9390 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9391 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9392 | http_server_properties->SetAlternativeService( |
| 9393 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9394 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9395 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9396 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9397 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9398 | TestCompletionCallback callback; |
| 9399 | |
| 9400 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9401 | &restricted_port_request, |
| 9402 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9403 | // Change to unrestricted port should succeed. |
| 9404 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9405 | } |
| 9406 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9407 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9408 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9409 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9410 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9411 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9412 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9413 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9414 | |
| 9415 | HttpRequestInfo restricted_port_request; |
| 9416 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9417 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9418 | restricted_port_request.load_flags = 0; |
| 9419 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9420 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9421 | StaticSocketDataProvider first_data; |
| 9422 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9423 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9424 | |
| 9425 | MockRead data_reads[] = { |
| 9426 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9427 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9428 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9429 | }; |
| 9430 | StaticSocketDataProvider second_data( |
| 9431 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9432 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9433 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9434 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9435 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9436 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9437 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9438 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9439 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9440 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9441 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9442 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9443 | http_server_properties->SetAlternativeService( |
| 9444 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9445 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9446 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9447 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9448 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9449 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9451 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9452 | &restricted_port_request, |
| 9453 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9454 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9455 | // Valid change to restricted port should pass. |
| 9456 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9457 | } |
| 9458 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9459 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9460 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9461 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9462 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9463 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9464 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9465 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9466 | |
| 9467 | HttpRequestInfo unrestricted_port_request; |
| 9468 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9469 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9470 | unrestricted_port_request.load_flags = 0; |
| 9471 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9472 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9473 | StaticSocketDataProvider first_data; |
| 9474 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9475 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9476 | |
| 9477 | MockRead data_reads[] = { |
| 9478 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9479 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9480 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9481 | }; |
| 9482 | StaticSocketDataProvider second_data( |
| 9483 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9484 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9485 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9486 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9487 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9488 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9489 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9490 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9491 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9492 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9493 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9494 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9495 | http_server_properties->SetAlternativeService( |
| 9496 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9497 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9498 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9499 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9501 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9503 | int rv = trans->Start( |
| 9504 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9505 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9506 | // Valid change to restricted port should pass. |
| 9507 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9508 | } |
| 9509 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9510 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9511 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9512 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9513 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9514 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9515 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9516 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9517 | |
| 9518 | HttpRequestInfo unrestricted_port_request; |
| 9519 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9520 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9521 | unrestricted_port_request.load_flags = 0; |
| 9522 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9523 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9524 | StaticSocketDataProvider first_data; |
| 9525 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9526 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9527 | |
| 9528 | MockRead data_reads[] = { |
| 9529 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9530 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9531 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9532 | }; |
| 9533 | StaticSocketDataProvider second_data( |
| 9534 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9535 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9536 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9537 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9538 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9539 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9540 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 9541 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9542 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9543 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9544 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9545 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9546 | http_server_properties->SetAlternativeService( |
| 9547 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9548 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9549 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9550 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9551 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9552 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9554 | int rv = trans->Start( |
| 9555 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9556 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9557 | // Valid change to an unrestricted port should pass. |
| 9558 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9559 | } |
| 9560 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9561 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9562 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 9563 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9564 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9565 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9566 | |
| 9567 | HttpRequestInfo request; |
| 9568 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9569 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9570 | request.load_flags = 0; |
| 9571 | |
| 9572 | // The alternate protocol request will error out before we attempt to connect, |
| 9573 | // so only the standard HTTP request will try to connect. |
| 9574 | MockRead data_reads[] = { |
| 9575 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9576 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9577 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9578 | }; |
| 9579 | StaticSocketDataProvider data( |
| 9580 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9581 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9582 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9583 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9584 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9585 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9586 | session->http_server_properties(); |
| 9587 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9588 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9589 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9590 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9591 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9592 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9593 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9594 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9595 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9597 | TestCompletionCallback callback; |
| 9598 | |
| 9599 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9601 | // The HTTP request should succeed. |
| 9602 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9603 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9605 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9606 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9607 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9608 | |
| 9609 | std::string response_data; |
| 9610 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9611 | EXPECT_EQ("hello world", response_data); |
| 9612 | } |
| 9613 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9614 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9615 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9616 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9617 | |
| 9618 | HttpRequestInfo request; |
| 9619 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9620 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9621 | request.load_flags = 0; |
| 9622 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9623 | std::string alternate_protocol_http_header = |
| 9624 | GetAlternateProtocolHttpHeader(); |
| 9625 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9626 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9627 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9628 | MockRead(alternate_protocol_http_header.c_str()), |
| 9629 | MockRead("\r\n"), |
| 9630 | MockRead("hello world"), |
| 9631 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9632 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9633 | |
| 9634 | StaticSocketDataProvider first_transaction( |
| 9635 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9636 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9637 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9638 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9639 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9640 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9641 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9642 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9643 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9644 | scoped_ptr<SpdyFrame> req( |
| 9645 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9646 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9647 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9648 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9649 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9650 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9651 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9652 | }; |
| 9653 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9654 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9655 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9656 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9657 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9658 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9659 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9660 | NULL, 0, NULL, 0); |
| 9661 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9662 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9663 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9664 | &hanging_non_alternate_protocol_socket); |
| 9665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9666 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9667 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9668 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9669 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9672 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9673 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9674 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9675 | |
| 9676 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9677 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9678 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9679 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9680 | |
| 9681 | std::string response_data; |
| 9682 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9683 | EXPECT_EQ("hello world", response_data); |
| 9684 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9685 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9687 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9688 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9689 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9690 | |
| 9691 | response = trans->GetResponseInfo(); |
| 9692 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9693 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9694 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9695 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9696 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9697 | |
| 9698 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9699 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9700 | } |
| 9701 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9702 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9703 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9704 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9705 | |
| 9706 | HttpRequestInfo request; |
| 9707 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9708 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9709 | request.load_flags = 0; |
| 9710 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9711 | std::string alternate_protocol_http_header = |
| 9712 | GetAlternateProtocolHttpHeader(); |
| 9713 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9714 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9715 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9716 | MockRead(alternate_protocol_http_header.c_str()), |
| 9717 | MockRead("\r\n"), |
| 9718 | MockRead("hello world"), |
| 9719 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9720 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9721 | }; |
| 9722 | |
| 9723 | StaticSocketDataProvider first_transaction( |
| 9724 | data_reads, arraysize(data_reads), NULL, 0); |
| 9725 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9726 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9727 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9728 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9729 | StaticSocketDataProvider hanging_socket( |
| 9730 | NULL, 0, NULL, 0); |
| 9731 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9732 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9733 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9734 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9735 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9736 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9737 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9738 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9739 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9740 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9741 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9742 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9743 | scoped_ptr<SpdyFrame> req1( |
| 9744 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9745 | scoped_ptr<SpdyFrame> req2( |
| 9746 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9747 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9748 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9749 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9750 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9751 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9752 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9753 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9754 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9755 | CreateMockRead(*resp1, 2), |
| 9756 | CreateMockRead(*data1, 3), |
| 9757 | CreateMockRead(*resp2, 4), |
| 9758 | CreateMockRead(*data2, 5), |
| 9759 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9760 | }; |
| 9761 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9762 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9763 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9764 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9765 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9766 | |
| 9767 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9768 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9769 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9770 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9771 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9772 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9775 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9776 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9777 | |
| 9778 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9779 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9780 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9781 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9782 | |
| 9783 | std::string response_data; |
| 9784 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9785 | EXPECT_EQ("hello world", response_data); |
| 9786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9787 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9788 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9789 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9790 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9792 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9793 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9794 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9795 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9796 | |
| 9797 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9798 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9799 | |
| 9800 | response = trans2.GetResponseInfo(); |
| 9801 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9802 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9803 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9804 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9805 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9806 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9807 | EXPECT_EQ("hello!", response_data); |
| 9808 | |
| 9809 | response = trans3.GetResponseInfo(); |
| 9810 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9811 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9812 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9813 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9814 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9815 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9816 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9817 | } |
| 9818 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9819 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9820 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9821 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9822 | |
| 9823 | HttpRequestInfo request; |
| 9824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9825 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9826 | request.load_flags = 0; |
| 9827 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9828 | std::string alternate_protocol_http_header = |
| 9829 | GetAlternateProtocolHttpHeader(); |
| 9830 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9831 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9832 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9833 | MockRead(alternate_protocol_http_header.c_str()), |
| 9834 | MockRead("\r\n"), |
| 9835 | MockRead("hello world"), |
| 9836 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9837 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9838 | }; |
| 9839 | |
| 9840 | StaticSocketDataProvider first_transaction( |
| 9841 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9842 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9843 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9844 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9845 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9847 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9848 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9849 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9850 | NULL, 0, NULL, 0); |
| 9851 | hanging_alternate_protocol_socket.set_connect_data( |
| 9852 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9853 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9854 | &hanging_alternate_protocol_socket); |
| 9855 | |
| 9856 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9857 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9859 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9860 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9861 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9862 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9863 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9865 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9866 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9867 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9868 | |
| 9869 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9870 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9871 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9872 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9873 | |
| 9874 | std::string response_data; |
| 9875 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9876 | EXPECT_EQ("hello world", response_data); |
| 9877 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9878 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9880 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9881 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9882 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9883 | |
| 9884 | response = trans->GetResponseInfo(); |
| 9885 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9886 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9887 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9888 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9889 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9890 | |
| 9891 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9892 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9893 | } |
| 9894 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9895 | class CapturingProxyResolver : public ProxyResolver { |
| 9896 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9897 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9898 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9899 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9900 | int GetProxyForURL(const GURL& url, |
| 9901 | ProxyInfo* results, |
| 9902 | const CompletionCallback& callback, |
| 9903 | RequestHandle* request, |
| 9904 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9905 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9906 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9907 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9908 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9909 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9910 | } |
| 9911 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9912 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9913 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9914 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9915 | NOTREACHED(); |
| 9916 | return LOAD_STATE_IDLE; |
| 9917 | } |
| 9918 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9919 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9920 | |
| 9921 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9922 | std::vector<GURL> resolved_; |
| 9923 | |
| 9924 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9925 | }; |
| 9926 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9927 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9928 | public: |
| 9929 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9930 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9931 | |
| 9932 | int CreateProxyResolver( |
| 9933 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9934 | scoped_ptr<ProxyResolver>* resolver, |
| 9935 | const net::CompletionCallback& callback, |
| 9936 | scoped_ptr<Request>* request) override { |
| 9937 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9938 | return OK; |
| 9939 | } |
| 9940 | |
| 9941 | private: |
| 9942 | ProxyResolver* resolver_; |
| 9943 | }; |
| 9944 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9945 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9946 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9947 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9948 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9949 | |
| 9950 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9951 | proxy_config.set_auto_detect(true); |
| 9952 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9953 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9954 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9955 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9956 | new ProxyConfigServiceFixed(proxy_config), |
| 9957 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9958 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9959 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9960 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9961 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9962 | |
| 9963 | HttpRequestInfo request; |
| 9964 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9965 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9966 | request.load_flags = 0; |
| 9967 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9968 | std::string alternate_protocol_http_header = |
| 9969 | GetAlternateProtocolHttpHeader(); |
| 9970 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9971 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9972 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9973 | MockRead(alternate_protocol_http_header.c_str()), |
| 9974 | MockRead("\r\n"), |
| 9975 | MockRead("hello world"), |
| 9976 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9977 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9978 | }; |
| 9979 | |
| 9980 | StaticSocketDataProvider first_transaction( |
| 9981 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9982 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9983 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9984 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9985 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9986 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9987 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9989 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9990 | scoped_ptr<SpdyFrame> req( |
| 9991 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9992 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9993 | MockWrite(ASYNC, 0, |
| 9994 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9995 | "Host: www.example.org\r\n" |
| 9996 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9997 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9998 | }; |
| 9999 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10000 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10001 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10002 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10003 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10004 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10005 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10006 | CreateMockRead(*resp.get(), 3), |
| 10007 | CreateMockRead(*data.get(), 4), |
| 10008 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10009 | }; |
| 10010 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10011 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10012 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10013 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10014 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10015 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10016 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10017 | NULL, 0, NULL, 0); |
| 10018 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10019 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10020 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10021 | &hanging_non_alternate_protocol_socket); |
| 10022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10023 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10024 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10025 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10026 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10027 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10029 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10030 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10031 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10032 | |
| 10033 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10034 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10035 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10036 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10037 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10038 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10039 | |
| 10040 | std::string response_data; |
| 10041 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10042 | EXPECT_EQ("hello world", response_data); |
| 10043 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10044 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10046 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10048 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10049 | |
| 10050 | response = trans->GetResponseInfo(); |
| 10051 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10052 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10053 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10054 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10055 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10056 | |
| 10057 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10058 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10059 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10060 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10061 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10062 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10063 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10064 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10065 | LoadTimingInfo load_timing_info; |
| 10066 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10067 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10068 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10069 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10070 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10071 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10072 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10073 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10074 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10075 | |
| 10076 | HttpRequestInfo request; |
| 10077 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10078 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10079 | request.load_flags = 0; |
| 10080 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10081 | std::string alternate_protocol_http_header = |
| 10082 | GetAlternateProtocolHttpHeader(); |
| 10083 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10084 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10085 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10086 | MockRead(alternate_protocol_http_header.c_str()), |
| 10087 | MockRead("\r\n"), |
| 10088 | MockRead("hello world"), |
| 10089 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10090 | }; |
| 10091 | |
| 10092 | StaticSocketDataProvider first_transaction( |
| 10093 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10094 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10095 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10096 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10097 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10098 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10099 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10101 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10102 | scoped_ptr<SpdyFrame> req( |
| 10103 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10104 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10105 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10106 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10107 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10108 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10109 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10110 | }; |
| 10111 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10112 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10113 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10114 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10115 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10116 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10117 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10118 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10119 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10120 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10123 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10125 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10126 | |
| 10127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10128 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10129 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10130 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10131 | |
| 10132 | std::string response_data; |
| 10133 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10134 | EXPECT_EQ("hello world", response_data); |
| 10135 | |
| 10136 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10137 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10138 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10139 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10140 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10141 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10142 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10143 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10145 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10147 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10148 | |
| 10149 | response = trans->GetResponseInfo(); |
| 10150 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10151 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10152 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10153 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10154 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10155 | |
| 10156 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10157 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10158 | } |
| 10159 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10160 | // GenerateAuthToken is a mighty big test. |
| 10161 | // It tests all permutation of GenerateAuthToken behavior: |
| 10162 | // - Synchronous and Asynchronous completion. |
| 10163 | // - OK or error on completion. |
| 10164 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10165 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10166 | // - Non-authenticating and authenticating backend. |
| 10167 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10168 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10169 | // problems generating an auth token for an authenticating proxy, we don't |
| 10170 | // need to test all permutations of the backend server). |
| 10171 | // |
| 10172 | // The test proceeds by going over each of the configuration cases, and |
| 10173 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10174 | // specifies both the configuration for the test as well as the expectations |
| 10175 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10176 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10177 | static const char kServer[] = "http://www.example.com"; |
| 10178 | static const char kSecureServer[] = "https://www.example.com"; |
| 10179 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10180 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10181 | |
| 10182 | enum AuthTiming { |
| 10183 | AUTH_NONE, |
| 10184 | AUTH_SYNC, |
| 10185 | AUTH_ASYNC, |
| 10186 | }; |
| 10187 | |
| 10188 | const MockWrite kGet( |
| 10189 | "GET / HTTP/1.1\r\n" |
| 10190 | "Host: www.example.com\r\n" |
| 10191 | "Connection: keep-alive\r\n\r\n"); |
| 10192 | const MockWrite kGetProxy( |
| 10193 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10194 | "Host: www.example.com\r\n" |
| 10195 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10196 | const MockWrite kGetAuth( |
| 10197 | "GET / HTTP/1.1\r\n" |
| 10198 | "Host: www.example.com\r\n" |
| 10199 | "Connection: keep-alive\r\n" |
| 10200 | "Authorization: auth_token\r\n\r\n"); |
| 10201 | const MockWrite kGetProxyAuth( |
| 10202 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10203 | "Host: www.example.com\r\n" |
| 10204 | "Proxy-Connection: keep-alive\r\n" |
| 10205 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10206 | const MockWrite kGetAuthThroughProxy( |
| 10207 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10208 | "Host: www.example.com\r\n" |
| 10209 | "Proxy-Connection: keep-alive\r\n" |
| 10210 | "Authorization: auth_token\r\n\r\n"); |
| 10211 | const MockWrite kGetAuthWithProxyAuth( |
| 10212 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10213 | "Host: www.example.com\r\n" |
| 10214 | "Proxy-Connection: keep-alive\r\n" |
| 10215 | "Proxy-Authorization: auth_token\r\n" |
| 10216 | "Authorization: auth_token\r\n\r\n"); |
| 10217 | const MockWrite kConnect( |
| 10218 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10219 | "Host: www.example.com\r\n" |
| 10220 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10221 | const MockWrite kConnectProxyAuth( |
| 10222 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10223 | "Host: www.example.com\r\n" |
| 10224 | "Proxy-Connection: keep-alive\r\n" |
| 10225 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10226 | |
| 10227 | const MockRead kSuccess( |
| 10228 | "HTTP/1.1 200 OK\r\n" |
| 10229 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10230 | "Content-Length: 3\r\n\r\n" |
| 10231 | "Yes"); |
| 10232 | const MockRead kFailure( |
| 10233 | "Should not be called."); |
| 10234 | const MockRead kServerChallenge( |
| 10235 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10236 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10237 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10238 | "Content-Length: 14\r\n\r\n" |
| 10239 | "Unauthorized\r\n"); |
| 10240 | const MockRead kProxyChallenge( |
| 10241 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10242 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10243 | "Proxy-Connection: close\r\n" |
| 10244 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10245 | "Content-Length: 14\r\n\r\n" |
| 10246 | "Unauthorized\r\n"); |
| 10247 | const MockRead kProxyConnected( |
| 10248 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10249 | |
| 10250 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10251 | // no constructors, but the C++ compiler on Windows warns about |
| 10252 | // unspecified data in compound literals. So, moved to using constructors, |
| 10253 | // and TestRound's created with the default constructor should not be used. |
| 10254 | struct TestRound { |
| 10255 | TestRound() |
| 10256 | : expected_rv(ERR_UNEXPECTED), |
| 10257 | extra_write(NULL), |
| 10258 | extra_read(NULL) { |
| 10259 | } |
| 10260 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10261 | int expected_rv_arg) |
| 10262 | : write(write_arg), |
| 10263 | read(read_arg), |
| 10264 | expected_rv(expected_rv_arg), |
| 10265 | extra_write(NULL), |
| 10266 | extra_read(NULL) { |
| 10267 | } |
| 10268 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10269 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10270 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10271 | : write(write_arg), |
| 10272 | read(read_arg), |
| 10273 | expected_rv(expected_rv_arg), |
| 10274 | extra_write(extra_write_arg), |
| 10275 | extra_read(extra_read_arg) { |
| 10276 | } |
| 10277 | MockWrite write; |
| 10278 | MockRead read; |
| 10279 | int expected_rv; |
| 10280 | const MockWrite* extra_write; |
| 10281 | const MockRead* extra_read; |
| 10282 | }; |
| 10283 | |
| 10284 | static const int kNoSSL = 500; |
| 10285 | |
| 10286 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10287 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10288 | AuthTiming proxy_auth_timing; |
| 10289 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10290 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10291 | AuthTiming server_auth_timing; |
| 10292 | int server_auth_rv; |
| 10293 | int num_auth_rounds; |
| 10294 | int first_ssl_round; |
| 10295 | TestRound rounds[3]; |
| 10296 | } test_configs[] = { |
| 10297 | // Non-authenticating HTTP server with a direct connection. |
| 10298 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10299 | { TestRound(kGet, kSuccess, OK)}}, |
| 10300 | // Authenticating HTTP server with a direct connection. |
| 10301 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10302 | { TestRound(kGet, kServerChallenge, OK), |
| 10303 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10304 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10305 | { TestRound(kGet, kServerChallenge, OK), |
| 10306 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10307 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10308 | { TestRound(kGet, kServerChallenge, OK), |
| 10309 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10310 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10311 | { TestRound(kGet, kServerChallenge, OK), |
| 10312 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10313 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10314 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10315 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10316 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10317 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10318 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10319 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10320 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10321 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10322 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10323 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10324 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10325 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10326 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10327 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10328 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10329 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10330 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10331 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10332 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10333 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10334 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10335 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10336 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10337 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10338 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10339 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10340 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10341 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10342 | // Authenticating HTTP server through an authenticating proxy. |
| 10343 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10344 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10345 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10346 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10347 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10348 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10349 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10350 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10351 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10352 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10353 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10354 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10355 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10356 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10357 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10358 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10359 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10360 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10361 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10362 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10363 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10364 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10365 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10366 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10367 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10368 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10369 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10370 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10371 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10372 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10373 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10374 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10375 | // Non-authenticating HTTPS server with a direct connection. |
| 10376 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10377 | { TestRound(kGet, kSuccess, OK)}}, |
| 10378 | // Authenticating HTTPS server with a direct connection. |
| 10379 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10380 | { TestRound(kGet, kServerChallenge, OK), |
| 10381 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10382 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10383 | { TestRound(kGet, kServerChallenge, OK), |
| 10384 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10385 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10386 | { TestRound(kGet, kServerChallenge, OK), |
| 10387 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10388 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10389 | { TestRound(kGet, kServerChallenge, OK), |
| 10390 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10391 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10392 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10393 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10394 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10395 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10396 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10397 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10398 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10399 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10400 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10401 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10402 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10403 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10404 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10405 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10406 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10407 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10408 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10409 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10410 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10411 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10412 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10413 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10414 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10415 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10416 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10417 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10418 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10419 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10420 | // Authenticating HTTPS server through an authenticating proxy. |
| 10421 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10422 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10423 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10424 | &kGet, &kServerChallenge), |
| 10425 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10426 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10427 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10428 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10429 | &kGet, &kServerChallenge), |
| 10430 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10431 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10432 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10433 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10434 | &kGet, &kServerChallenge), |
| 10435 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10436 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10437 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10438 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10439 | &kGet, &kServerChallenge), |
| 10440 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10441 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10442 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10443 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10444 | &kGet, &kServerChallenge), |
| 10445 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10446 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10447 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10448 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10449 | &kGet, &kServerChallenge), |
| 10450 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10451 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10452 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10453 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10454 | &kGet, &kServerChallenge), |
| 10455 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10456 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10457 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10458 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10459 | &kGet, &kServerChallenge), |
| 10460 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10461 | }; |
| 10462 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10463 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10464 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10465 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10466 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10467 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10468 | |
| 10469 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10470 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10471 | for (int n = 0; n < 2; n++) { |
| 10472 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10473 | std::string auth_challenge = "Mock realm=proxy"; |
| 10474 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10475 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10476 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10477 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10478 | origin, BoundNetLog()); |
| 10479 | auth_handler->SetGenerateExpectation( |
| 10480 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10481 | test_config.proxy_auth_rv); |
| 10482 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10483 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10484 | } |
| 10485 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10486 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10487 | std::string auth_challenge = "Mock realm=server"; |
| 10488 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10489 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10490 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10491 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10492 | origin, BoundNetLog()); |
| 10493 | auth_handler->SetGenerateExpectation( |
| 10494 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10495 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10496 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10497 | } |
| 10498 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10499 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10500 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10501 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10502 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10503 | } |
| 10504 | |
| 10505 | HttpRequestInfo request; |
| 10506 | request.method = "GET"; |
| 10507 | request.url = GURL(test_config.server_url); |
| 10508 | request.load_flags = 0; |
| 10509 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10510 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10511 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10512 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10513 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10514 | |
| 10515 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10516 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10517 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10518 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10519 | |
| 10520 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10521 | mock_reads.back().push_back(read_write_round.read); |
| 10522 | mock_writes.back().push_back(read_write_round.write); |
| 10523 | |
| 10524 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10525 | // socket is closed and a new one will be created for the next request. |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 10526 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10527 | mock_reads.push_back(std::vector<MockRead>()); |
| 10528 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10529 | } |
| 10530 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10531 | if (read_write_round.extra_read) { |
| 10532 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10533 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10534 | if (read_write_round.extra_write) { |
| 10535 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10536 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10537 | |
| 10538 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10539 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10540 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10541 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10542 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10543 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10544 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10545 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10546 | data_providers.push_back(new StaticSocketDataProvider( |
| 10547 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10548 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10549 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10550 | data_providers.back()); |
| 10551 | } |
| 10552 | |
| 10553 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10554 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10555 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10556 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10557 | int rv; |
| 10558 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10559 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10560 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10561 | rv = trans.RestartWithAuth( |
| 10562 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10563 | } |
| 10564 | if (rv == ERR_IO_PENDING) |
| 10565 | rv = callback.WaitForResult(); |
| 10566 | |
| 10567 | // Compare results with expected data. |
| 10568 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10569 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10570 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10571 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10572 | continue; |
| 10573 | } |
| 10574 | if (round + 1 < test_config.num_auth_rounds) { |
| 10575 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10576 | } else { |
| 10577 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10578 | } |
| 10579 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10580 | } |
| 10581 | } |
| 10582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10583 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10584 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10585 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10586 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10587 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10588 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10589 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10590 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10591 | |
| 10592 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10593 | auth_handler->set_connection_based(true); |
| 10594 | std::string auth_challenge = "Mock realm=server"; |
| 10595 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10596 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10597 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10598 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10599 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10600 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10601 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10602 | int rv = OK; |
| 10603 | const HttpResponseInfo* response = NULL; |
| 10604 | HttpRequestInfo request; |
| 10605 | request.method = "GET"; |
| 10606 | request.url = origin; |
| 10607 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10608 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10609 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10610 | |
| 10611 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10612 | // to validate that the TCP socket is not released to the pool between |
| 10613 | // each round of multi-round authentication. |
| 10614 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10615 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10616 | 50, // Max sockets for pool |
| 10617 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10618 | session_deps_.host_resolver.get(), |
| 10619 | session_deps_.socket_factory.get(), |
| 10620 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10621 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10622 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10623 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10624 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10625 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10626 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10627 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10628 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10629 | |
| 10630 | const MockWrite kGet( |
| 10631 | "GET / HTTP/1.1\r\n" |
| 10632 | "Host: www.example.com\r\n" |
| 10633 | "Connection: keep-alive\r\n\r\n"); |
| 10634 | const MockWrite kGetAuth( |
| 10635 | "GET / HTTP/1.1\r\n" |
| 10636 | "Host: www.example.com\r\n" |
| 10637 | "Connection: keep-alive\r\n" |
| 10638 | "Authorization: auth_token\r\n\r\n"); |
| 10639 | |
| 10640 | const MockRead kServerChallenge( |
| 10641 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10642 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10643 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10644 | "Content-Length: 14\r\n\r\n" |
| 10645 | "Unauthorized\r\n"); |
| 10646 | const MockRead kSuccess( |
| 10647 | "HTTP/1.1 200 OK\r\n" |
| 10648 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10649 | "Content-Length: 3\r\n\r\n" |
| 10650 | "Yes"); |
| 10651 | |
| 10652 | MockWrite writes[] = { |
| 10653 | // First round |
| 10654 | kGet, |
| 10655 | // Second round |
| 10656 | kGetAuth, |
| 10657 | // Third round |
| 10658 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10659 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10660 | kGetAuth, |
| 10661 | // Competing request |
| 10662 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10663 | }; |
| 10664 | MockRead reads[] = { |
| 10665 | // First round |
| 10666 | kServerChallenge, |
| 10667 | // Second round |
| 10668 | kServerChallenge, |
| 10669 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10670 | kServerChallenge, |
| 10671 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10672 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10673 | // Competing response |
| 10674 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10675 | }; |
| 10676 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10677 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10678 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10679 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10680 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10681 | |
| 10682 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10683 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10684 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10685 | if (rv == ERR_IO_PENDING) |
| 10686 | rv = callback.WaitForResult(); |
| 10687 | EXPECT_EQ(OK, rv); |
| 10688 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10689 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10690 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10691 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10692 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10693 | // In between rounds, another request comes in for the same domain. |
| 10694 | // It should not be able to grab the TCP socket that trans has already |
| 10695 | // claimed. |
| 10696 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10697 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10698 | TestCompletionCallback callback_compete; |
| 10699 | rv = trans_compete->Start( |
| 10700 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10701 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10702 | // callback_compete.WaitForResult at this point would stall forever, |
| 10703 | // since the HttpNetworkTransaction does not release the request back to |
| 10704 | // the pool until after authentication completes. |
| 10705 | |
| 10706 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10707 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10708 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10709 | if (rv == ERR_IO_PENDING) |
| 10710 | rv = callback.WaitForResult(); |
| 10711 | EXPECT_EQ(OK, rv); |
| 10712 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10713 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10714 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10715 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10716 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10717 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10718 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10719 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10720 | if (rv == ERR_IO_PENDING) |
| 10721 | rv = callback.WaitForResult(); |
| 10722 | EXPECT_EQ(OK, rv); |
| 10723 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10724 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10725 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10726 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10727 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10728 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10729 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10730 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10731 | if (rv == ERR_IO_PENDING) |
| 10732 | rv = callback.WaitForResult(); |
| 10733 | EXPECT_EQ(OK, rv); |
| 10734 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10735 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10736 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10737 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10738 | |
| 10739 | // Read the body since the fourth round was successful. This will also |
| 10740 | // release the socket back to the pool. |
| 10741 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10742 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10743 | if (rv == ERR_IO_PENDING) |
| 10744 | rv = callback.WaitForResult(); |
| 10745 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10746 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10747 | EXPECT_EQ(0, rv); |
| 10748 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10749 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10750 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10751 | |
| 10752 | // The competing request can now finish. Wait for the headers and then |
| 10753 | // read the body. |
| 10754 | rv = callback_compete.WaitForResult(); |
| 10755 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10756 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10757 | if (rv == ERR_IO_PENDING) |
| 10758 | rv = callback.WaitForResult(); |
| 10759 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10760 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10761 | EXPECT_EQ(0, rv); |
| 10762 | |
| 10763 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10764 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10765 | } |
| 10766 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10767 | // This tests the case that a request is issued via http instead of spdy after |
| 10768 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10769 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10770 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10771 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10772 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10773 | session_deps_.next_protos = next_protos; |
| 10774 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10775 | HttpRequestInfo request; |
| 10776 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10777 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10778 | request.load_flags = 0; |
| 10779 | |
| 10780 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10781 | MockWrite( |
| 10782 | "GET / HTTP/1.1\r\n" |
| 10783 | "Host: www.example.org\r\n" |
| 10784 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10785 | }; |
| 10786 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10787 | std::string alternate_protocol_http_header = |
| 10788 | GetAlternateProtocolHttpHeader(); |
| 10789 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10790 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10791 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10792 | MockRead(alternate_protocol_http_header.c_str()), |
| 10793 | MockRead("\r\n"), |
| 10794 | MockRead("hello world"), |
| 10795 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10796 | }; |
| 10797 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10798 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10799 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10800 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10802 | |
| 10803 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10804 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10807 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10808 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10809 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10810 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10813 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10814 | |
| 10815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10816 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10817 | |
| 10818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10819 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10820 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10821 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10822 | |
| 10823 | std::string response_data; |
| 10824 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10825 | EXPECT_EQ("hello world", response_data); |
| 10826 | |
| 10827 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10828 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10829 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10830 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10831 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 10832 | // immediate server closing of the socket. |
| 10833 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10834 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10835 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10836 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10837 | |
| 10838 | HttpRequestInfo request; |
| 10839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10840 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10841 | request.load_flags = 0; |
| 10842 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10843 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10844 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10846 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10847 | scoped_ptr<SpdyFrame> req( |
| 10848 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10849 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10850 | |
| 10851 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10852 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10853 | }; |
| 10854 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10855 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10856 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10857 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10859 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10860 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10861 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10862 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10863 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10865 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10866 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10867 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10868 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10869 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10870 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10871 | // it gets it. This is needed since the auth handler may get destroyed |
| 10872 | // before we get a chance to query it. |
| 10873 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10874 | public: |
| 10875 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10876 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10877 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10878 | |
| 10879 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10880 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10881 | const HttpRequestInfo* request, |
| 10882 | const CompletionCallback& callback, |
| 10883 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10884 | *url_ = request->url; |
| 10885 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10886 | credentials, request, callback, auth_token); |
| 10887 | } |
| 10888 | |
| 10889 | private: |
| 10890 | GURL* url_; |
| 10891 | }; |
| 10892 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10893 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 10894 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10895 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10896 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10897 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10898 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10899 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10900 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10901 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10902 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10903 | GURL request_url; |
| 10904 | { |
| 10905 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10906 | new HttpAuthHandlerMock::Factory(); |
| 10907 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10908 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10909 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10910 | auth_factory->set_do_init_from_challenge(true); |
| 10911 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10912 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10913 | |
| 10914 | HttpRequestInfo request; |
| 10915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10916 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10917 | request.load_flags = 0; |
| 10918 | |
| 10919 | // First round goes unauthenticated through the proxy. |
| 10920 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10921 | MockWrite( |
| 10922 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10923 | "Host: www.example.org\r\n" |
| 10924 | "Proxy-Connection: keep-alive\r\n" |
| 10925 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10926 | }; |
| 10927 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10928 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10929 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10930 | MockRead("Alternate-Protocol: 443:"), |
| 10931 | MockRead(GetAlternateProtocolFromParam()), |
| 10932 | MockRead("\r\n"), |
| 10933 | MockRead("Proxy-Connection: close\r\n"), |
| 10934 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10935 | }; |
| 10936 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10937 | data_writes_1, arraysize(data_writes_1)); |
| 10938 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10939 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10940 | // Alternate-Protocol announcement in the first round. It fails due |
| 10941 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10942 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10943 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10944 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10945 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10946 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10947 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10948 | // to obtain a new one. |
| 10949 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10950 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10951 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10952 | // establishment and SPDY framing issues. Alas, the |
| 10953 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10954 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10955 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10956 | scoped_ptr<SpdyFrame> req( |
| 10957 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10958 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10959 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10960 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10961 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10962 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10963 | MockWrite(ASYNC, 0, |
| 10964 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10965 | "Host: www.example.org\r\n" |
| 10966 | "Proxy-Connection: keep-alive\r\n" |
| 10967 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10968 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10969 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10970 | MockWrite(ASYNC, 2, |
| 10971 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10972 | "Host: www.example.org\r\n" |
| 10973 | "Proxy-Connection: keep-alive\r\n" |
| 10974 | "Proxy-Authorization: auth_token\r\n" |
| 10975 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10976 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10977 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10978 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10979 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10980 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10981 | // First connection attempt fails |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 10982 | MockRead(ASYNC, 1, |
| 10983 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10984 | "Proxy-Authenticate: Mock\r\n" |
| 10985 | "Content-Length: 0\r\n" |
| 10986 | "Proxy-Connection: keep-alive\r\n" |
| 10987 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10988 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10989 | // Second connection attempt passes |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 10990 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10991 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10992 | // SPDY response |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 10993 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10994 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10995 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10996 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 10997 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10998 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10999 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11000 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11001 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11002 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11003 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11004 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11005 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11006 | NULL, 0, NULL, 0); |
| 11007 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11008 | never_finishing_connect); |
| 11009 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11010 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11011 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11012 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11013 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11014 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11015 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11016 | |
| 11017 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11018 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11019 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11021 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11022 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11023 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11024 | |
| 11025 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11026 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11027 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11028 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11029 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11030 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11031 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11032 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11033 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11034 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11035 | |
| 11036 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11037 | TestCompletionCallback callback_3; |
| 11038 | rv = trans_2->RestartWithAuth( |
| 11039 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11041 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11042 | |
| 11043 | // After all that work, these two lines (or actually, just the scheme) are |
| 11044 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11045 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11046 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11047 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11048 | LoadTimingInfo load_timing_info; |
| 11049 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11050 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11051 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11052 | } |
| 11053 | |
| 11054 | // Test that if we cancel the transaction as the connection is completing, that |
| 11055 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11056 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11057 | // Setup everything about the connection to complete synchronously, so that |
| 11058 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11059 | // for is the callback from the HttpStreamRequest. |
| 11060 | // Then cancel the transaction. |
| 11061 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11062 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11063 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11064 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11065 | MockRead(SYNCHRONOUS, "hello world"), |
| 11066 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11067 | }; |
| 11068 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11069 | HttpRequestInfo request; |
| 11070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11071 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11072 | request.load_flags = 0; |
| 11073 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11074 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11075 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11076 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11078 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11079 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11080 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11083 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11084 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11085 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11086 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11087 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11088 | trans.reset(); // Cancel the transaction here. |
| 11089 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11090 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11091 | } |
| 11092 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11093 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11094 | // stream is drained properly and added back to the socket pool. The main |
| 11095 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11096 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11097 | // deleted. |
| 11098 | // See http://crbug.com/368418 |
| 11099 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11100 | MockRead data_reads[] = { |
| 11101 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11102 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11103 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11104 | MockRead(ASYNC, "1"), |
| 11105 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11106 | // HttpNetworkTransaction has been deleted. |
| 11107 | MockRead(ASYNC, "2"), |
| 11108 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11109 | }; |
| 11110 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11112 | |
| 11113 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11114 | |
| 11115 | { |
| 11116 | HttpRequestInfo request; |
| 11117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11118 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11119 | request.load_flags = 0; |
| 11120 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11122 | TestCompletionCallback callback; |
| 11123 | |
| 11124 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11125 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11126 | callback.WaitForResult(); |
| 11127 | |
| 11128 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11129 | ASSERT_TRUE(response != NULL); |
| 11130 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11131 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11132 | |
| 11133 | // The transaction and HttpRequestInfo are deleted. |
| 11134 | } |
| 11135 | |
| 11136 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11137 | base::MessageLoop::current()->RunUntilIdle(); |
| 11138 | |
| 11139 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11140 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11141 | } |
| 11142 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11143 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11144 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11145 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11146 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11147 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11148 | session_deps_.net_log = log.bound().net_log(); |
| 11149 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11150 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11151 | HttpRequestInfo request; |
| 11152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11153 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11154 | |
| 11155 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11156 | MockWrite( |
| 11157 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11158 | "Host: www.example.org\r\n" |
| 11159 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11160 | }; |
| 11161 | |
| 11162 | MockRead data_reads1[] = { |
| 11163 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11164 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11165 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11166 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11167 | }; |
| 11168 | |
| 11169 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11170 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11173 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11174 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11175 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11177 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11178 | trans->SetBeforeProxyHeadersSentCallback( |
| 11179 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11180 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11182 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11184 | |
| 11185 | rv = callback1.WaitForResult(); |
| 11186 | EXPECT_EQ(OK, rv); |
| 11187 | |
| 11188 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11189 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11190 | |
| 11191 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11192 | EXPECT_EQ(200, response->headers->response_code()); |
| 11193 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11194 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11195 | EXPECT_TRUE( |
| 11196 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11197 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11198 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11199 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11200 | |
| 11201 | LoadTimingInfo load_timing_info; |
| 11202 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11203 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11204 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11205 | } |
| 11206 | |
| 11207 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11208 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11209 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11210 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11211 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11212 | session_deps_.net_log = log.bound().net_log(); |
| 11213 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11214 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11215 | HttpRequestInfo request; |
| 11216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11217 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11218 | |
| 11219 | // Since we have proxy, should try to establish tunnel. |
| 11220 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11221 | MockWrite( |
| 11222 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11223 | "Host: www.example.org\r\n" |
| 11224 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11225 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11226 | MockWrite( |
| 11227 | "GET / HTTP/1.1\r\n" |
| 11228 | "Host: www.example.org\r\n" |
| 11229 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11230 | }; |
| 11231 | |
| 11232 | MockRead data_reads1[] = { |
| 11233 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11234 | |
| 11235 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11236 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11237 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11238 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11239 | }; |
| 11240 | |
| 11241 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11242 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11243 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11244 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11247 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11248 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11249 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11250 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11252 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11254 | |
| 11255 | rv = callback1.WaitForResult(); |
| 11256 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11257 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11258 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11259 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11260 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11261 | NetLog::PHASE_NONE); |
| 11262 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11263 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11264 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11265 | NetLog::PHASE_NONE); |
| 11266 | |
| 11267 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11268 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11269 | |
| 11270 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11271 | EXPECT_EQ(200, response->headers->response_code()); |
| 11272 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11273 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11274 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11275 | EXPECT_TRUE( |
| 11276 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11277 | |
| 11278 | LoadTimingInfo load_timing_info; |
| 11279 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11280 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11281 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11282 | } |
| 11283 | |
| 11284 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11285 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11286 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11287 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11288 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11289 | session_deps_.net_log = log.bound().net_log(); |
| 11290 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11291 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11292 | HttpRequestInfo request; |
| 11293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11294 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11295 | |
| 11296 | // Since we have proxy, should try to establish tunnel. |
| 11297 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11298 | MockWrite( |
| 11299 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11300 | "Host: www.example.org\r\n" |
| 11301 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11302 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11303 | MockWrite( |
| 11304 | "GET / HTTP/1.1\r\n" |
| 11305 | "Host: www.example.org\r\n" |
| 11306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11307 | }; |
| 11308 | |
| 11309 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11310 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11311 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11312 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11313 | }; |
| 11314 | |
| 11315 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11316 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11317 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11318 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11319 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11321 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11322 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11323 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11324 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11326 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11327 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11328 | |
| 11329 | rv = callback1.WaitForResult(); |
| 11330 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11331 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11332 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11333 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11334 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11335 | NetLog::PHASE_NONE); |
| 11336 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11337 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11338 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11339 | NetLog::PHASE_NONE); |
| 11340 | } |
| 11341 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11342 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11343 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11344 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11345 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11346 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11347 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11348 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11349 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11350 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11351 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11352 | }; |
| 11353 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11354 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11355 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11356 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11357 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11358 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11359 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11361 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11362 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11363 | |
| 11364 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11365 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11366 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11367 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11368 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11369 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11370 | |
| 11371 | HttpRequestInfo request; |
| 11372 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11373 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11374 | request.load_flags = 0; |
| 11375 | |
| 11376 | // This is the important line that marks this as a preconnect. |
| 11377 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11378 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11379 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11380 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11381 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11382 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11385 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11386 | } |
| 11387 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11388 | // Given a net error, cause that error to be returned from the first Write() |
| 11389 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11390 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11391 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11392 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11393 | request_info.url = GURL("https://www.example.com/"); |
| 11394 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11395 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11396 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11397 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11398 | MockWrite data_writes[] = { |
| 11399 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11400 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11401 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11404 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11405 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11406 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11407 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11409 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11410 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11411 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11412 | rv = callback.WaitForResult(); |
| 11413 | ASSERT_EQ(error, rv); |
| 11414 | } |
| 11415 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11416 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11417 | // Just check a grab bag of cert errors. |
| 11418 | static const int kErrors[] = { |
| 11419 | ERR_CERT_COMMON_NAME_INVALID, |
| 11420 | ERR_CERT_AUTHORITY_INVALID, |
| 11421 | ERR_CERT_DATE_INVALID, |
| 11422 | }; |
| 11423 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11424 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11425 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11426 | } |
| 11427 | } |
| 11428 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11429 | // Ensure that a client certificate is removed from the SSL client auth |
| 11430 | // cache when: |
| 11431 | // 1) No proxy is involved. |
| 11432 | // 2) TLS False Start is disabled. |
| 11433 | // 3) The initial TLS handshake requests a client certificate. |
| 11434 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11435 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11436 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11437 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11438 | request_info.url = GURL("https://www.example.com/"); |
| 11439 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11440 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11441 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11442 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11443 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11444 | |
| 11445 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11446 | // CertificateRequest is received for the first time, the handshake will |
| 11447 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11448 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11449 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11450 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11451 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11452 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11453 | |
| 11454 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11455 | // False Start is not being used, the result of the SSL handshake will be |
| 11456 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11457 | // matches the result of a server sending a handshake_failure alert, |
| 11458 | // rather than a Finished message, because it requires a client |
| 11459 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11460 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11461 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11463 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11464 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11465 | |
| 11466 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11467 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11468 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11469 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11470 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11471 | // requiring a client certificate, this fallback handshake should also |
| 11472 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11473 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11474 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11476 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11477 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11478 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11479 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11480 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11481 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11482 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11483 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11484 | // requiring a client certificate, this fallback handshake should also |
| 11485 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11486 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11487 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11489 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11490 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11491 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11492 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11493 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11494 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11495 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11496 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11497 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11498 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11499 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11500 | |
| 11501 | // Complete the SSL handshake, which should abort due to requiring a |
| 11502 | // client certificate. |
| 11503 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11504 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11505 | |
| 11506 | // Indicate that no certificate should be supplied. From the perspective |
| 11507 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11508 | // certificate, so this is the same as supply a |
| 11509 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11510 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11511 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11512 | |
| 11513 | // Ensure the certificate was added to the client auth cache before |
| 11514 | // allowing the connection to continue restarting. |
| 11515 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11516 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11517 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11518 | ASSERT_EQ(NULL, client_cert.get()); |
| 11519 | |
| 11520 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11521 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11522 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11523 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11524 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11525 | |
| 11526 | // Ensure that the client certificate is removed from the cache on a |
| 11527 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11528 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11529 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11530 | } |
| 11531 | |
| 11532 | // Ensure that a client certificate is removed from the SSL client auth |
| 11533 | // cache when: |
| 11534 | // 1) No proxy is involved. |
| 11535 | // 2) TLS False Start is enabled. |
| 11536 | // 3) The initial TLS handshake requests a client certificate. |
| 11537 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11538 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11539 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11540 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11541 | request_info.url = GURL("https://www.example.com/"); |
| 11542 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11543 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11544 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11545 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11546 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11547 | |
| 11548 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11549 | // return successfully after reading up to the peer's Certificate message. |
| 11550 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11551 | // enqueue application data to be sent in the same packet as the |
| 11552 | // ChangeCipherSpec and Finished messages. |
| 11553 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11554 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11555 | // Finished messages. If there was an error negotiating with the peer, |
| 11556 | // such as due to the peer requiring a client certificate when none was |
| 11557 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11558 | // called. |
| 11559 | |
| 11560 | // Like the non-False Start case, when a client certificate is requested by |
| 11561 | // the peer, the handshake is aborted during the Connect() call. |
| 11562 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11563 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11564 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11566 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11568 | |
| 11569 | // When a client certificate is supplied, Connect() will not be aborted |
| 11570 | // when the peer requests the certificate. Instead, the handshake will |
| 11571 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11572 | // the socket. The handshake messages are not processed until Read() is |
| 11573 | // called, which then detects that the handshake was aborted, due to the |
| 11574 | // peer sending a handshake_failure because it requires a client |
| 11575 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11576 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11577 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11579 | MockRead data2_reads[] = { |
| 11580 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11581 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11582 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11583 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11584 | |
| 11585 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11586 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11587 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11588 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11589 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11591 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11592 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11593 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11594 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11595 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11596 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11597 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11598 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11599 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11600 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11601 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11602 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11603 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11604 | ssl_data5.cert_request_info = cert_request.get(); |
| 11605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11606 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11607 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11608 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11609 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11610 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11611 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11612 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11613 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11614 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11615 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11616 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11617 | |
| 11618 | // Complete the SSL handshake, which should abort due to requiring a |
| 11619 | // client certificate. |
| 11620 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11621 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11622 | |
| 11623 | // Indicate that no certificate should be supplied. From the perspective |
| 11624 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11625 | // certificate, so this is the same as supply a |
| 11626 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11627 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11628 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11629 | |
| 11630 | // Ensure the certificate was added to the client auth cache before |
| 11631 | // allowing the connection to continue restarting. |
| 11632 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11633 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11634 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11635 | ASSERT_EQ(NULL, client_cert.get()); |
| 11636 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11637 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11638 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11639 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11640 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11641 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11642 | |
| 11643 | // Ensure that the client certificate is removed from the cache on a |
| 11644 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11645 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11646 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11647 | } |
| 11648 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11649 | // Ensure that a client certificate is removed from the SSL client auth |
| 11650 | // cache when: |
| 11651 | // 1) An HTTPS proxy is involved. |
| 11652 | // 3) The HTTPS proxy requests a client certificate. |
| 11653 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11654 | // proxy. |
| 11655 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11656 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11657 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11658 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11659 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11660 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11661 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11662 | |
| 11663 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11664 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11665 | |
| 11666 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11667 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11668 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11669 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11670 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11671 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11673 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11674 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11675 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11676 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11677 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11679 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11680 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11681 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11682 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11683 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11684 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11685 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11686 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11687 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11688 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11689 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11690 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11691 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11692 | requests[0].url = GURL("https://www.example.com/"); |
| 11693 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11694 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11695 | |
| 11696 | requests[1].url = GURL("http://www.example.com/"); |
| 11697 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11698 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11699 | |
| 11700 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11701 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11702 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11703 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11704 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11705 | |
| 11706 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11707 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11708 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11709 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11710 | |
| 11711 | // Complete the SSL handshake, which should abort due to requiring a |
| 11712 | // client certificate. |
| 11713 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11714 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11715 | |
| 11716 | // Indicate that no certificate should be supplied. From the perspective |
| 11717 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11718 | // certificate, so this is the same as supply a |
| 11719 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11720 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11721 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11722 | |
| 11723 | // Ensure the certificate was added to the client auth cache before |
| 11724 | // allowing the connection to continue restarting. |
| 11725 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11726 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11727 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11728 | ASSERT_EQ(NULL, client_cert.get()); |
| 11729 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11730 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11731 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11732 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11733 | |
| 11734 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11735 | // then consume ssl_data3, which should also fail. The result code is |
| 11736 | // checked against what ssl_data3 should return. |
| 11737 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11738 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11739 | |
| 11740 | // Now that the new handshake has failed, ensure that the client |
| 11741 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11742 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11743 | HostPortPair("proxy", 70), &client_cert)); |
| 11744 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11745 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11746 | } |
| 11747 | } |
| 11748 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11749 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11750 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11751 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11752 | |
| 11753 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11754 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11755 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11756 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11757 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11758 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11759 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11760 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11762 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11763 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11764 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11765 | scoped_ptr<SpdyFrame> host2_req( |
| 11766 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11767 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11768 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11769 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11770 | scoped_ptr<SpdyFrame> host1_resp( |
| 11771 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11772 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11773 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11774 | scoped_ptr<SpdyFrame> host2_resp( |
| 11775 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11776 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11777 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11778 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11779 | CreateMockRead(*host1_resp, 1), |
| 11780 | CreateMockRead(*host1_resp_body, 2), |
| 11781 | CreateMockRead(*host2_resp, 4), |
| 11782 | CreateMockRead(*host2_resp_body, 5), |
| 11783 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11784 | }; |
| 11785 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11786 | IPAddressNumber ip; |
| 11787 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11788 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11789 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11790 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11791 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11792 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11793 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11794 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11795 | HttpRequestInfo request1; |
| 11796 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11797 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11798 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11799 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11800 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11801 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11803 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11804 | |
| 11805 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11806 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11807 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11808 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11809 | |
| 11810 | std::string response_data; |
| 11811 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11812 | EXPECT_EQ("hello!", response_data); |
| 11813 | |
| 11814 | // Preload www.gmail.com into HostCache. |
| 11815 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11816 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11817 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11818 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11819 | DEFAULT_PRIORITY, |
| 11820 | &ignored, |
| 11821 | callback.callback(), |
| 11822 | NULL, |
| 11823 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11825 | rv = callback.WaitForResult(); |
| 11826 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11827 | |
| 11828 | HttpRequestInfo request2; |
| 11829 | request2.method = "GET"; |
| 11830 | request2.url = GURL("https://www.gmail.com/"); |
| 11831 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11832 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11834 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11836 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11837 | |
| 11838 | response = trans2.GetResponseInfo(); |
| 11839 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11840 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11841 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11842 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11843 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11844 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11845 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11846 | } |
| 11847 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11848 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11849 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11850 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11851 | |
| 11852 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11853 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11854 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11855 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11856 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11857 | |
| 11858 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11859 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11861 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11862 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11863 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11864 | scoped_ptr<SpdyFrame> host2_req( |
| 11865 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11866 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11867 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11868 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11869 | scoped_ptr<SpdyFrame> host1_resp( |
| 11870 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11871 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11872 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11873 | scoped_ptr<SpdyFrame> host2_resp( |
| 11874 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11875 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11876 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11877 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11878 | CreateMockRead(*host1_resp, 1), |
| 11879 | CreateMockRead(*host1_resp_body, 2), |
| 11880 | CreateMockRead(*host2_resp, 4), |
| 11881 | CreateMockRead(*host2_resp_body, 5), |
| 11882 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11883 | }; |
| 11884 | |
| 11885 | IPAddressNumber ip; |
| 11886 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11887 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11888 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11889 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11890 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11891 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11892 | |
| 11893 | TestCompletionCallback callback; |
| 11894 | HttpRequestInfo request1; |
| 11895 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11896 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11897 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11898 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11899 | |
| 11900 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11901 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11902 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11903 | |
| 11904 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11905 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11906 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11907 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11908 | |
| 11909 | std::string response_data; |
| 11910 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11911 | EXPECT_EQ("hello!", response_data); |
| 11912 | |
| 11913 | HttpRequestInfo request2; |
| 11914 | request2.method = "GET"; |
| 11915 | request2.url = GURL("https://www.gmail.com/"); |
| 11916 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11917 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11918 | |
| 11919 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11921 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11922 | |
| 11923 | response = trans2.GetResponseInfo(); |
| 11924 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11925 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11926 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11927 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11928 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11929 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11930 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11931 | } |
| 11932 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11933 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11934 | public: |
| 11935 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11936 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11937 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11938 | |
| 11939 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11940 | |
| 11941 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11942 | int Resolve(const RequestInfo& info, |
| 11943 | RequestPriority priority, |
| 11944 | AddressList* addresses, |
| 11945 | const CompletionCallback& callback, |
| 11946 | RequestHandle* out_req, |
| 11947 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11948 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11949 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11950 | } |
| 11951 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11952 | int ResolveFromCache(const RequestInfo& info, |
| 11953 | AddressList* addresses, |
| 11954 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11955 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11956 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11957 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11958 | return rv; |
| 11959 | } |
| 11960 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11961 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11962 | host_resolver_.CancelRequest(req); |
| 11963 | } |
| 11964 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11965 | MockCachingHostResolver* GetMockHostResolver() { |
| 11966 | return &host_resolver_; |
| 11967 | } |
| 11968 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11969 | private: |
| 11970 | MockCachingHostResolver host_resolver_; |
| 11971 | const HostPortPair host_port_; |
| 11972 | }; |
| 11973 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11974 | TEST_P(HttpNetworkTransactionTest, |
| 11975 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11976 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11977 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11978 | |
| 11979 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11980 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11981 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11982 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11983 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11984 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11985 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11986 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11987 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11988 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11989 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11991 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11992 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11993 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11994 | scoped_ptr<SpdyFrame> host2_req( |
| 11995 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11996 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11997 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11998 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11999 | scoped_ptr<SpdyFrame> host1_resp( |
| 12000 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12001 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12002 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12003 | scoped_ptr<SpdyFrame> host2_resp( |
| 12004 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12005 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12006 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12007 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12008 | CreateMockRead(*host1_resp, 1), |
| 12009 | CreateMockRead(*host1_resp_body, 2), |
| 12010 | CreateMockRead(*host2_resp, 4), |
| 12011 | CreateMockRead(*host2_resp_body, 5), |
| 12012 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12013 | }; |
| 12014 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12015 | IPAddressNumber ip; |
| 12016 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12017 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12018 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12019 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12020 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12021 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12022 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12023 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12024 | HttpRequestInfo request1; |
| 12025 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12026 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12027 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12028 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12030 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12032 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12033 | |
| 12034 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12035 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12036 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12037 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12038 | |
| 12039 | std::string response_data; |
| 12040 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12041 | EXPECT_EQ("hello!", response_data); |
| 12042 | |
| 12043 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12044 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12045 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12046 | rv = host_resolver.Resolve(resolve_info, |
| 12047 | DEFAULT_PRIORITY, |
| 12048 | &ignored, |
| 12049 | callback.callback(), |
| 12050 | NULL, |
| 12051 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12053 | rv = callback.WaitForResult(); |
| 12054 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12055 | |
| 12056 | HttpRequestInfo request2; |
| 12057 | request2.method = "GET"; |
| 12058 | request2.url = GURL("https://www.gmail.com/"); |
| 12059 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12060 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12062 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12064 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12065 | |
| 12066 | response = trans2.GetResponseInfo(); |
| 12067 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12068 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12069 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12070 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12071 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12072 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12073 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12074 | } |
| 12075 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12076 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12077 | const std::string https_url = "https://www.example.org:8080/"; |
| 12078 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12079 | |
| 12080 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12081 | scoped_ptr<SpdyFrame> req1( |
| 12082 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12083 | |
| 12084 | MockWrite writes1[] = { |
| 12085 | CreateMockWrite(*req1, 0), |
| 12086 | }; |
| 12087 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12088 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12089 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12090 | MockRead reads1[] = { |
| 12091 | CreateMockRead(*resp1, 1), |
| 12092 | CreateMockRead(*body1, 2), |
| 12093 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12094 | }; |
| 12095 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12096 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12097 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12098 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12099 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12100 | |
| 12101 | // HTTP GET for the HTTP URL |
| 12102 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12103 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12104 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12105 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12106 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12107 | }; |
| 12108 | |
| 12109 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12110 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12111 | MockRead(ASYNC, 2, "hello"), |
| 12112 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12113 | }; |
| 12114 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12115 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12116 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12117 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12118 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12119 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12121 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12122 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12123 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12124 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12125 | |
| 12126 | // Start the first transaction to set up the SpdySession |
| 12127 | HttpRequestInfo request1; |
| 12128 | request1.method = "GET"; |
| 12129 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12130 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12131 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12132 | TestCompletionCallback callback1; |
| 12133 | EXPECT_EQ(ERR_IO_PENDING, |
| 12134 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12135 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12136 | |
| 12137 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12138 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12139 | |
| 12140 | // Now, start the HTTP request |
| 12141 | HttpRequestInfo request2; |
| 12142 | request2.method = "GET"; |
| 12143 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12144 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12145 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12146 | TestCompletionCallback callback2; |
| 12147 | EXPECT_EQ(ERR_IO_PENDING, |
| 12148 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12149 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12150 | |
| 12151 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12152 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12153 | } |
| 12154 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12155 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12156 | public: |
| 12157 | void Run(bool pooling, bool valid) { |
| 12158 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12159 | 443); |
| 12160 | HostPortPair alternative("www.example.org", 443); |
| 12161 | |
| 12162 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12163 | scoped_refptr<X509Certificate> cert( |
| 12164 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12165 | ASSERT_TRUE(cert.get()); |
| 12166 | bool common_name_fallback_used; |
| 12167 | EXPECT_EQ(valid, |
| 12168 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12169 | EXPECT_TRUE( |
| 12170 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12171 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12172 | ssl.SetNextProto(GetParam()); |
| 12173 | ssl.cert = cert; |
| 12174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12175 | |
| 12176 | // If pooling, then start a request to alternative first to create a |
| 12177 | // SpdySession. |
| 12178 | std::string url0 = "https://www.example.org:443"; |
| 12179 | // Second request to origin, which has an alternative service, and could |
| 12180 | // open a connection to the alternative host or pool to the existing one. |
| 12181 | std::string url1("https://"); |
| 12182 | url1.append(origin.host()); |
| 12183 | url1.append(":443"); |
| 12184 | |
| 12185 | scoped_ptr<SpdyFrame> req0; |
| 12186 | scoped_ptr<SpdyFrame> req1; |
| 12187 | scoped_ptr<SpdyFrame> resp0; |
| 12188 | scoped_ptr<SpdyFrame> body0; |
| 12189 | scoped_ptr<SpdyFrame> resp1; |
| 12190 | scoped_ptr<SpdyFrame> body1; |
| 12191 | std::vector<MockWrite> writes; |
| 12192 | std::vector<MockRead> reads; |
| 12193 | |
| 12194 | if (pooling) { |
| 12195 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12196 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12197 | |
| 12198 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12199 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12200 | |
| 12201 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12202 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12203 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12204 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12205 | |
| 12206 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12207 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12208 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12209 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12210 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12211 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12212 | } else { |
| 12213 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12214 | |
| 12215 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12216 | |
| 12217 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12218 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12219 | |
| 12220 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12221 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12222 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12223 | } |
| 12224 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12225 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12226 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12228 | |
| 12229 | // Connection to the origin fails. |
| 12230 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12231 | StaticSocketDataProvider data_refused; |
| 12232 | data_refused.set_connect_data(mock_connect); |
| 12233 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12234 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12235 | session_deps_.use_alternative_services = true; |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12236 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12237 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12238 | session->http_server_properties(); |
| 12239 | AlternativeService alternative_service( |
| 12240 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12241 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12242 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12243 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12244 | |
| 12245 | // First request to alternative. |
| 12246 | if (pooling) { |
| 12247 | scoped_ptr<HttpTransaction> trans0( |
| 12248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12249 | HttpRequestInfo request0; |
| 12250 | request0.method = "GET"; |
| 12251 | request0.url = GURL(url0); |
| 12252 | request0.load_flags = 0; |
| 12253 | TestCompletionCallback callback0; |
| 12254 | |
| 12255 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12257 | rv = callback0.WaitForResult(); |
| 12258 | EXPECT_EQ(OK, rv); |
| 12259 | } |
| 12260 | |
| 12261 | // Second request to origin. |
| 12262 | scoped_ptr<HttpTransaction> trans1( |
| 12263 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12264 | HttpRequestInfo request1; |
| 12265 | request1.method = "GET"; |
| 12266 | request1.url = GURL(url1); |
| 12267 | request1.load_flags = 0; |
| 12268 | TestCompletionCallback callback1; |
| 12269 | |
| 12270 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12272 | base::MessageLoop::current()->RunUntilIdle(); |
| 12273 | if (data.IsReadPaused()) { |
| 12274 | data.CompleteRead(); |
| 12275 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12276 | rv = callback1.WaitForResult(); |
| 12277 | if (valid) { |
| 12278 | EXPECT_EQ(OK, rv); |
| 12279 | } else { |
| 12280 | if (pooling) { |
| 12281 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12282 | } else { |
| 12283 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12284 | } |
| 12285 | } |
| 12286 | } |
| 12287 | }; |
| 12288 | |
| 12289 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12290 | AltSvcCertificateVerificationTest, |
| 12291 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12292 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12293 | |
| 12294 | // The alternative service host must exhibit a certificate that is valid for the |
| 12295 | // origin host. Test that this is enforced when pooling to an existing |
| 12296 | // connection. |
| 12297 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12298 | Run(true, true); |
| 12299 | } |
| 12300 | |
| 12301 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12302 | Run(true, false); |
| 12303 | } |
| 12304 | |
| 12305 | // The alternative service host must exhibit a certificate that is valid for the |
| 12306 | // origin host. Test that this is enforced when opening a new connection. |
| 12307 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12308 | Run(false, true); |
| 12309 | } |
| 12310 | |
| 12311 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12312 | Run(false, false); |
| 12313 | } |
| 12314 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12315 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12316 | // with the alternative server. That connection should not be used. |
| 12317 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12318 | HostPortPair origin("origin.example.org", 443); |
| 12319 | HostPortPair alternative("alternative.example.org", 443); |
| 12320 | |
| 12321 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12322 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12323 | ssl.SetNextProto(kProtoHTTP11); |
| 12324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12325 | |
| 12326 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12327 | // negotiated. |
| 12328 | StaticSocketDataProvider data; |
| 12329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12330 | |
| 12331 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12332 | // negotiated. In order to test this, a failed connection to the origin is |
| 12333 | // mocked. This way the request relies on the alternate Job. |
| 12334 | StaticSocketDataProvider data_refused; |
| 12335 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12336 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12337 | |
| 12338 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12339 | session_deps_.use_alternative_services = true; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12340 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12341 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12342 | session->http_server_properties(); |
| 12343 | AlternativeService alternative_service( |
| 12344 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12345 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12346 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12347 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12348 | |
| 12349 | scoped_ptr<HttpTransaction> trans( |
| 12350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12351 | HttpRequestInfo request; |
| 12352 | request.method = "GET"; |
| 12353 | request.url = GURL("https://origin.example.org:443"); |
| 12354 | request.load_flags = 0; |
| 12355 | TestCompletionCallback callback; |
| 12356 | |
| 12357 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12358 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12359 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12360 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12361 | } |
| 12362 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12363 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12364 | // origin, and an alternate one to the alternative server. If the former |
| 12365 | // succeeds, the request should succeed, even if the latter fails because |
| 12366 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12367 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12368 | HostPortPair origin("origin.example.org", 443); |
| 12369 | HostPortPair alternative("alternative.example.org", 443); |
| 12370 | |
| 12371 | // Negotiate HTTP/1.1 with alternative. |
| 12372 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12373 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12375 | |
| 12376 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12377 | // negotiated. |
| 12378 | StaticSocketDataProvider data; |
| 12379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12380 | |
| 12381 | // Negotiate HTTP/1.1 with origin. |
| 12382 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12383 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12384 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12385 | |
| 12386 | MockWrite http_writes[] = { |
| 12387 | MockWrite( |
| 12388 | "GET / HTTP/1.1\r\n" |
| 12389 | "Host: origin.example.org\r\n" |
| 12390 | "Connection: keep-alive\r\n\r\n"), |
| 12391 | MockWrite( |
| 12392 | "GET /second HTTP/1.1\r\n" |
| 12393 | "Host: origin.example.org\r\n" |
| 12394 | "Connection: keep-alive\r\n\r\n"), |
| 12395 | }; |
| 12396 | |
| 12397 | MockRead http_reads[] = { |
| 12398 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12399 | MockRead("Content-Type: text/html\r\n"), |
| 12400 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12401 | MockRead("foobar"), |
| 12402 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12403 | MockRead("Content-Type: text/html\r\n"), |
| 12404 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12405 | MockRead("another"), |
| 12406 | }; |
| 12407 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12408 | http_writes, arraysize(http_writes)); |
| 12409 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12410 | |
| 12411 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12412 | session_deps_.use_alternative_services = true; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12413 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12414 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12415 | session->http_server_properties(); |
| 12416 | AlternativeService alternative_service( |
| 12417 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12418 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12419 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12420 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12421 | |
| 12422 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12423 | HttpRequestInfo request1; |
| 12424 | request1.method = "GET"; |
| 12425 | request1.url = GURL("https://origin.example.org:443"); |
| 12426 | request1.load_flags = 0; |
| 12427 | TestCompletionCallback callback1; |
| 12428 | |
| 12429 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12430 | rv = callback1.GetResult(rv); |
| 12431 | EXPECT_EQ(OK, rv); |
| 12432 | |
| 12433 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12434 | ASSERT_TRUE(response1 != nullptr); |
| 12435 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12436 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12437 | |
| 12438 | std::string response_data1; |
| 12439 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12440 | EXPECT_EQ("foobar", response_data1); |
| 12441 | |
| 12442 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12443 | // for alternative service. |
| 12444 | EXPECT_TRUE( |
| 12445 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12446 | |
| 12447 | // Since |alternative_service| is broken, a second transaction to origin |
| 12448 | // should not start an alternate Job. It should pool to existing connection |
| 12449 | // to origin. |
| 12450 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12451 | HttpRequestInfo request2; |
| 12452 | request2.method = "GET"; |
| 12453 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12454 | request2.load_flags = 0; |
| 12455 | TestCompletionCallback callback2; |
| 12456 | |
| 12457 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12458 | rv = callback2.GetResult(rv); |
| 12459 | EXPECT_EQ(OK, rv); |
| 12460 | |
| 12461 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12462 | ASSERT_TRUE(response2 != nullptr); |
| 12463 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12464 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12465 | |
| 12466 | std::string response_data2; |
| 12467 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12468 | EXPECT_EQ("another", response_data2); |
| 12469 | } |
| 12470 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12471 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12472 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12473 | // used. |
| 12474 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12475 | HostPortPair origin("origin.example.org", 443); |
| 12476 | HostPortPair alternative("alternative.example.org", 443); |
| 12477 | std::string origin_url = "https://origin.example.org:443"; |
| 12478 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12479 | |
| 12480 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12481 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12482 | ssl.SetNextProto(kProtoHTTP11); |
| 12483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12484 | |
| 12485 | // HTTP/1.1 data for |request1| and |request2|. |
| 12486 | MockWrite http_writes[] = { |
| 12487 | MockWrite( |
| 12488 | "GET / HTTP/1.1\r\n" |
| 12489 | "Host: alternative.example.org\r\n" |
| 12490 | "Connection: keep-alive\r\n\r\n"), |
| 12491 | MockWrite( |
| 12492 | "GET / HTTP/1.1\r\n" |
| 12493 | "Host: alternative.example.org\r\n" |
| 12494 | "Connection: keep-alive\r\n\r\n"), |
| 12495 | }; |
| 12496 | |
| 12497 | MockRead http_reads[] = { |
| 12498 | MockRead( |
| 12499 | "HTTP/1.1 200 OK\r\n" |
| 12500 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12501 | "Content-Length: 40\r\n\r\n" |
| 12502 | "first HTTP/1.1 response from alternative"), |
| 12503 | MockRead( |
| 12504 | "HTTP/1.1 200 OK\r\n" |
| 12505 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12506 | "Content-Length: 41\r\n\r\n" |
| 12507 | "second HTTP/1.1 response from alternative"), |
| 12508 | }; |
| 12509 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12510 | http_writes, arraysize(http_writes)); |
| 12511 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12512 | |
| 12513 | // This test documents that an alternate Job should not pool to an already |
| 12514 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12515 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12516 | StaticSocketDataProvider data_refused; |
| 12517 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12518 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12519 | |
| 12520 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12521 | session_deps_.use_alternative_services = true; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12522 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12523 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12524 | session->http_server_properties(); |
| 12525 | AlternativeService alternative_service( |
| 12526 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12527 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12528 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12529 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12530 | |
| 12531 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12532 | scoped_ptr<HttpTransaction> trans1( |
| 12533 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12534 | HttpRequestInfo request1; |
| 12535 | request1.method = "GET"; |
| 12536 | request1.url = GURL(alternative_url); |
| 12537 | request1.load_flags = 0; |
| 12538 | TestCompletionCallback callback1; |
| 12539 | |
| 12540 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12541 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12542 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12543 | ASSERT_TRUE(response1); |
| 12544 | ASSERT_TRUE(response1->headers.get()); |
| 12545 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12546 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12547 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12548 | std::string response_data1; |
| 12549 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12550 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12551 | |
| 12552 | // Request for origin.example.org, which has an alternative service. This |
| 12553 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12554 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12555 | // open other connections to alternative server. The Job to origin fails, so |
| 12556 | // this request fails. |
| 12557 | scoped_ptr<HttpTransaction> trans2( |
| 12558 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12559 | HttpRequestInfo request2; |
| 12560 | request2.method = "GET"; |
| 12561 | request2.url = GURL(origin_url); |
| 12562 | request2.load_flags = 0; |
| 12563 | TestCompletionCallback callback2; |
| 12564 | |
| 12565 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12566 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12567 | |
| 12568 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12569 | // socket is still open and in the pool. |
| 12570 | scoped_ptr<HttpTransaction> trans3( |
| 12571 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12572 | HttpRequestInfo request3; |
| 12573 | request3.method = "GET"; |
| 12574 | request3.url = GURL(alternative_url); |
| 12575 | request3.load_flags = 0; |
| 12576 | TestCompletionCallback callback3; |
| 12577 | |
| 12578 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12579 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12580 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12581 | ASSERT_TRUE(response3); |
| 12582 | ASSERT_TRUE(response3->headers.get()); |
| 12583 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12584 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12585 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12586 | std::string response_data3; |
| 12587 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12588 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12589 | } |
| 12590 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12591 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12592 | const std::string https_url = "https://www.example.org:8080/"; |
| 12593 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12594 | |
| 12595 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12596 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12597 | scoped_ptr<SpdyFrame> connect( |
| 12598 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12599 | scoped_ptr<SpdyFrame> req1( |
| 12600 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12601 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12602 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12603 | |
| 12604 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12605 | SpdyHeaderBlock req2_block; |
| 12606 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 12607 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12608 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12609 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 12610 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12611 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12612 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12613 | |
| 12614 | MockWrite writes1[] = { |
| 12615 | CreateMockWrite(*connect, 0), |
| 12616 | CreateMockWrite(*wrapped_req1, 2), |
| 12617 | CreateMockWrite(*req2, 5), |
| 12618 | }; |
| 12619 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12620 | scoped_ptr<SpdyFrame> conn_resp( |
| 12621 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12622 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12623 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12624 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12625 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12626 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12627 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12628 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12629 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12630 | MockRead reads1[] = { |
| 12631 | CreateMockRead(*conn_resp, 1), |
| 12632 | CreateMockRead(*wrapped_resp1, 3), |
| 12633 | CreateMockRead(*wrapped_body1, 4), |
| 12634 | CreateMockRead(*resp2, 6), |
| 12635 | CreateMockRead(*body2, 7), |
| 12636 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12637 | }; |
| 12638 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12639 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12640 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12641 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12642 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12643 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12644 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12645 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12646 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12647 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12648 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12649 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12650 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12651 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12652 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12653 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12654 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12655 | |
| 12656 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12657 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12658 | |
| 12659 | // Start the first transaction to set up the SpdySession |
| 12660 | HttpRequestInfo request1; |
| 12661 | request1.method = "GET"; |
| 12662 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12663 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12664 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12665 | TestCompletionCallback callback1; |
| 12666 | EXPECT_EQ(ERR_IO_PENDING, |
| 12667 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12668 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12669 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12670 | |
| 12671 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12672 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12673 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12674 | LoadTimingInfo load_timing_info1; |
| 12675 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12676 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12677 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12678 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12679 | // Now, start the HTTP request |
| 12680 | HttpRequestInfo request2; |
| 12681 | request2.method = "GET"; |
| 12682 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12683 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12684 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12685 | TestCompletionCallback callback2; |
| 12686 | EXPECT_EQ(ERR_IO_PENDING, |
| 12687 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12688 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12689 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12690 | |
| 12691 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12692 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12693 | |
| 12694 | LoadTimingInfo load_timing_info2; |
| 12695 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12696 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12697 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12698 | // HTTP requests over a SPDY session should have a different connection |
| 12699 | // socket_log_id than requests over a tunnel. |
| 12700 | 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] | 12701 | } |
| 12702 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12703 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12704 | // that we do not pool other origins that resolve to the same IP when |
| 12705 | // the certificate does not match the new origin. |
| 12706 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12707 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12708 | const std::string url1 = "http://www.example.org/"; |
| 12709 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12710 | const std::string ip_addr = "1.2.3.4"; |
| 12711 | |
| 12712 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12713 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12714 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12715 | scoped_ptr<SpdyFrame> req1( |
| 12716 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12717 | |
| 12718 | MockWrite writes1[] = { |
| 12719 | CreateMockWrite(*req1, 0), |
| 12720 | }; |
| 12721 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12722 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12723 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12724 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12725 | CreateMockRead(*resp1, 1), |
| 12726 | CreateMockRead(*body1, 2), |
| 12727 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12728 | }; |
| 12729 | |
| 12730 | scoped_ptr<DeterministicSocketData> data1( |
| 12731 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12732 | writes1, arraysize(writes1))); |
| 12733 | IPAddressNumber ip; |
| 12734 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12735 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12736 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12737 | data1->set_connect_data(connect_data1); |
| 12738 | |
| 12739 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12740 | scoped_ptr<SpdyFrame> req2( |
| 12741 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12742 | |
| 12743 | MockWrite writes2[] = { |
| 12744 | CreateMockWrite(*req2, 0), |
| 12745 | }; |
| 12746 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12747 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12748 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12749 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12750 | CreateMockRead(*resp2, 1), |
| 12751 | CreateMockRead(*body2, 2), |
| 12752 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12753 | }; |
| 12754 | |
| 12755 | scoped_ptr<DeterministicSocketData> data2( |
| 12756 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12757 | writes2, arraysize(writes2))); |
| 12758 | MockConnect connect_data2(ASYNC, OK); |
| 12759 | data2->set_connect_data(connect_data2); |
| 12760 | |
| 12761 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12762 | // all others direct. |
| 12763 | ProxyConfig proxy_config; |
| 12764 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12765 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12766 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12767 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12768 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12769 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12770 | // Load a valid cert. Note, that this does not need to |
| 12771 | // be valid for proxy because the MockSSLClientSocket does |
| 12772 | // not actually verify it. But SpdySession will use this |
| 12773 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12774 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12775 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12776 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12777 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12778 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12779 | |
| 12780 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12781 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12782 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12783 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12784 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12785 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12786 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12787 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12788 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12789 | |
| 12790 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12791 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12792 | |
| 12793 | // Start the first transaction to set up the SpdySession |
| 12794 | HttpRequestInfo request1; |
| 12795 | request1.method = "GET"; |
| 12796 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12797 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12798 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12799 | TestCompletionCallback callback1; |
| 12800 | ASSERT_EQ(ERR_IO_PENDING, |
| 12801 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12802 | data1->RunFor(3); |
| 12803 | |
| 12804 | ASSERT_TRUE(callback1.have_result()); |
| 12805 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12806 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12807 | |
| 12808 | // Now, start the HTTP request |
| 12809 | HttpRequestInfo request2; |
| 12810 | request2.method = "GET"; |
| 12811 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12812 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12813 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12814 | TestCompletionCallback callback2; |
| 12815 | EXPECT_EQ(ERR_IO_PENDING, |
| 12816 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12817 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12818 | data2->RunFor(3); |
| 12819 | |
| 12820 | ASSERT_TRUE(callback2.have_result()); |
| 12821 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12822 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12823 | } |
| 12824 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12825 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12826 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12827 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12828 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12829 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12830 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12831 | |
| 12832 | MockRead reads1[] = { |
| 12833 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12834 | }; |
| 12835 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12836 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12837 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12838 | scoped_ptr<SpdyFrame> req2( |
| 12839 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12840 | MockWrite writes2[] = { |
| 12841 | CreateMockWrite(*req2, 0), |
| 12842 | }; |
| 12843 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12844 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12845 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12846 | MockRead reads2[] = { |
| 12847 | CreateMockRead(*resp2, 1), |
| 12848 | CreateMockRead(*body2, 2), |
| 12849 | MockRead(ASYNC, OK, 3) // EOF |
| 12850 | }; |
| 12851 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12852 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12853 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12854 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12855 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12856 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12858 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12859 | |
| 12860 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12861 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12863 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12864 | |
| 12865 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12866 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12867 | |
| 12868 | // Start the first transaction to set up the SpdySession and verify that |
| 12869 | // connection was closed. |
| 12870 | HttpRequestInfo request1; |
| 12871 | request1.method = "GET"; |
| 12872 | request1.url = GURL(https_url); |
| 12873 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12874 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12875 | TestCompletionCallback callback1; |
| 12876 | EXPECT_EQ(ERR_IO_PENDING, |
| 12877 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12878 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12879 | |
| 12880 | // Now, start the second request and make sure it succeeds. |
| 12881 | HttpRequestInfo request2; |
| 12882 | request2.method = "GET"; |
| 12883 | request2.url = GURL(https_url); |
| 12884 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12885 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12886 | TestCompletionCallback callback2; |
| 12887 | EXPECT_EQ(ERR_IO_PENDING, |
| 12888 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12889 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12890 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12891 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12892 | } |
| 12893 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12894 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12895 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12896 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12897 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12898 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12899 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12900 | |
| 12901 | // Use two different hosts with different IPs so they don't get pooled. |
| 12902 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12903 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12904 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12905 | |
| 12906 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12907 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12908 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12909 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12911 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12912 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12913 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12914 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12915 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12916 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12917 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12918 | scoped_ptr<SpdyFrame> host1_resp( |
| 12919 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12920 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12921 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12922 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12923 | CreateMockRead(*host1_resp, 1), |
| 12924 | CreateMockRead(*host1_resp_body, 2), |
| 12925 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12926 | }; |
| 12927 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12928 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12929 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12930 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12931 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12932 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12933 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12934 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12935 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12936 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12937 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12938 | scoped_ptr<SpdyFrame> host2_resp( |
| 12939 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12940 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12941 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12942 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12943 | CreateMockRead(*host2_resp, 1), |
| 12944 | CreateMockRead(*host2_resp_body, 2), |
| 12945 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12946 | }; |
| 12947 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12948 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12949 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12950 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12951 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12952 | |
| 12953 | MockWrite http_write[] = { |
| 12954 | MockWrite("GET / HTTP/1.1\r\n" |
| 12955 | "Host: www.a.com\r\n" |
| 12956 | "Connection: keep-alive\r\n\r\n"), |
| 12957 | }; |
| 12958 | |
| 12959 | MockRead http_read[] = { |
| 12960 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12961 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12962 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12963 | MockRead("hello!"), |
| 12964 | }; |
| 12965 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12966 | http_write, arraysize(http_write)); |
| 12967 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12968 | |
| 12969 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12970 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12971 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12972 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12973 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12974 | |
| 12975 | TestCompletionCallback callback; |
| 12976 | HttpRequestInfo request1; |
| 12977 | request1.method = "GET"; |
| 12978 | request1.url = GURL("https://www.a.com/"); |
| 12979 | request1.load_flags = 0; |
| 12980 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12981 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12982 | |
| 12983 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12984 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12985 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12986 | |
| 12987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12988 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12989 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12990 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12991 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12992 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12993 | |
| 12994 | std::string response_data; |
| 12995 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12996 | EXPECT_EQ("hello!", response_data); |
| 12997 | trans.reset(); |
| 12998 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12999 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13000 | |
| 13001 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13002 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13003 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13004 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13005 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13006 | HttpRequestInfo request2; |
| 13007 | request2.method = "GET"; |
| 13008 | request2.url = GURL("https://www.b.com/"); |
| 13009 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13010 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13011 | |
| 13012 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13014 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13015 | |
| 13016 | response = trans->GetResponseInfo(); |
| 13017 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13018 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13019 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13020 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13021 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13022 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13023 | EXPECT_EQ("hello!", response_data); |
| 13024 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13025 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13026 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13027 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13028 | |
| 13029 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13030 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13031 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13032 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13033 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13034 | HttpRequestInfo request3; |
| 13035 | request3.method = "GET"; |
| 13036 | request3.url = GURL("http://www.a.com/"); |
| 13037 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13038 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13039 | |
| 13040 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13042 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13043 | |
| 13044 | response = trans->GetResponseInfo(); |
| 13045 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13046 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13047 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13048 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13049 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13050 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13051 | EXPECT_EQ("hello!", response_data); |
| 13052 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13053 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13054 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13055 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13056 | } |
| 13057 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13058 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13059 | HttpRequestInfo request; |
| 13060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13061 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13062 | request.load_flags = 0; |
| 13063 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13064 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13065 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13066 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13067 | |
| 13068 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 13069 | StaticSocketDataProvider data; |
| 13070 | data.set_connect_data(mock_connect); |
| 13071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13072 | |
| 13073 | TestCompletionCallback callback; |
| 13074 | |
| 13075 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13076 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13077 | |
| 13078 | rv = callback.WaitForResult(); |
| 13079 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13080 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13081 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13082 | HttpRequestHeaders request_headers; |
| 13083 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13084 | |
| 13085 | ConnectionAttempts attempts; |
| 13086 | trans->GetConnectionAttempts(&attempts); |
| 13087 | ASSERT_EQ(1u, attempts.size()); |
| 13088 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13089 | } |
| 13090 | |
| 13091 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13092 | HttpRequestInfo request; |
| 13093 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13094 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13095 | request.load_flags = 0; |
| 13096 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13097 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13098 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13099 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13100 | |
| 13101 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13102 | StaticSocketDataProvider data; |
| 13103 | data.set_connect_data(mock_connect); |
| 13104 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13105 | |
| 13106 | TestCompletionCallback callback; |
| 13107 | |
| 13108 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13109 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13110 | |
| 13111 | rv = callback.WaitForResult(); |
| 13112 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13113 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13114 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13115 | HttpRequestHeaders request_headers; |
| 13116 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13117 | |
| 13118 | ConnectionAttempts attempts; |
| 13119 | trans->GetConnectionAttempts(&attempts); |
| 13120 | ASSERT_EQ(1u, attempts.size()); |
| 13121 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13122 | } |
| 13123 | |
| 13124 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13125 | HttpRequestInfo request; |
| 13126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13127 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13128 | request.load_flags = 0; |
| 13129 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13130 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13131 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13132 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13133 | |
| 13134 | MockWrite data_writes[] = { |
| 13135 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13136 | }; |
| 13137 | MockRead data_reads[] = { |
| 13138 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13139 | }; |
| 13140 | |
| 13141 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13142 | data_writes, arraysize(data_writes)); |
| 13143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13144 | |
| 13145 | TestCompletionCallback callback; |
| 13146 | |
| 13147 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13148 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13149 | |
| 13150 | rv = callback.WaitForResult(); |
| 13151 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13152 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13153 | HttpRequestHeaders request_headers; |
| 13154 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13155 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13156 | } |
| 13157 | |
| 13158 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13159 | HttpRequestInfo request; |
| 13160 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13161 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13162 | request.load_flags = 0; |
| 13163 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13164 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13165 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13166 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13167 | |
| 13168 | MockWrite data_writes[] = { |
| 13169 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13170 | }; |
| 13171 | MockRead data_reads[] = { |
| 13172 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13173 | }; |
| 13174 | |
| 13175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13176 | data_writes, arraysize(data_writes)); |
| 13177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13178 | |
| 13179 | TestCompletionCallback callback; |
| 13180 | |
| 13181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13183 | |
| 13184 | rv = callback.WaitForResult(); |
| 13185 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13186 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13187 | HttpRequestHeaders request_headers; |
| 13188 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13189 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13190 | } |
| 13191 | |
| 13192 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13193 | HttpRequestInfo request; |
| 13194 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13195 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13196 | request.load_flags = 0; |
| 13197 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13198 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13199 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13200 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13201 | |
| 13202 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13203 | MockWrite( |
| 13204 | "GET / HTTP/1.1\r\n" |
| 13205 | "Host: www.example.org\r\n" |
| 13206 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13207 | }; |
| 13208 | MockRead data_reads[] = { |
| 13209 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13210 | }; |
| 13211 | |
| 13212 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13213 | data_writes, arraysize(data_writes)); |
| 13214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13215 | |
| 13216 | TestCompletionCallback callback; |
| 13217 | |
| 13218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13220 | |
| 13221 | rv = callback.WaitForResult(); |
| 13222 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13223 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13224 | HttpRequestHeaders request_headers; |
| 13225 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13226 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13227 | } |
| 13228 | |
| 13229 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13230 | HttpRequestInfo request; |
| 13231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13232 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13233 | request.load_flags = 0; |
| 13234 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13235 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13236 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13238 | |
| 13239 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13240 | MockWrite( |
| 13241 | "GET / HTTP/1.1\r\n" |
| 13242 | "Host: www.example.org\r\n" |
| 13243 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13244 | }; |
| 13245 | MockRead data_reads[] = { |
| 13246 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13247 | }; |
| 13248 | |
| 13249 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13250 | data_writes, arraysize(data_writes)); |
| 13251 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13252 | |
| 13253 | TestCompletionCallback callback; |
| 13254 | |
| 13255 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13257 | |
| 13258 | rv = callback.WaitForResult(); |
| 13259 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13260 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13261 | HttpRequestHeaders request_headers; |
| 13262 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13263 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13264 | } |
| 13265 | |
| 13266 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13267 | HttpRequestInfo request; |
| 13268 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13269 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13270 | request.load_flags = 0; |
| 13271 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13272 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13273 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13274 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13276 | |
| 13277 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13278 | MockWrite( |
| 13279 | "GET / HTTP/1.1\r\n" |
| 13280 | "Host: www.example.org\r\n" |
| 13281 | "Connection: keep-alive\r\n" |
| 13282 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13283 | }; |
| 13284 | MockRead data_reads[] = { |
| 13285 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13286 | "Content-Length: 5\r\n\r\n" |
| 13287 | "hello"), |
| 13288 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13289 | }; |
| 13290 | |
| 13291 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13292 | data_writes, arraysize(data_writes)); |
| 13293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13294 | |
| 13295 | TestCompletionCallback callback; |
| 13296 | |
| 13297 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13299 | |
| 13300 | rv = callback.WaitForResult(); |
| 13301 | EXPECT_EQ(OK, rv); |
| 13302 | |
| 13303 | HttpRequestHeaders request_headers; |
| 13304 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13305 | std::string foo; |
| 13306 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13307 | EXPECT_EQ("bar", foo); |
| 13308 | } |
| 13309 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13310 | namespace { |
| 13311 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13312 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13313 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13314 | public base::SupportsWeakPtr<FakeStream> { |
| 13315 | public: |
| 13316 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13317 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13318 | |
| 13319 | RequestPriority priority() const { return priority_; } |
| 13320 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13321 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13322 | RequestPriority priority, |
| 13323 | const BoundNetLog& net_log, |
| 13324 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13325 | return ERR_IO_PENDING; |
| 13326 | } |
| 13327 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13328 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13329 | HttpResponseInfo* response, |
| 13330 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13331 | ADD_FAILURE(); |
| 13332 | return ERR_UNEXPECTED; |
| 13333 | } |
| 13334 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13335 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13336 | ADD_FAILURE(); |
| 13337 | return ERR_UNEXPECTED; |
| 13338 | } |
| 13339 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13340 | int ReadResponseBody(IOBuffer* buf, |
| 13341 | int buf_len, |
| 13342 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13343 | ADD_FAILURE(); |
| 13344 | return ERR_UNEXPECTED; |
| 13345 | } |
| 13346 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13347 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13348 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13349 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13350 | ADD_FAILURE(); |
| 13351 | return false; |
| 13352 | } |
| 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 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13361 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13362 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13363 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13364 | ADD_FAILURE(); |
| 13365 | return 0; |
| 13366 | } |
| 13367 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame^] | 13368 | int64_t GetTotalSentBytes() const override { |
| 13369 | ADD_FAILURE(); |
| 13370 | return 0; |
| 13371 | } |
| 13372 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13373 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13374 | ADD_FAILURE(); |
| 13375 | return false; |
| 13376 | } |
| 13377 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13378 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13379 | |
| 13380 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13381 | ADD_FAILURE(); |
| 13382 | } |
| 13383 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13384 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13385 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13386 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13387 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13388 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13389 | |
| 13390 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13391 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13392 | private: |
| 13393 | RequestPriority priority_; |
| 13394 | |
| 13395 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13396 | }; |
| 13397 | |
| 13398 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13399 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13400 | class FakeStreamRequest : public HttpStreamRequest, |
| 13401 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13402 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13403 | FakeStreamRequest(RequestPriority priority, |
| 13404 | HttpStreamRequest::Delegate* delegate) |
| 13405 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13406 | delegate_(delegate), |
| 13407 | websocket_stream_create_helper_(NULL) {} |
| 13408 | |
| 13409 | FakeStreamRequest(RequestPriority priority, |
| 13410 | HttpStreamRequest::Delegate* delegate, |
| 13411 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13412 | : priority_(priority), |
| 13413 | delegate_(delegate), |
| 13414 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13415 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13416 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13417 | |
| 13418 | RequestPriority priority() const { return priority_; } |
| 13419 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13420 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13421 | websocket_stream_create_helper() const { |
| 13422 | return websocket_stream_create_helper_; |
| 13423 | } |
| 13424 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13425 | // Create a new FakeStream and pass it to the request's |
| 13426 | // delegate. Returns a weak pointer to the FakeStream. |
| 13427 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13428 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13429 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13430 | // immediately delete |fake_stream|. |
| 13431 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13432 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13433 | return weak_stream; |
| 13434 | } |
| 13435 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13436 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13437 | ADD_FAILURE(); |
| 13438 | return ERR_UNEXPECTED; |
| 13439 | } |
| 13440 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13441 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13442 | ADD_FAILURE(); |
| 13443 | return LoadState(); |
| 13444 | } |
| 13445 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13446 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13447 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13448 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13449 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13450 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13451 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13452 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13453 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13454 | const ConnectionAttempts& connection_attempts() const override { |
| 13455 | static ConnectionAttempts no_attempts; |
| 13456 | return no_attempts; |
| 13457 | } |
| 13458 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13459 | private: |
| 13460 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13461 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13462 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13463 | |
| 13464 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13465 | }; |
| 13466 | |
| 13467 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13468 | class FakeStreamFactory : public HttpStreamFactory { |
| 13469 | public: |
| 13470 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13471 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13472 | |
| 13473 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13474 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13475 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13476 | return last_stream_request_; |
| 13477 | } |
| 13478 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13479 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13480 | RequestPriority priority, |
| 13481 | const SSLConfig& server_ssl_config, |
| 13482 | const SSLConfig& proxy_ssl_config, |
| 13483 | HttpStreamRequest::Delegate* delegate, |
| 13484 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13485 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13486 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13487 | return fake_request; |
| 13488 | } |
| 13489 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13490 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13491 | const HttpRequestInfo& info, |
| 13492 | RequestPriority priority, |
| 13493 | const SSLConfig& server_ssl_config, |
| 13494 | const SSLConfig& proxy_ssl_config, |
| 13495 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13496 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13497 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13498 | FakeStreamRequest* fake_request = |
| 13499 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13500 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13501 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13502 | } |
| 13503 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13504 | void PreconnectStreams(int num_streams, |
| 13505 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13506 | const SSLConfig& server_ssl_config, |
| 13507 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13508 | ADD_FAILURE(); |
| 13509 | } |
| 13510 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13511 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13512 | ADD_FAILURE(); |
| 13513 | return NULL; |
| 13514 | } |
| 13515 | |
| 13516 | private: |
| 13517 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13518 | |
| 13519 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13520 | }; |
| 13521 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13522 | // TODO(ricea): Maybe unify this with the one in |
| 13523 | // url_request_http_job_unittest.cc ? |
| 13524 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13525 | public: |
| 13526 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13527 | bool using_proxy) |
| 13528 | : state_(connection.release(), using_proxy) {} |
| 13529 | |
| 13530 | // Fake implementation of HttpStreamBase methods. |
| 13531 | // This ends up being quite "real" because this object has to really send data |
| 13532 | // on the mock socket. It might be easier to use the real implementation, but |
| 13533 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13534 | // difficult. |
| 13535 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13536 | RequestPriority priority, |
| 13537 | const BoundNetLog& net_log, |
| 13538 | const CompletionCallback& callback) override { |
| 13539 | state_.Initialize(request_info, priority, net_log, callback); |
| 13540 | return OK; |
| 13541 | } |
| 13542 | |
| 13543 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13544 | HttpResponseInfo* response, |
| 13545 | const CompletionCallback& callback) override { |
| 13546 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13547 | response, callback); |
| 13548 | } |
| 13549 | |
| 13550 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13551 | return parser()->ReadResponseHeaders(callback); |
| 13552 | } |
| 13553 | |
| 13554 | int ReadResponseBody(IOBuffer* buf, |
| 13555 | int buf_len, |
| 13556 | const CompletionCallback& callback) override { |
| 13557 | NOTREACHED(); |
| 13558 | return ERR_IO_PENDING; |
| 13559 | } |
| 13560 | |
| 13561 | void Close(bool not_reusable) override { |
| 13562 | if (parser()) |
| 13563 | parser()->Close(true); |
| 13564 | } |
| 13565 | |
| 13566 | bool IsResponseBodyComplete() const override { |
| 13567 | NOTREACHED(); |
| 13568 | return false; |
| 13569 | } |
| 13570 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13571 | bool IsConnectionReused() const override { |
| 13572 | NOTREACHED(); |
| 13573 | return false; |
| 13574 | } |
| 13575 | void SetConnectionReused() override { NOTREACHED(); } |
| 13576 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13577 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13578 | |
| 13579 | int64 GetTotalReceivedBytes() const override { |
| 13580 | NOTREACHED(); |
| 13581 | return 0; |
| 13582 | } |
| 13583 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame^] | 13584 | int64_t GetTotalSentBytes() const override { |
| 13585 | NOTREACHED(); |
| 13586 | return 0; |
| 13587 | } |
| 13588 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13589 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13590 | NOTREACHED(); |
| 13591 | return false; |
| 13592 | } |
| 13593 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13594 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13595 | |
| 13596 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13597 | NOTREACHED(); |
| 13598 | } |
| 13599 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13600 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13601 | |
| 13602 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13603 | |
| 13604 | UploadProgress GetUploadProgress() const override { |
| 13605 | NOTREACHED(); |
| 13606 | return UploadProgress(); |
| 13607 | } |
| 13608 | |
| 13609 | HttpStream* RenewStreamForAuth() override { |
| 13610 | NOTREACHED(); |
| 13611 | return nullptr; |
| 13612 | } |
| 13613 | |
| 13614 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13615 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13616 | NOTREACHED(); |
| 13617 | return scoped_ptr<WebSocketStream>(); |
| 13618 | } |
| 13619 | |
| 13620 | private: |
| 13621 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13622 | HttpBasicState state_; |
| 13623 | |
| 13624 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13625 | }; |
| 13626 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13627 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13628 | // worth doing. |
| 13629 | class FakeWebSocketStreamCreateHelper : |
| 13630 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13631 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13632 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13633 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13634 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13635 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13636 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13637 | } |
| 13638 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13639 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13640 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13641 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13642 | NOTREACHED(); |
| 13643 | return NULL; |
| 13644 | }; |
| 13645 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13646 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13647 | |
| 13648 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13649 | NOTREACHED(); |
| 13650 | return scoped_ptr<WebSocketStream>(); |
| 13651 | } |
| 13652 | }; |
| 13653 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13654 | } // namespace |
| 13655 | |
| 13656 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13657 | // stream request on start. |
| 13658 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 13659 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13660 | HttpNetworkSessionPeer peer(session); |
| 13661 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13662 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13663 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13664 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13665 | |
| 13666 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13667 | |
| 13668 | HttpRequestInfo request; |
| 13669 | TestCompletionCallback callback; |
| 13670 | EXPECT_EQ(ERR_IO_PENDING, |
| 13671 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13672 | |
| 13673 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13674 | fake_factory->last_stream_request(); |
| 13675 | ASSERT_TRUE(fake_request != NULL); |
| 13676 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13677 | } |
| 13678 | |
| 13679 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13680 | // updates to its stream request. |
| 13681 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 13682 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13683 | HttpNetworkSessionPeer peer(session); |
| 13684 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13685 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13686 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13687 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13688 | |
| 13689 | HttpRequestInfo request; |
| 13690 | TestCompletionCallback callback; |
| 13691 | EXPECT_EQ(ERR_IO_PENDING, |
| 13692 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13693 | |
| 13694 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13695 | fake_factory->last_stream_request(); |
| 13696 | ASSERT_TRUE(fake_request != NULL); |
| 13697 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13698 | |
| 13699 | trans.SetPriority(LOWEST); |
| 13700 | ASSERT_TRUE(fake_request != NULL); |
| 13701 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13702 | } |
| 13703 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13704 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13705 | // updates to its stream. |
| 13706 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 13707 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13708 | HttpNetworkSessionPeer peer(session); |
| 13709 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13710 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13711 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13712 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13713 | |
| 13714 | HttpRequestInfo request; |
| 13715 | TestCompletionCallback callback; |
| 13716 | EXPECT_EQ(ERR_IO_PENDING, |
| 13717 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13718 | |
| 13719 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13720 | fake_factory->last_stream_request(); |
| 13721 | ASSERT_TRUE(fake_request != NULL); |
| 13722 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13723 | ASSERT_TRUE(fake_stream != NULL); |
| 13724 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13725 | |
| 13726 | trans.SetPriority(LOWEST); |
| 13727 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13728 | } |
| 13729 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13730 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13731 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13732 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13733 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13734 | std::string test_cases[] = {"ws://www.example.org/", |
| 13735 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13736 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 13737 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13738 | HttpNetworkSessionPeer peer(session); |
| 13739 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13740 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13741 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13742 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13743 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13744 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13745 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13746 | &websocket_stream_create_helper); |
| 13747 | |
| 13748 | HttpRequestInfo request; |
| 13749 | TestCompletionCallback callback; |
| 13750 | request.method = "GET"; |
| 13751 | request.url = GURL(test_cases[i]); |
| 13752 | |
| 13753 | EXPECT_EQ(ERR_IO_PENDING, |
| 13754 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13755 | |
| 13756 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13757 | fake_factory->last_stream_request(); |
| 13758 | ASSERT_TRUE(fake_request != NULL); |
| 13759 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13760 | fake_request->websocket_stream_create_helper()); |
| 13761 | } |
| 13762 | } |
| 13763 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13764 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13765 | // if the transport socket pool is stalled on the global socket limit. |
| 13766 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13767 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13768 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13769 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13770 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13771 | |
| 13772 | // Set up SSL request. |
| 13773 | |
| 13774 | HttpRequestInfo ssl_request; |
| 13775 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13776 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13777 | |
| 13778 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13779 | MockWrite( |
| 13780 | "GET / HTTP/1.1\r\n" |
| 13781 | "Host: www.example.org\r\n" |
| 13782 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13783 | }; |
| 13784 | MockRead ssl_reads[] = { |
| 13785 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13786 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13787 | MockRead("hello world"), |
| 13788 | MockRead(SYNCHRONOUS, OK), |
| 13789 | }; |
| 13790 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13791 | ssl_writes, arraysize(ssl_writes)); |
| 13792 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13793 | |
| 13794 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13796 | |
| 13797 | // Set up HTTP request. |
| 13798 | |
| 13799 | HttpRequestInfo http_request; |
| 13800 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13801 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13802 | |
| 13803 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13804 | MockWrite( |
| 13805 | "GET / HTTP/1.1\r\n" |
| 13806 | "Host: www.example.org\r\n" |
| 13807 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13808 | }; |
| 13809 | MockRead http_reads[] = { |
| 13810 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13811 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13812 | MockRead("falafel"), |
| 13813 | MockRead(SYNCHRONOUS, OK), |
| 13814 | }; |
| 13815 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13816 | http_writes, arraysize(http_writes)); |
| 13817 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13818 | |
| 13819 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13820 | |
| 13821 | // Start the SSL request. |
| 13822 | TestCompletionCallback ssl_callback; |
| 13823 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13825 | ASSERT_EQ(ERR_IO_PENDING, |
| 13826 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13827 | BoundNetLog())); |
| 13828 | |
| 13829 | // Start the HTTP request. Pool should stall. |
| 13830 | TestCompletionCallback http_callback; |
| 13831 | scoped_ptr<HttpTransaction> http_trans( |
| 13832 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13833 | ASSERT_EQ(ERR_IO_PENDING, |
| 13834 | http_trans->Start(&http_request, http_callback.callback(), |
| 13835 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13836 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13837 | |
| 13838 | // Wait for response from SSL request. |
| 13839 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13840 | std::string response_data; |
| 13841 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13842 | EXPECT_EQ("hello world", response_data); |
| 13843 | |
| 13844 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13845 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13846 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13847 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13848 | |
| 13849 | // The HTTP request can now complete. |
| 13850 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13851 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13852 | EXPECT_EQ("falafel", response_data); |
| 13853 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13854 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13855 | } |
| 13856 | |
| 13857 | // Tests that when a SSL connection is established but there's no corresponding |
| 13858 | // request that needs it, the new socket is closed if the transport socket pool |
| 13859 | // is stalled on the global socket limit. |
| 13860 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13861 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13862 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13863 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13864 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13865 | |
| 13866 | // Set up an ssl request. |
| 13867 | |
| 13868 | HttpRequestInfo ssl_request; |
| 13869 | ssl_request.method = "GET"; |
| 13870 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13871 | |
| 13872 | // No data will be sent on the SSL socket. |
| 13873 | StaticSocketDataProvider ssl_data; |
| 13874 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13875 | |
| 13876 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13878 | |
| 13879 | // Set up HTTP request. |
| 13880 | |
| 13881 | HttpRequestInfo http_request; |
| 13882 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13883 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13884 | |
| 13885 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13886 | MockWrite( |
| 13887 | "GET / HTTP/1.1\r\n" |
| 13888 | "Host: www.example.org\r\n" |
| 13889 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13890 | }; |
| 13891 | MockRead http_reads[] = { |
| 13892 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13893 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13894 | MockRead("falafel"), |
| 13895 | MockRead(SYNCHRONOUS, OK), |
| 13896 | }; |
| 13897 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13898 | http_writes, arraysize(http_writes)); |
| 13899 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13900 | |
| 13901 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13902 | |
| 13903 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13904 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13905 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13906 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13907 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 13908 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 13909 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13910 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13911 | |
| 13912 | // Start the HTTP request. Pool should stall. |
| 13913 | TestCompletionCallback http_callback; |
| 13914 | scoped_ptr<HttpTransaction> http_trans( |
| 13915 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13916 | ASSERT_EQ(ERR_IO_PENDING, |
| 13917 | http_trans->Start(&http_request, http_callback.callback(), |
| 13918 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13919 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13920 | |
| 13921 | // The SSL connection will automatically be closed once the connection is |
| 13922 | // established, to let the HTTP request start. |
| 13923 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13924 | std::string response_data; |
| 13925 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13926 | EXPECT_EQ("falafel", response_data); |
| 13927 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13928 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13929 | } |
| 13930 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13931 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13932 | ScopedVector<UploadElementReader> element_readers; |
| 13933 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13934 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13935 | |
| 13936 | HttpRequestInfo request; |
| 13937 | request.method = "POST"; |
| 13938 | request.url = GURL("http://www.foo.com/"); |
| 13939 | request.upload_data_stream = &upload_data_stream; |
| 13940 | request.load_flags = 0; |
| 13941 | |
| 13942 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13943 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13944 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13945 | // Send headers successfully, but get an error while sending the body. |
| 13946 | MockWrite data_writes[] = { |
| 13947 | MockWrite("POST / HTTP/1.1\r\n" |
| 13948 | "Host: www.foo.com\r\n" |
| 13949 | "Connection: keep-alive\r\n" |
| 13950 | "Content-Length: 3\r\n\r\n"), |
| 13951 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13952 | }; |
| 13953 | |
| 13954 | MockRead data_reads[] = { |
| 13955 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13956 | MockRead("hello world"), |
| 13957 | MockRead(SYNCHRONOUS, OK), |
| 13958 | }; |
| 13959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13960 | arraysize(data_writes)); |
| 13961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13962 | |
| 13963 | TestCompletionCallback callback; |
| 13964 | |
| 13965 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13967 | |
| 13968 | rv = callback.WaitForResult(); |
| 13969 | EXPECT_EQ(OK, rv); |
| 13970 | |
| 13971 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13972 | ASSERT_TRUE(response != NULL); |
| 13973 | |
| 13974 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13975 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13976 | |
| 13977 | std::string response_data; |
| 13978 | rv = ReadTransaction(trans.get(), &response_data); |
| 13979 | EXPECT_EQ(OK, rv); |
| 13980 | EXPECT_EQ("hello world", response_data); |
| 13981 | } |
| 13982 | |
| 13983 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13984 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13985 | TEST_P(HttpNetworkTransactionTest, |
| 13986 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13987 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13988 | MockWrite data_writes[] = { |
| 13989 | MockWrite("GET / HTTP/1.1\r\n" |
| 13990 | "Host: www.foo.com\r\n" |
| 13991 | "Connection: keep-alive\r\n\r\n"), |
| 13992 | MockWrite("POST / HTTP/1.1\r\n" |
| 13993 | "Host: www.foo.com\r\n" |
| 13994 | "Connection: keep-alive\r\n" |
| 13995 | "Content-Length: 3\r\n\r\n"), |
| 13996 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13997 | }; |
| 13998 | |
| 13999 | MockRead data_reads[] = { |
| 14000 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14001 | "Content-Length: 14\r\n\r\n"), |
| 14002 | MockRead("first response"), |
| 14003 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14004 | "Content-Length: 15\r\n\r\n"), |
| 14005 | MockRead("second response"), |
| 14006 | MockRead(SYNCHRONOUS, OK), |
| 14007 | }; |
| 14008 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14009 | arraysize(data_writes)); |
| 14010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14011 | |
| 14012 | TestCompletionCallback callback; |
| 14013 | HttpRequestInfo request1; |
| 14014 | request1.method = "GET"; |
| 14015 | request1.url = GURL("http://www.foo.com/"); |
| 14016 | request1.load_flags = 0; |
| 14017 | |
| 14018 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14020 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14021 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14022 | |
| 14023 | rv = callback.WaitForResult(); |
| 14024 | EXPECT_EQ(OK, rv); |
| 14025 | |
| 14026 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14027 | ASSERT_TRUE(response1 != NULL); |
| 14028 | |
| 14029 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14030 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14031 | |
| 14032 | std::string response_data1; |
| 14033 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14034 | EXPECT_EQ(OK, rv); |
| 14035 | EXPECT_EQ("first response", response_data1); |
| 14036 | // Delete the transaction to release the socket back into the socket pool. |
| 14037 | trans1.reset(); |
| 14038 | |
| 14039 | ScopedVector<UploadElementReader> element_readers; |
| 14040 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14041 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14042 | |
| 14043 | HttpRequestInfo request2; |
| 14044 | request2.method = "POST"; |
| 14045 | request2.url = GURL("http://www.foo.com/"); |
| 14046 | request2.upload_data_stream = &upload_data_stream; |
| 14047 | request2.load_flags = 0; |
| 14048 | |
| 14049 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14051 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14053 | |
| 14054 | rv = callback.WaitForResult(); |
| 14055 | EXPECT_EQ(OK, rv); |
| 14056 | |
| 14057 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14058 | ASSERT_TRUE(response2 != NULL); |
| 14059 | |
| 14060 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14061 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14062 | |
| 14063 | std::string response_data2; |
| 14064 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14065 | EXPECT_EQ(OK, rv); |
| 14066 | EXPECT_EQ("second response", response_data2); |
| 14067 | } |
| 14068 | |
| 14069 | TEST_P(HttpNetworkTransactionTest, |
| 14070 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14071 | ScopedVector<UploadElementReader> element_readers; |
| 14072 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14073 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14074 | |
| 14075 | HttpRequestInfo request; |
| 14076 | request.method = "POST"; |
| 14077 | request.url = GURL("http://www.foo.com/"); |
| 14078 | request.upload_data_stream = &upload_data_stream; |
| 14079 | request.load_flags = 0; |
| 14080 | |
| 14081 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14082 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14084 | // Send headers successfully, but get an error while sending the body. |
| 14085 | MockWrite data_writes[] = { |
| 14086 | MockWrite("POST / HTTP/1.1\r\n" |
| 14087 | "Host: www.foo.com\r\n" |
| 14088 | "Connection: keep-alive\r\n" |
| 14089 | "Content-Length: 3\r\n\r\n" |
| 14090 | "fo"), |
| 14091 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14092 | }; |
| 14093 | |
| 14094 | MockRead data_reads[] = { |
| 14095 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14096 | MockRead("hello world"), |
| 14097 | MockRead(SYNCHRONOUS, OK), |
| 14098 | }; |
| 14099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14100 | arraysize(data_writes)); |
| 14101 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14102 | |
| 14103 | TestCompletionCallback callback; |
| 14104 | |
| 14105 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14106 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14107 | |
| 14108 | rv = callback.WaitForResult(); |
| 14109 | EXPECT_EQ(OK, rv); |
| 14110 | |
| 14111 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14112 | ASSERT_TRUE(response != NULL); |
| 14113 | |
| 14114 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14115 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14116 | |
| 14117 | std::string response_data; |
| 14118 | rv = ReadTransaction(trans.get(), &response_data); |
| 14119 | EXPECT_EQ(OK, rv); |
| 14120 | EXPECT_EQ("hello world", response_data); |
| 14121 | } |
| 14122 | |
| 14123 | // This tests the more common case than the previous test, where headers and |
| 14124 | // body are not merged into a single request. |
| 14125 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14126 | ScopedVector<UploadElementReader> element_readers; |
| 14127 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14128 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14129 | |
| 14130 | HttpRequestInfo request; |
| 14131 | request.method = "POST"; |
| 14132 | request.url = GURL("http://www.foo.com/"); |
| 14133 | request.upload_data_stream = &upload_data_stream; |
| 14134 | request.load_flags = 0; |
| 14135 | |
| 14136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14137 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14139 | // Send headers successfully, but get an error while sending the body. |
| 14140 | MockWrite data_writes[] = { |
| 14141 | MockWrite("POST / HTTP/1.1\r\n" |
| 14142 | "Host: www.foo.com\r\n" |
| 14143 | "Connection: keep-alive\r\n" |
| 14144 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14145 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14146 | }; |
| 14147 | |
| 14148 | MockRead data_reads[] = { |
| 14149 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14150 | MockRead("hello world"), |
| 14151 | MockRead(SYNCHRONOUS, OK), |
| 14152 | }; |
| 14153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14154 | arraysize(data_writes)); |
| 14155 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14156 | |
| 14157 | TestCompletionCallback callback; |
| 14158 | |
| 14159 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14161 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14162 | // they can't be merged with the body in a single send. Not currently |
| 14163 | // necessary since a chunked body is never merged with headers, but this makes |
| 14164 | // the test more future proof. |
| 14165 | base::RunLoop().RunUntilIdle(); |
| 14166 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14167 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14168 | |
| 14169 | rv = callback.WaitForResult(); |
| 14170 | EXPECT_EQ(OK, rv); |
| 14171 | |
| 14172 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14173 | ASSERT_TRUE(response != NULL); |
| 14174 | |
| 14175 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14176 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14177 | |
| 14178 | std::string response_data; |
| 14179 | rv = ReadTransaction(trans.get(), &response_data); |
| 14180 | EXPECT_EQ(OK, rv); |
| 14181 | EXPECT_EQ("hello world", response_data); |
| 14182 | } |
| 14183 | |
| 14184 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 14185 | ScopedVector<UploadElementReader> element_readers; |
| 14186 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14187 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14188 | |
| 14189 | HttpRequestInfo request; |
| 14190 | request.method = "POST"; |
| 14191 | request.url = GURL("http://www.foo.com/"); |
| 14192 | request.upload_data_stream = &upload_data_stream; |
| 14193 | request.load_flags = 0; |
| 14194 | |
| 14195 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14196 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14197 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14198 | |
| 14199 | MockWrite data_writes[] = { |
| 14200 | MockWrite("POST / HTTP/1.1\r\n" |
| 14201 | "Host: www.foo.com\r\n" |
| 14202 | "Connection: keep-alive\r\n" |
| 14203 | "Content-Length: 3\r\n\r\n"), |
| 14204 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14205 | }; |
| 14206 | |
| 14207 | MockRead data_reads[] = { |
| 14208 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14209 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14210 | MockRead("hello world"), |
| 14211 | MockRead(SYNCHRONOUS, OK), |
| 14212 | }; |
| 14213 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14214 | arraysize(data_writes)); |
| 14215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14216 | |
| 14217 | TestCompletionCallback callback; |
| 14218 | |
| 14219 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14220 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14221 | |
| 14222 | rv = callback.WaitForResult(); |
| 14223 | EXPECT_EQ(OK, rv); |
| 14224 | |
| 14225 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14226 | ASSERT_TRUE(response != NULL); |
| 14227 | |
| 14228 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14229 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14230 | |
| 14231 | std::string response_data; |
| 14232 | rv = ReadTransaction(trans.get(), &response_data); |
| 14233 | EXPECT_EQ(OK, rv); |
| 14234 | EXPECT_EQ("hello world", response_data); |
| 14235 | } |
| 14236 | |
| 14237 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14238 | ScopedVector<UploadElementReader> element_readers; |
| 14239 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14240 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14241 | |
| 14242 | HttpRequestInfo request; |
| 14243 | request.method = "POST"; |
| 14244 | request.url = GURL("http://www.foo.com/"); |
| 14245 | request.upload_data_stream = &upload_data_stream; |
| 14246 | request.load_flags = 0; |
| 14247 | |
| 14248 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14249 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14250 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14251 | // Send headers successfully, but get an error while sending the body. |
| 14252 | MockWrite data_writes[] = { |
| 14253 | MockWrite("POST / HTTP/1.1\r\n" |
| 14254 | "Host: www.foo.com\r\n" |
| 14255 | "Connection: keep-alive\r\n" |
| 14256 | "Content-Length: 3\r\n\r\n"), |
| 14257 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14258 | }; |
| 14259 | |
| 14260 | MockRead data_reads[] = { |
| 14261 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14262 | MockRead("hello world"), |
| 14263 | MockRead(SYNCHRONOUS, OK), |
| 14264 | }; |
| 14265 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14266 | arraysize(data_writes)); |
| 14267 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14268 | |
| 14269 | TestCompletionCallback callback; |
| 14270 | |
| 14271 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14272 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14273 | |
| 14274 | rv = callback.WaitForResult(); |
| 14275 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14276 | } |
| 14277 | |
| 14278 | TEST_P(HttpNetworkTransactionTest, |
| 14279 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14280 | ScopedVector<UploadElementReader> element_readers; |
| 14281 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14282 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14283 | |
| 14284 | HttpRequestInfo request; |
| 14285 | request.method = "POST"; |
| 14286 | request.url = GURL("http://www.foo.com/"); |
| 14287 | request.upload_data_stream = &upload_data_stream; |
| 14288 | request.load_flags = 0; |
| 14289 | |
| 14290 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14291 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14292 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14293 | // Send headers successfully, but get an error while sending the body. |
| 14294 | MockWrite data_writes[] = { |
| 14295 | MockWrite("POST / HTTP/1.1\r\n" |
| 14296 | "Host: www.foo.com\r\n" |
| 14297 | "Connection: keep-alive\r\n" |
| 14298 | "Content-Length: 3\r\n\r\n"), |
| 14299 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14300 | }; |
| 14301 | |
| 14302 | MockRead data_reads[] = { |
| 14303 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14304 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14305 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14306 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14307 | MockRead(SYNCHRONOUS, OK), |
| 14308 | }; |
| 14309 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14310 | arraysize(data_writes)); |
| 14311 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14312 | |
| 14313 | TestCompletionCallback callback; |
| 14314 | |
| 14315 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14316 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14317 | |
| 14318 | rv = callback.WaitForResult(); |
| 14319 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14320 | } |
| 14321 | |
| 14322 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14323 | ScopedVector<UploadElementReader> element_readers; |
| 14324 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14325 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14326 | |
| 14327 | HttpRequestInfo request; |
| 14328 | request.method = "POST"; |
| 14329 | request.url = GURL("http://www.foo.com/"); |
| 14330 | request.upload_data_stream = &upload_data_stream; |
| 14331 | request.load_flags = 0; |
| 14332 | |
| 14333 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14334 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14336 | // Send headers successfully, but get an error while sending the body. |
| 14337 | MockWrite data_writes[] = { |
| 14338 | MockWrite("POST / HTTP/1.1\r\n" |
| 14339 | "Host: www.foo.com\r\n" |
| 14340 | "Connection: keep-alive\r\n" |
| 14341 | "Content-Length: 3\r\n\r\n"), |
| 14342 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14343 | }; |
| 14344 | |
| 14345 | MockRead data_reads[] = { |
| 14346 | MockRead("HTTP 0.9 rocks!"), |
| 14347 | MockRead(SYNCHRONOUS, OK), |
| 14348 | }; |
| 14349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14350 | arraysize(data_writes)); |
| 14351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14352 | |
| 14353 | TestCompletionCallback callback; |
| 14354 | |
| 14355 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14357 | |
| 14358 | rv = callback.WaitForResult(); |
| 14359 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14360 | } |
| 14361 | |
| 14362 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14363 | ScopedVector<UploadElementReader> element_readers; |
| 14364 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14365 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14366 | |
| 14367 | HttpRequestInfo request; |
| 14368 | request.method = "POST"; |
| 14369 | request.url = GURL("http://www.foo.com/"); |
| 14370 | request.upload_data_stream = &upload_data_stream; |
| 14371 | request.load_flags = 0; |
| 14372 | |
| 14373 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14374 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14375 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14376 | // Send headers successfully, but get an error while sending the body. |
| 14377 | MockWrite data_writes[] = { |
| 14378 | MockWrite("POST / HTTP/1.1\r\n" |
| 14379 | "Host: www.foo.com\r\n" |
| 14380 | "Connection: keep-alive\r\n" |
| 14381 | "Content-Length: 3\r\n\r\n"), |
| 14382 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14383 | }; |
| 14384 | |
| 14385 | MockRead data_reads[] = { |
| 14386 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14387 | MockRead(SYNCHRONOUS, OK), |
| 14388 | }; |
| 14389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14390 | arraysize(data_writes)); |
| 14391 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14392 | |
| 14393 | TestCompletionCallback callback; |
| 14394 | |
| 14395 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14396 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14397 | |
| 14398 | rv = callback.WaitForResult(); |
| 14399 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14400 | } |
| 14401 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14402 | // Verify that proxy headers are not sent to the destination server when |
| 14403 | // establishing a tunnel for a secure WebSocket connection. |
| 14404 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14405 | HttpRequestInfo request; |
| 14406 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14407 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14408 | AddWebSocketHeaders(&request.extra_headers); |
| 14409 | |
| 14410 | // Configure against proxy server "myproxy:70". |
| 14411 | session_deps_.proxy_service.reset( |
| 14412 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14413 | |
| 14414 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14415 | |
| 14416 | // Since a proxy is configured, try to establish a tunnel. |
| 14417 | MockWrite data_writes[] = { |
| 14418 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14419 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14420 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14421 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14422 | |
| 14423 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14424 | // be issuing -- the final header line contains the credentials. |
| 14425 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14426 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14427 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14428 | "Proxy-Connection: keep-alive\r\n" |
| 14429 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14430 | |
| 14431 | MockWrite( |
| 14432 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14433 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14434 | "Connection: Upgrade\r\n" |
| 14435 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14436 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14437 | "Sec-WebSocket-Version: 13\r\n" |
| 14438 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14439 | }; |
| 14440 | |
| 14441 | // The proxy responds to the connect with a 407, using a persistent |
| 14442 | // connection. |
| 14443 | MockRead data_reads[] = { |
| 14444 | // No credentials. |
| 14445 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14446 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 14447 | MockRead("Content-Length: 0\r\n"), |
| 14448 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14449 | |
| 14450 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14451 | |
| 14452 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14453 | MockRead("Upgrade: websocket\r\n"), |
| 14454 | MockRead("Connection: Upgrade\r\n"), |
| 14455 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14456 | }; |
| 14457 | |
| 14458 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14459 | arraysize(data_writes)); |
| 14460 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14461 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14463 | |
| 14464 | scoped_ptr<HttpTransaction> trans( |
| 14465 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14466 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14467 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14468 | &websocket_stream_create_helper); |
| 14469 | |
| 14470 | { |
| 14471 | TestCompletionCallback callback; |
| 14472 | |
| 14473 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14474 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14475 | |
| 14476 | rv = callback.WaitForResult(); |
| 14477 | EXPECT_EQ(OK, rv); |
| 14478 | } |
| 14479 | |
| 14480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14481 | ASSERT_TRUE(response); |
| 14482 | ASSERT_TRUE(response->headers.get()); |
| 14483 | EXPECT_EQ(407, response->headers->response_code()); |
| 14484 | |
| 14485 | { |
| 14486 | TestCompletionCallback callback; |
| 14487 | |
| 14488 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14489 | callback.callback()); |
| 14490 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14491 | |
| 14492 | rv = callback.WaitForResult(); |
| 14493 | EXPECT_EQ(OK, rv); |
| 14494 | } |
| 14495 | |
| 14496 | response = trans->GetResponseInfo(); |
| 14497 | ASSERT_TRUE(response); |
| 14498 | ASSERT_TRUE(response->headers.get()); |
| 14499 | |
| 14500 | EXPECT_EQ(101, response->headers->response_code()); |
| 14501 | |
| 14502 | trans.reset(); |
| 14503 | session->CloseAllConnections(); |
| 14504 | } |
| 14505 | |
| 14506 | // Verify that proxy headers are not sent to the destination server when |
| 14507 | // establishing a tunnel for an insecure WebSocket connection. |
| 14508 | // This requires the authentication info to be injected into the auth cache |
| 14509 | // due to crbug.com/395064 |
| 14510 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14511 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14512 | HttpRequestInfo request; |
| 14513 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14514 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14515 | AddWebSocketHeaders(&request.extra_headers); |
| 14516 | |
| 14517 | // Configure against proxy server "myproxy:70". |
| 14518 | session_deps_.proxy_service.reset( |
| 14519 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14520 | |
| 14521 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14522 | |
| 14523 | MockWrite data_writes[] = { |
| 14524 | // Try to establish a tunnel for the WebSocket connection, with |
| 14525 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14526 | // they cannot and will not use the same TCP/IP connection as the |
| 14527 | // preflight HTTP request. |
| 14528 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14530 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14531 | "Proxy-Connection: keep-alive\r\n" |
| 14532 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14533 | |
| 14534 | MockWrite( |
| 14535 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14536 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14537 | "Connection: Upgrade\r\n" |
| 14538 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14539 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14540 | "Sec-WebSocket-Version: 13\r\n" |
| 14541 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14542 | }; |
| 14543 | |
| 14544 | MockRead data_reads[] = { |
| 14545 | // HTTP CONNECT with credentials. |
| 14546 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14547 | |
| 14548 | // WebSocket connection established inside tunnel. |
| 14549 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14550 | MockRead("Upgrade: websocket\r\n"), |
| 14551 | MockRead("Connection: Upgrade\r\n"), |
| 14552 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14553 | }; |
| 14554 | |
| 14555 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14556 | arraysize(data_writes)); |
| 14557 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14558 | |
| 14559 | session->http_auth_cache()->Add( |
| 14560 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14561 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14562 | |
| 14563 | scoped_ptr<HttpTransaction> trans( |
| 14564 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14565 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14566 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14567 | &websocket_stream_create_helper); |
| 14568 | |
| 14569 | TestCompletionCallback callback; |
| 14570 | |
| 14571 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14572 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14573 | |
| 14574 | rv = callback.WaitForResult(); |
| 14575 | EXPECT_EQ(OK, rv); |
| 14576 | |
| 14577 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14578 | ASSERT_TRUE(response); |
| 14579 | ASSERT_TRUE(response->headers.get()); |
| 14580 | |
| 14581 | EXPECT_EQ(101, response->headers->response_code()); |
| 14582 | |
| 14583 | trans.reset(); |
| 14584 | session->CloseAllConnections(); |
| 14585 | } |
| 14586 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14587 | } // namespace net |