[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 35 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 37 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 38 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 39 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 40 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 41 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 42 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 81 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 82 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 84 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 85 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 87 | using base::ASCIIToUTF16; |
| 88 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 89 | //----------------------------------------------------------------------------- |
| 90 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 91 | namespace net { |
| 92 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 93 | namespace { |
| 94 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 95 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 96 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 97 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 98 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 99 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 100 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 101 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 102 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 103 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 104 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 105 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 106 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 107 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 108 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 109 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 110 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 111 | } |
| 112 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 113 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 114 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 115 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 116 | } |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 119 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 120 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 123 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 124 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 125 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 126 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | if (!params) |
| 128 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 129 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 130 | if (!params->GetList("headers", &header_list)) |
| 131 | return false; |
| 132 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 133 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 134 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 139 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 144 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 145 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
| 150 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 152 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 154 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 158 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 159 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 161 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 164 | |
| 165 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 166 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 169 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 171 | load_timing_info.send_start); |
| 172 | |
| 173 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 175 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 177 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 178 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 182 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
| 189 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 191 | load_timing_info.proxy_resolve_end); |
| 192 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 193 | load_timing_info.send_start); |
| 194 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 203 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | int connect_timing_flags) { |
| 206 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | |
| 209 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 211 | load_timing_info.proxy_resolve_end); |
| 212 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 213 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 214 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 215 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 217 | load_timing_info.send_start); |
| 218 | |
| 219 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 221 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 223 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 225 | } |
| 226 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 227 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 228 | headers->SetHeader("Connection", "Upgrade"); |
| 229 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 230 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 231 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 232 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 233 | } |
| 234 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 235 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 236 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 237 | } |
| 238 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 239 | } // namespace |
| 240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 241 | class HttpNetworkTransactionTest |
| 242 | : public PlatformTest, |
| 243 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 245 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 246 | // Important to restore the per-pool limit first, since the pool limit must |
| 247 | // always be greater than group limit, and the tests reduce both limits. |
| 248 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 250 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 251 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 252 | } |
| 253 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 254 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 255 | HttpNetworkTransactionTest() |
| 256 | : spdy_util_(GetParam()), |
| 257 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 258 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 260 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 261 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 262 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 263 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 264 | struct SimpleGetHelperResult { |
| 265 | int rv; |
| 266 | std::string status_line; |
| 267 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 268 | int64_t total_received_bytes; |
| 269 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 270 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 271 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 272 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 273 | }; |
| 274 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 275 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 276 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 277 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 278 | } |
| 279 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 280 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 281 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 282 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 283 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 284 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 285 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 286 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 287 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 288 | } |
| 289 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 290 | const char* GetAlternateProtocolFromParam() { |
| 291 | return |
| 292 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 293 | } |
| 294 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 295 | std::string GetAlternativeServiceHttpHeader() { |
| 296 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 297 | "=\"www.example.com:443\"\r\n"; |
| 298 | } |
| 299 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 300 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 301 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 302 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 305 | // Either |write_failure| specifies a write failure or |read_failure| |
| 306 | // specifies a read failure when using a reused socket. In either case, the |
| 307 | // failure should cause the network transaction to resend the request, and the |
| 308 | // other argument should be NULL. |
| 309 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 310 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 311 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 312 | // Either |write_failure| specifies a write failure or |read_failure| |
| 313 | // specifies a read failure when using a reused socket. In either case, the |
| 314 | // failure should cause the network transaction to resend the request, and the |
| 315 | // other argument should be NULL. |
| 316 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 317 | const MockRead* read_failure, |
| 318 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 319 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 320 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 321 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 322 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 323 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 324 | HttpRequestInfo request; |
| 325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 326 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 327 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 328 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 329 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 330 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 332 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 334 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 335 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 336 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 337 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 339 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 340 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 341 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 342 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 344 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 345 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 346 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 347 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 348 | |
| 349 | // Even in the failure cases that use this function, connections are always |
| 350 | // successfully established before the error. |
| 351 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 352 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 353 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 354 | if (out.rv != OK) |
| 355 | return out; |
| 356 | |
| 357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 358 | // Can't use ASSERT_* inside helper functions like this, so |
| 359 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 360 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 361 | out.rv = ERR_UNEXPECTED; |
| 362 | return out; |
| 363 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 364 | out.status_line = response->headers->GetStatusLine(); |
| 365 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 366 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 367 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 368 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 369 | bool got_endpoint = |
| 370 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 371 | EXPECT_EQ(got_endpoint, |
| 372 | out.remote_endpoint_after_start.address().size() > 0); |
| 373 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 374 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 375 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 376 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 377 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 378 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 379 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 380 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 381 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 382 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 383 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 384 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 385 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 386 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 387 | std::string line; |
| 388 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 389 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 390 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 391 | HttpRequestHeaders request_headers; |
| 392 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 393 | std::string value; |
| 394 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 395 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 396 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 397 | EXPECT_EQ("keep-alive", value); |
| 398 | |
| 399 | std::string response_headers; |
| 400 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 401 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 402 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 403 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 404 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 405 | // The total number of sent bytes should not have changed. |
| 406 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 407 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 408 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 409 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 410 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 411 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 412 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 413 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 414 | MockWrite data_writes[] = { |
| 415 | MockWrite("GET / HTTP/1.1\r\n" |
| 416 | "Host: www.example.org\r\n" |
| 417 | "Connection: keep-alive\r\n\r\n"), |
| 418 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 419 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 420 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 421 | arraysize(data_writes)); |
| 422 | StaticSocketDataProvider* data[] = {&reads}; |
| 423 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 424 | |
| 425 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 426 | out.total_sent_bytes); |
| 427 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 430 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 431 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 432 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 433 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 434 | |
| 435 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 436 | |
| 437 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 438 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 439 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 440 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 441 | |
| 442 | // Original socket limits. Some tests set these. Safest to always restore |
| 443 | // them once each test has been run. |
| 444 | int old_max_group_sockets_; |
| 445 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 446 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 447 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 448 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 449 | HttpNetworkTransactionTest, |
| 450 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 451 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 452 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 453 | namespace { |
| 454 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 455 | class BeforeNetworkStartHandler { |
| 456 | public: |
| 457 | explicit BeforeNetworkStartHandler(bool defer) |
| 458 | : defer_on_before_network_start_(defer), |
| 459 | observed_before_network_start_(false) {} |
| 460 | |
| 461 | void OnBeforeNetworkStart(bool* defer) { |
| 462 | *defer = defer_on_before_network_start_; |
| 463 | observed_before_network_start_ = true; |
| 464 | } |
| 465 | |
| 466 | bool observed_before_network_start() const { |
| 467 | return observed_before_network_start_; |
| 468 | } |
| 469 | |
| 470 | private: |
| 471 | const bool defer_on_before_network_start_; |
| 472 | bool observed_before_network_start_; |
| 473 | |
| 474 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 475 | }; |
| 476 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 477 | class BeforeProxyHeadersSentHandler { |
| 478 | public: |
| 479 | BeforeProxyHeadersSentHandler() |
| 480 | : observed_before_proxy_headers_sent_(false) {} |
| 481 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 482 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 483 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 484 | observed_before_proxy_headers_sent_ = true; |
| 485 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 486 | } |
| 487 | |
| 488 | bool observed_before_proxy_headers_sent() const { |
| 489 | return observed_before_proxy_headers_sent_; |
| 490 | } |
| 491 | |
| 492 | std::string observed_proxy_server_uri() const { |
| 493 | return observed_proxy_server_uri_; |
| 494 | } |
| 495 | |
| 496 | private: |
| 497 | bool observed_before_proxy_headers_sent_; |
| 498 | std::string observed_proxy_server_uri_; |
| 499 | |
| 500 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 501 | }; |
| 502 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 503 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 504 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 505 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 506 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 507 | const int sizeof_row = strlen(row); |
| 508 | const int num_rows = static_cast<int>( |
| 509 | ceil(static_cast<float>(size) / sizeof_row)); |
| 510 | const int sizeof_data = num_rows * sizeof_row; |
| 511 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 512 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 513 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 514 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 515 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 516 | } |
| 517 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 518 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 519 | // Alternative functions that eliminate randomness and dependency on the local |
| 520 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 521 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 522 | static const uint8 bytes[] = { |
| 523 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 524 | }; |
| 525 | static size_t current_byte = 0; |
| 526 | for (size_t i = 0; i < n; ++i) { |
| 527 | output[i] = bytes[current_byte++]; |
| 528 | current_byte %= arraysize(bytes); |
| 529 | } |
| 530 | } |
| 531 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 532 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 533 | static const uint8 bytes[] = { |
| 534 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 535 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 536 | }; |
| 537 | static size_t current_byte = 0; |
| 538 | for (size_t i = 0; i < n; ++i) { |
| 539 | output[i] = bytes[current_byte++]; |
| 540 | current_byte %= arraysize(bytes); |
| 541 | } |
| 542 | } |
| 543 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 544 | std::string MockGetHostName() { |
| 545 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 546 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 547 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 548 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 549 | template<typename ParentPool> |
| 550 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 551 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 552 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 553 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 554 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 555 | const std::string last_group_name_received() const { |
| 556 | return last_group_name_; |
| 557 | } |
| 558 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 559 | int RequestSocket(const std::string& group_name, |
| 560 | const void* socket_params, |
| 561 | RequestPriority priority, |
| 562 | ClientSocketHandle* handle, |
| 563 | const CompletionCallback& callback, |
| 564 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 565 | last_group_name_ = group_name; |
| 566 | return ERR_IO_PENDING; |
| 567 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 568 | void CancelRequest(const std::string& group_name, |
| 569 | ClientSocketHandle* handle) override {} |
| 570 | void ReleaseSocket(const std::string& group_name, |
| 571 | scoped_ptr<StreamSocket> socket, |
| 572 | int id) override {} |
| 573 | void CloseIdleSockets() override {} |
| 574 | int IdleSocketCount() const override { return 0; } |
| 575 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 576 | return 0; |
| 577 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 578 | LoadState GetLoadState(const std::string& group_name, |
| 579 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 580 | return LOAD_STATE_IDLE; |
| 581 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 582 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 583 | return base::TimeDelta(); |
| 584 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 585 | |
| 586 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 587 | std::string last_group_name_; |
| 588 | }; |
| 589 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 590 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 591 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 592 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 593 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 594 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 595 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 596 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 597 | CaptureGroupNameSSLSocketPool; |
| 598 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 599 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 600 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 601 | HostResolver* host_resolver, |
| 602 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 603 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 604 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 605 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 606 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 607 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 608 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 609 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 610 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 611 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 612 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 613 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 614 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 615 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 616 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 617 | : SSLClientSocketPool(0, |
| 618 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 619 | cert_verifier, |
| 620 | NULL, |
| 621 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 622 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 623 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 624 | std::string(), |
| 625 | NULL, |
| 626 | NULL, |
| 627 | NULL, |
| 628 | NULL, |
| 629 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 630 | NULL) { |
| 631 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 632 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 633 | //----------------------------------------------------------------------------- |
| 634 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 635 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 636 | // configured for common cases. |
| 637 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 638 | if (!auth_challenge) |
| 639 | return false; |
| 640 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 641 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 642 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 643 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 648 | if (!auth_challenge) |
| 649 | return false; |
| 650 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 651 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 652 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 653 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 658 | if (!auth_challenge) |
| 659 | return false; |
| 660 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 661 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 662 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 663 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 664 | return true; |
| 665 | } |
| 666 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 667 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 668 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 669 | if (!auth_challenge) |
| 670 | return false; |
| 671 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 672 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 673 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 674 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 675 | return true; |
| 676 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 677 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 678 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 679 | } // namespace |
| 680 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 681 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 682 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 683 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 684 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 685 | } |
| 686 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 687 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 688 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 689 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 690 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 691 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 692 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 693 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 694 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 695 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 696 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 697 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 698 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 699 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 700 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 701 | |
| 702 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 706 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 708 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 710 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 711 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 712 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 713 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 715 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 716 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 717 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 721 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 723 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 726 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 727 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 728 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 730 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 731 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 732 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 736 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 738 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 741 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 742 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 743 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 745 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 746 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 747 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | // Beyond 4 bytes of slop and it should fail to find a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 751 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 753 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 756 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 757 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 758 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 759 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 760 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 761 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 762 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 766 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 767 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 768 | MockRead("\n"), |
| 769 | MockRead("\n"), |
| 770 | MockRead("Q"), |
| 771 | MockRead("J"), |
| 772 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 773 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 775 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 776 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 777 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 779 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 780 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 781 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 785 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 786 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 787 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 789 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 790 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 791 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 792 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 793 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 794 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 795 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 796 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 797 | } |
| 798 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 799 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 800 | // persistent connection. The response should still terminate since a 204 |
| 801 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 802 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 803 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 804 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 805 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 806 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 807 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 808 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 809 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 810 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 811 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 812 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 813 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 814 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 815 | int64_t response_size = reads_size - strlen(junk); |
| 816 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 817 | } |
| 818 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 819 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 820 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 821 | std::string final_chunk = "0\r\n\r\n"; |
| 822 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 823 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 824 | MockRead data_reads[] = { |
| 825 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 826 | MockRead("5\r\nHello\r\n"), |
| 827 | MockRead("1\r\n"), |
| 828 | MockRead(" \r\n"), |
| 829 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 830 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 832 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 835 | EXPECT_EQ(OK, out.rv); |
| 836 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 837 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 838 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 839 | int64_t response_size = reads_size - extra_data.size(); |
| 840 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 841 | } |
| 842 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 843 | // Next tests deal with http://crbug.com/56344. |
| 844 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 845 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 846 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 847 | MockRead data_reads[] = { |
| 848 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 849 | MockRead("Content-Length: 10\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n\r\n"), |
| 851 | }; |
| 852 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 853 | arraysize(data_reads)); |
| 854 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 855 | } |
| 856 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 857 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 858 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 859 | MockRead data_reads[] = { |
| 860 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 861 | MockRead("Content-Length: 5\r\n"), |
| 862 | MockRead("Content-Length: 5\r\n\r\n"), |
| 863 | MockRead("Hello"), |
| 864 | }; |
| 865 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 866 | arraysize(data_reads)); |
| 867 | EXPECT_EQ(OK, out.rv); |
| 868 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 869 | EXPECT_EQ("Hello", out.response_data); |
| 870 | } |
| 871 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 872 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 873 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 874 | // More than 2 dupes. |
| 875 | { |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 878 | MockRead("Content-Length: 5\r\n"), |
| 879 | MockRead("Content-Length: 5\r\n"), |
| 880 | MockRead("Content-Length: 5\r\n\r\n"), |
| 881 | MockRead("Hello"), |
| 882 | }; |
| 883 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 884 | arraysize(data_reads)); |
| 885 | EXPECT_EQ(OK, out.rv); |
| 886 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 887 | EXPECT_EQ("Hello", out.response_data); |
| 888 | } |
| 889 | // HTTP/1.0 |
| 890 | { |
| 891 | MockRead data_reads[] = { |
| 892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 893 | MockRead("Content-Length: 5\r\n"), |
| 894 | MockRead("Content-Length: 5\r\n"), |
| 895 | MockRead("Content-Length: 5\r\n\r\n"), |
| 896 | MockRead("Hello"), |
| 897 | }; |
| 898 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 899 | arraysize(data_reads)); |
| 900 | EXPECT_EQ(OK, out.rv); |
| 901 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 902 | EXPECT_EQ("Hello", out.response_data); |
| 903 | } |
| 904 | // 2 dupes and one mismatched. |
| 905 | { |
| 906 | MockRead data_reads[] = { |
| 907 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 908 | MockRead("Content-Length: 10\r\n"), |
| 909 | MockRead("Content-Length: 10\r\n"), |
| 910 | MockRead("Content-Length: 5\r\n\r\n"), |
| 911 | }; |
| 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
| 914 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 915 | } |
| 916 | } |
| 917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 918 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 919 | MultipleContentLengthHeadersTransferEncoding) { |
| 920 | MockRead data_reads[] = { |
| 921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 922 | MockRead("Content-Length: 666\r\n"), |
| 923 | MockRead("Content-Length: 1337\r\n"), |
| 924 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 925 | MockRead("5\r\nHello\r\n"), |
| 926 | MockRead("1\r\n"), |
| 927 | MockRead(" \r\n"), |
| 928 | MockRead("5\r\nworld\r\n"), |
| 929 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 931 | }; |
| 932 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 933 | arraysize(data_reads)); |
| 934 | EXPECT_EQ(OK, out.rv); |
| 935 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 936 | EXPECT_EQ("Hello world", out.response_data); |
| 937 | } |
| 938 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 939 | // Next tests deal with http://crbug.com/98895. |
| 940 | |
| 941 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 942 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 943 | MockRead data_reads[] = { |
| 944 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 945 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 946 | MockRead("Content-Length: 5\r\n\r\n"), |
| 947 | MockRead("Hello"), |
| 948 | }; |
| 949 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 950 | arraysize(data_reads)); |
| 951 | EXPECT_EQ(OK, out.rv); |
| 952 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 953 | EXPECT_EQ("Hello", out.response_data); |
| 954 | } |
| 955 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 956 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 957 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 958 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 959 | MockRead data_reads[] = { |
| 960 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 961 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 962 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 963 | MockRead("Content-Length: 5\r\n\r\n"), |
| 964 | MockRead("Hello"), |
| 965 | }; |
| 966 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 967 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 968 | EXPECT_EQ(OK, out.rv); |
| 969 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 970 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 974 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | MockRead data_reads[] = { |
| 976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 977 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 978 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 979 | MockRead("Content-Length: 5\r\n\r\n"), |
| 980 | MockRead("Hello"), |
| 981 | }; |
| 982 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 983 | arraysize(data_reads)); |
| 984 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 985 | } |
| 986 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 987 | // Checks that two identical Location headers result in no error. |
| 988 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 989 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | MockRead data_reads[] = { |
| 991 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 992 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 993 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 994 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 995 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 996 | }; |
| 997 | |
| 998 | HttpRequestInfo request; |
| 999 | request.method = "GET"; |
| 1000 | request.url = GURL("http://redirect.com/"); |
| 1001 | request.load_flags = 0; |
| 1002 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1003 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1004 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1005 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | |
| 1007 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1008 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1010 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1012 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1014 | |
| 1015 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1016 | |
| 1017 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1018 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1019 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1020 | std::string url; |
| 1021 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1022 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1023 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1026 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1027 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1030 | MockRead("Location: http://good.com/\r\n"), |
| 1031 | MockRead("Location: http://evil.com/\r\n"), |
| 1032 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1033 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1034 | }; |
| 1035 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1036 | arraysize(data_reads)); |
| 1037 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1038 | } |
| 1039 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1040 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1041 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1042 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1043 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1044 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1045 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1046 | request.load_flags = 0; |
| 1047 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1048 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1049 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1051 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1052 | trans->SetBeforeProxyHeadersSentCallback( |
| 1053 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1054 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1055 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1056 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1057 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1058 | "Host: www.example.org\r\n" |
| 1059 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1060 | }; |
| 1061 | MockRead data_reads1[] = { |
| 1062 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1063 | MockRead("Server: Blah\r\n"), |
| 1064 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1065 | |
| 1066 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1067 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | }; |
| 1069 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1070 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1071 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1074 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1076 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1077 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1078 | |
| 1079 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1080 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1081 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1083 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | |
| 1085 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1086 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1087 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1088 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1089 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1090 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1091 | |
| 1092 | std::string server_header; |
| 1093 | void* iter = NULL; |
| 1094 | bool has_server_header = response->headers->EnumerateHeader( |
| 1095 | &iter, "Server", &server_header); |
| 1096 | EXPECT_TRUE(has_server_header); |
| 1097 | EXPECT_EQ("Blah", server_header); |
| 1098 | |
| 1099 | // Reading should give EOF right away, since there is no message body |
| 1100 | // (despite non-zero content-length). |
| 1101 | std::string response_data; |
| 1102 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1103 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1104 | EXPECT_EQ("", response_data); |
| 1105 | } |
| 1106 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1107 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1108 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1109 | |
| 1110 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1111 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1112 | MockRead("hello"), |
| 1113 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1114 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1115 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1116 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1117 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1118 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1119 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1120 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1121 | "hello", "world" |
| 1122 | }; |
| 1123 | |
| 1124 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1125 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1127 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1128 | request.load_flags = 0; |
| 1129 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1130 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1133 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1135 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1137 | |
| 1138 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1139 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1140 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1141 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1142 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1144 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1146 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1147 | |
| 1148 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1149 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1150 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1151 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1155 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1156 | ScopedVector<UploadElementReader> element_readers; |
| 1157 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1158 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1159 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1160 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | request.method = "POST"; |
| 1162 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1163 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | request.load_flags = 0; |
| 1165 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1166 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1167 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1169 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1171 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1172 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1173 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1174 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1179 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1183 | |
| 1184 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1185 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1186 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1187 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1188 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1190 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1191 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | |
| 1193 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1194 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1195 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1196 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1199 | // This test is almost the same as Ignores100 above, but the response contains |
| 1200 | // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1201 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1202 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1203 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1204 | request.method = "GET"; |
| 1205 | request.url = GURL("http://www.foo.com/"); |
| 1206 | request.load_flags = 0; |
| 1207 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1208 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1209 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1211 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1212 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1213 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1214 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1215 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1217 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1218 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1221 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1223 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1225 | |
| 1226 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1227 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1228 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1229 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1230 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1231 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1232 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1233 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1234 | |
| 1235 | std::string response_data; |
| 1236 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1237 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1238 | EXPECT_EQ("hello world", response_data); |
| 1239 | } |
| 1240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1241 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1242 | HttpRequestInfo request; |
| 1243 | request.method = "POST"; |
| 1244 | request.url = GURL("http://www.foo.com/"); |
| 1245 | request.load_flags = 0; |
| 1246 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1247 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1248 | scoped_ptr<HttpTransaction> trans( |
| 1249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1250 | |
| 1251 | MockRead data_reads[] = { |
| 1252 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1253 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1254 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1255 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1256 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1257 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1258 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1259 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1260 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1261 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1262 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1263 | rv = callback.WaitForResult(); |
| 1264 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1266 | std::string response_data; |
| 1267 | rv = ReadTransaction(trans.get(), &response_data); |
| 1268 | EXPECT_EQ(OK, rv); |
| 1269 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1270 | } |
| 1271 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1272 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1273 | HttpRequestInfo request; |
| 1274 | request.method = "POST"; |
| 1275 | request.url = GURL("http://www.foo.com/"); |
| 1276 | request.load_flags = 0; |
| 1277 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1278 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1279 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1281 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1282 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1283 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1284 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1288 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1290 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1292 | |
| 1293 | rv = callback.WaitForResult(); |
| 1294 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1295 | } |
| 1296 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1297 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1298 | const MockWrite* write_failure, |
| 1299 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1300 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | request.method = "GET"; |
| 1302 | request.url = GURL("http://www.foo.com/"); |
| 1303 | request.load_flags = 0; |
| 1304 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1305 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1306 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1307 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1308 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1309 | // Written data for successfully sending both requests. |
| 1310 | MockWrite data1_writes[] = { |
| 1311 | MockWrite("GET / HTTP/1.1\r\n" |
| 1312 | "Host: www.foo.com\r\n" |
| 1313 | "Connection: keep-alive\r\n\r\n"), |
| 1314 | MockWrite("GET / HTTP/1.1\r\n" |
| 1315 | "Host: www.foo.com\r\n" |
| 1316 | "Connection: keep-alive\r\n\r\n") |
| 1317 | }; |
| 1318 | |
| 1319 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1321 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1322 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1323 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1325 | |
| 1326 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1327 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1328 | data1_writes[1] = *write_failure; |
| 1329 | } else { |
| 1330 | ASSERT_TRUE(read_failure); |
| 1331 | data1_reads[2] = *read_failure; |
| 1332 | } |
| 1333 | |
| 1334 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1335 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
| 1338 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1339 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1340 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1341 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1343 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1346 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | "hello", "world" |
| 1348 | }; |
| 1349 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1350 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1354 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1357 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
| 1360 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1361 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1363 | LoadTimingInfo load_timing_info; |
| 1364 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1365 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1366 | if (i == 0) { |
| 1367 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1368 | } else { |
| 1369 | // The second request should be using a new socket. |
| 1370 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1371 | } |
| 1372 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1374 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1376 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1380 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1381 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1382 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | } |
| 1384 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1385 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1386 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1387 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1388 | const MockRead* read_failure, |
| 1389 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1390 | HttpRequestInfo request; |
| 1391 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1392 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1393 | request.load_flags = 0; |
| 1394 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1395 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1396 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1397 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1398 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1399 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1400 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1401 | if (use_spdy) { |
| 1402 | ssl1.SetNextProto(GetParam()); |
| 1403 | ssl2.SetNextProto(GetParam()); |
| 1404 | } |
| 1405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1407 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1408 | // SPDY versions of the request and response. |
| 1409 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1410 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1411 | scoped_ptr<SpdyFrame> spdy_response( |
| 1412 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1413 | scoped_ptr<SpdyFrame> spdy_data( |
| 1414 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1415 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1416 | // HTTP/1.1 versions of the request and response. |
| 1417 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1418 | "Host: www.foo.com\r\n" |
| 1419 | "Connection: keep-alive\r\n\r\n"; |
| 1420 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1421 | const char kHttpData[] = "hello"; |
| 1422 | |
| 1423 | std::vector<MockRead> data1_reads; |
| 1424 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1425 | if (write_failure) { |
| 1426 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1427 | data1_writes.push_back(*write_failure); |
| 1428 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1429 | } else { |
| 1430 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1431 | if (use_spdy) { |
| 1432 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1433 | } else { |
| 1434 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1435 | } |
| 1436 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1439 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1440 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1442 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1443 | std::vector<MockRead> data2_reads; |
| 1444 | std::vector<MockWrite> data2_writes; |
| 1445 | |
| 1446 | if (use_spdy) { |
| 1447 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1448 | |
| 1449 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1450 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1451 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1452 | } else { |
| 1453 | data2_writes.push_back( |
| 1454 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1455 | |
| 1456 | data2_reads.push_back( |
| 1457 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1458 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1459 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1460 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1461 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1462 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1463 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1464 | |
| 1465 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1466 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1468 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1469 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1470 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1471 | // Wait for the preconnect to complete. |
| 1472 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1473 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1474 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1475 | |
| 1476 | // Make the request. |
| 1477 | TestCompletionCallback callback; |
| 1478 | |
| 1479 | scoped_ptr<HttpTransaction> trans( |
| 1480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1481 | |
| 1482 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1484 | |
| 1485 | rv = callback.WaitForResult(); |
| 1486 | EXPECT_EQ(OK, rv); |
| 1487 | |
| 1488 | LoadTimingInfo load_timing_info; |
| 1489 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1490 | TestLoadTimingNotReused( |
| 1491 | load_timing_info, |
| 1492 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1493 | |
| 1494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1495 | ASSERT_TRUE(response != NULL); |
| 1496 | |
| 1497 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1498 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1499 | |
| 1500 | std::string response_data; |
| 1501 | rv = ReadTransaction(trans.get(), &response_data); |
| 1502 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1503 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | } |
| 1505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1506 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1507 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1508 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1509 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1510 | } |
| 1511 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1512 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1513 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1514 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1515 | } |
| 1516 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1517 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1518 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1519 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1520 | } |
| 1521 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1522 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1523 | // if the socket was a reused keep alive socket. |
| 1524 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1525 | MockRead read_failure(SYNCHRONOUS, |
| 1526 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1527 | "Connection: Keep-Alive\r\n" |
| 1528 | "Content-Length: 6\r\n\r\n" |
| 1529 | "Pickle"); |
| 1530 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1531 | } |
| 1532 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1533 | TEST_P(HttpNetworkTransactionTest, |
| 1534 | PreconnectErrorNotConnectedOnWrite) { |
| 1535 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1536 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1540 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1541 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1545 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1546 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1547 | } |
| 1548 | |
| 1549 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1550 | MockRead read_failure(ASYNC, OK); // EOF |
| 1551 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1552 | } |
| 1553 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1554 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1555 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1556 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1557 | MockRead read_failure(SYNCHRONOUS, |
| 1558 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1559 | "Connection: Keep-Alive\r\n" |
| 1560 | "Content-Length: 6\r\n\r\n" |
| 1561 | "Pickle"); |
| 1562 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1563 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1564 | } |
| 1565 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1566 | TEST_P(HttpNetworkTransactionTest, |
| 1567 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1568 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1569 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1573 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1574 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1575 | } |
| 1576 | |
| 1577 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1578 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1579 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1580 | } |
| 1581 | |
| 1582 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1583 | MockRead read_failure(ASYNC, OK); // EOF |
| 1584 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1585 | } |
| 1586 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1587 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1588 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1590 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1591 | request.load_flags = 0; |
| 1592 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1593 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1594 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1596 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1597 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1598 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1599 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1600 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1602 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1603 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1606 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1608 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1610 | |
| 1611 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1612 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1613 | |
| 1614 | IPEndPoint endpoint; |
| 1615 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1616 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | // What do various browsers do when the server closes a non-keepalive |
| 1620 | // connection without sending any response header or body? |
| 1621 | // |
| 1622 | // IE7: error page |
| 1623 | // Safari 3.1.2 (Windows): error page |
| 1624 | // Firefox 3.0.1: blank page |
| 1625 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1626 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1627 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1628 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1629 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1630 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1631 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1632 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1633 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1634 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1635 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1636 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1637 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1639 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1640 | // Test that network access can be deferred and resumed. |
| 1641 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1642 | HttpRequestInfo request; |
| 1643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1644 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1645 | request.load_flags = 0; |
| 1646 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1647 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1648 | scoped_ptr<HttpTransaction> trans( |
| 1649 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1650 | |
| 1651 | // Defer on OnBeforeNetworkStart. |
| 1652 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1653 | trans->SetBeforeNetworkStartCallback( |
| 1654 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1655 | base::Unretained(&net_start_handler))); |
| 1656 | |
| 1657 | MockRead data_reads[] = { |
| 1658 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1659 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1660 | MockRead("hello"), |
| 1661 | MockRead(SYNCHRONOUS, 0), |
| 1662 | }; |
| 1663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1665 | |
| 1666 | TestCompletionCallback callback; |
| 1667 | |
| 1668 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1670 | base::MessageLoop::current()->RunUntilIdle(); |
| 1671 | |
| 1672 | // Should have deferred for network start. |
| 1673 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1674 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1675 | |
| 1676 | trans->ResumeNetworkStart(); |
| 1677 | rv = callback.WaitForResult(); |
| 1678 | EXPECT_EQ(OK, rv); |
| 1679 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1680 | |
| 1681 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1682 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1683 | if (rv == ERR_IO_PENDING) |
| 1684 | rv = callback.WaitForResult(); |
| 1685 | EXPECT_EQ(5, rv); |
| 1686 | trans.reset(); |
| 1687 | } |
| 1688 | |
| 1689 | // Test that network use can be deferred and canceled. |
| 1690 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1691 | HttpRequestInfo request; |
| 1692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1694 | request.load_flags = 0; |
| 1695 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1697 | scoped_ptr<HttpTransaction> trans( |
| 1698 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1699 | |
| 1700 | // Defer on OnBeforeNetworkStart. |
| 1701 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1702 | trans->SetBeforeNetworkStartCallback( |
| 1703 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1704 | base::Unretained(&net_start_handler))); |
| 1705 | |
| 1706 | TestCompletionCallback callback; |
| 1707 | |
| 1708 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1709 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1710 | base::MessageLoop::current()->RunUntilIdle(); |
| 1711 | |
| 1712 | // Should have deferred for network start. |
| 1713 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1714 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1715 | } |
| 1716 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1717 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1718 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1719 | // destructor in such situations. |
| 1720 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1721 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1722 | HttpRequestInfo request; |
| 1723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1724 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1725 | request.load_flags = 0; |
| 1726 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1727 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1730 | |
| 1731 | MockRead data_reads[] = { |
| 1732 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1733 | MockRead("Connection: keep-alive\r\n"), |
| 1734 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1735 | MockRead("hello"), |
| 1736 | MockRead(SYNCHRONOUS, 0), |
| 1737 | }; |
| 1738 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1740 | |
| 1741 | TestCompletionCallback callback; |
| 1742 | |
| 1743 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1745 | |
| 1746 | rv = callback.WaitForResult(); |
| 1747 | EXPECT_EQ(OK, rv); |
| 1748 | |
| 1749 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1750 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | if (rv == ERR_IO_PENDING) |
| 1752 | rv = callback.WaitForResult(); |
| 1753 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1754 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1755 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1756 | |
| 1757 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1758 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1759 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1760 | } |
| 1761 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1762 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | HttpRequestInfo request; |
| 1764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1766 | request.load_flags = 0; |
| 1767 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1768 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1769 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1771 | |
| 1772 | MockRead data_reads[] = { |
| 1773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1774 | MockRead("Connection: keep-alive\r\n"), |
| 1775 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1776 | MockRead(SYNCHRONOUS, 0), |
| 1777 | }; |
| 1778 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1780 | |
| 1781 | TestCompletionCallback callback; |
| 1782 | |
| 1783 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1784 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1785 | |
| 1786 | rv = callback.WaitForResult(); |
| 1787 | EXPECT_EQ(OK, rv); |
| 1788 | |
| 1789 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1790 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1791 | if (rv == ERR_IO_PENDING) |
| 1792 | rv = callback.WaitForResult(); |
| 1793 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1794 | |
| 1795 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1796 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1797 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1798 | } |
| 1799 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1800 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1801 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1802 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1803 | HttpRequestInfo request; |
| 1804 | request.method = "GET"; |
| 1805 | request.url = GURL("http://www.foo.com/"); |
| 1806 | request.load_flags = 0; |
| 1807 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1808 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1809 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1810 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1811 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1812 | // Note that because all these reads happen in the same |
| 1813 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1814 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1815 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1816 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1817 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1818 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1819 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1820 | "Content-Length: 0\r\n\r\n"), |
| 1821 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1822 | "Content-Length: 5\r\n\r\n" |
| 1823 | "hello"), |
| 1824 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1825 | "Content-Length: 0\r\n\r\n"), |
| 1826 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1827 | "Content-Length: 5\r\n\r\n" |
| 1828 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1829 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1830 | MockRead("hello"), |
| 1831 | }; |
| 1832 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1834 | |
| 1835 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1836 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1837 | }; |
| 1838 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1839 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1840 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1841 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1842 | std::string response_lines[kNumUnreadBodies]; |
| 1843 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1844 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1845 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1846 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1851 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1853 | |
| 1854 | rv = callback.WaitForResult(); |
| 1855 | EXPECT_EQ(OK, rv); |
| 1856 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1857 | LoadTimingInfo load_timing_info; |
| 1858 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1859 | if (i == 0) { |
| 1860 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1861 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1862 | } else { |
| 1863 | TestLoadTimingReused(load_timing_info); |
| 1864 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1865 | } |
| 1866 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1867 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1868 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1869 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1870 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1871 | response_lines[i] = response->headers->GetStatusLine(); |
| 1872 | |
| 1873 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1874 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1875 | |
| 1876 | const char* const kStatusLines[] = { |
| 1877 | "HTTP/1.1 204 No Content", |
| 1878 | "HTTP/1.1 205 Reset Content", |
| 1879 | "HTTP/1.1 304 Not Modified", |
| 1880 | "HTTP/1.1 302 Found", |
| 1881 | "HTTP/1.1 302 Found", |
| 1882 | "HTTP/1.1 301 Moved Permanently", |
| 1883 | "HTTP/1.1 301 Moved Permanently", |
| 1884 | }; |
| 1885 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1886 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1887 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1888 | |
| 1889 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1890 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1892 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1893 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1894 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1895 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1897 | rv = callback.WaitForResult(); |
| 1898 | EXPECT_EQ(OK, rv); |
| 1899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1900 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1901 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1903 | std::string response_data; |
| 1904 | rv = ReadTransaction(trans.get(), &response_data); |
| 1905 | EXPECT_EQ(OK, rv); |
| 1906 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1907 | } |
| 1908 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1909 | // Test the request-challenge-retry sequence for basic auth. |
| 1910 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1911 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1912 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1914 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1915 | request.load_flags = 0; |
| 1916 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1917 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1918 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1919 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1920 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1922 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1923 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1924 | MockWrite( |
| 1925 | "GET / HTTP/1.1\r\n" |
| 1926 | "Host: www.example.org\r\n" |
| 1927 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1928 | }; |
| 1929 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1930 | MockRead data_reads1[] = { |
| 1931 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1932 | // Give a couple authenticate options (only the middle one is actually |
| 1933 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1934 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1935 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1936 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1938 | // Large content-length -- won't matter, as connection will be reset. |
| 1939 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1940 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1941 | }; |
| 1942 | |
| 1943 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1944 | // be issuing -- the final header line contains the credentials. |
| 1945 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1946 | MockWrite( |
| 1947 | "GET / HTTP/1.1\r\n" |
| 1948 | "Host: www.example.org\r\n" |
| 1949 | "Connection: keep-alive\r\n" |
| 1950 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1951 | }; |
| 1952 | |
| 1953 | // Lastly, the server responds with the actual content. |
| 1954 | MockRead data_reads2[] = { |
| 1955 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1957 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1959 | }; |
| 1960 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1961 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1962 | data_writes1, arraysize(data_writes1)); |
| 1963 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1964 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1966 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1968 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1970 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1971 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1972 | |
| 1973 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1974 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1975 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1976 | LoadTimingInfo load_timing_info1; |
| 1977 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1978 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1979 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1980 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 1981 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 1982 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1983 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1984 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1986 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1987 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1989 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1991 | rv = trans->RestartWithAuth( |
| 1992 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1994 | |
| 1995 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1996 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1997 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1998 | LoadTimingInfo load_timing_info2; |
| 1999 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2000 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2001 | // The load timing after restart should have a new socket ID, and times after |
| 2002 | // those of the first load timing. |
| 2003 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2004 | load_timing_info2.connect_timing.connect_start); |
| 2005 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2006 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2007 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2008 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2009 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2010 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2011 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2012 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2013 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2014 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2015 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2016 | } |
| 2017 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2018 | // Test the request-challenge-retry sequence for basic auth. |
| 2019 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2020 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2021 | HttpRequestInfo request; |
| 2022 | request.method = "GET"; |
| 2023 | request.url = GURL("http://www.example.org/"); |
| 2024 | request.load_flags = 0; |
| 2025 | |
| 2026 | TestNetLog log; |
| 2027 | MockHostResolver* resolver = new MockHostResolver(); |
| 2028 | session_deps_.net_log = &log; |
| 2029 | session_deps_.host_resolver.reset(resolver); |
| 2030 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2031 | scoped_ptr<HttpTransaction> trans( |
| 2032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2033 | |
| 2034 | resolver->rules()->ClearRules(); |
| 2035 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2036 | |
| 2037 | MockWrite data_writes1[] = { |
| 2038 | MockWrite("GET / HTTP/1.1\r\n" |
| 2039 | "Host: www.example.org\r\n" |
| 2040 | "Connection: keep-alive\r\n\r\n"), |
| 2041 | }; |
| 2042 | |
| 2043 | MockRead data_reads1[] = { |
| 2044 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2045 | // Give a couple authenticate options (only the middle one is actually |
| 2046 | // supported). |
| 2047 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2048 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2049 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2050 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2051 | // Large content-length -- won't matter, as connection will be reset. |
| 2052 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2053 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2054 | }; |
| 2055 | |
| 2056 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2057 | // be issuing -- the final header line contains the credentials. |
| 2058 | MockWrite data_writes2[] = { |
| 2059 | MockWrite("GET / HTTP/1.1\r\n" |
| 2060 | "Host: www.example.org\r\n" |
| 2061 | "Connection: keep-alive\r\n" |
| 2062 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2063 | }; |
| 2064 | |
| 2065 | // Lastly, the server responds with the actual content. |
| 2066 | MockRead data_reads2[] = { |
| 2067 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2069 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2070 | }; |
| 2071 | |
| 2072 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2073 | data_writes1, arraysize(data_writes1)); |
| 2074 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2075 | data_writes2, arraysize(data_writes2)); |
| 2076 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2078 | |
| 2079 | TestCompletionCallback callback1; |
| 2080 | |
| 2081 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2082 | BoundNetLog()))); |
| 2083 | |
| 2084 | LoadTimingInfo load_timing_info1; |
| 2085 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2086 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2087 | |
| 2088 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2089 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2090 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2091 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2092 | |
| 2093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2094 | ASSERT_TRUE(response); |
| 2095 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2096 | |
| 2097 | IPEndPoint endpoint; |
| 2098 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2099 | ASSERT_FALSE(endpoint.address().empty()); |
| 2100 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2101 | |
| 2102 | resolver->rules()->ClearRules(); |
| 2103 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2104 | |
| 2105 | TestCompletionCallback callback2; |
| 2106 | |
| 2107 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2108 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2109 | |
| 2110 | LoadTimingInfo load_timing_info2; |
| 2111 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2112 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2113 | // The load timing after restart should have a new socket ID, and times after |
| 2114 | // those of the first load timing. |
| 2115 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2116 | load_timing_info2.connect_timing.connect_start); |
| 2117 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2118 | |
| 2119 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2120 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2121 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2122 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2123 | |
| 2124 | response = trans->GetResponseInfo(); |
| 2125 | ASSERT_TRUE(response); |
| 2126 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2127 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2128 | |
| 2129 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2130 | ASSERT_FALSE(endpoint.address().empty()); |
| 2131 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2132 | } |
| 2133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2134 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2135 | HttpRequestInfo request; |
| 2136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2137 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2138 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2139 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2140 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2141 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2142 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2143 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2144 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2145 | MockWrite( |
| 2146 | "GET / HTTP/1.1\r\n" |
| 2147 | "Host: www.example.org\r\n" |
| 2148 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2149 | }; |
| 2150 | |
| 2151 | MockRead data_reads[] = { |
| 2152 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2153 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2154 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2155 | // Large content-length -- won't matter, as connection will be reset. |
| 2156 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2157 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2158 | }; |
| 2159 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2161 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2163 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2165 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2167 | |
| 2168 | rv = callback.WaitForResult(); |
| 2169 | EXPECT_EQ(0, rv); |
| 2170 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2171 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2172 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2173 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2174 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2175 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2177 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2178 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2179 | } |
| 2180 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2181 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2182 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2183 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2184 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2185 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2186 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | request.load_flags = 0; |
| 2188 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2189 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2190 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2191 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2192 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2193 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2194 | MockWrite( |
| 2195 | "GET / HTTP/1.1\r\n" |
| 2196 | "Host: www.example.org\r\n" |
| 2197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2199 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2200 | // be issuing -- the final header line contains the credentials. |
| 2201 | MockWrite( |
| 2202 | "GET / HTTP/1.1\r\n" |
| 2203 | "Host: www.example.org\r\n" |
| 2204 | "Connection: keep-alive\r\n" |
| 2205 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2206 | }; |
| 2207 | |
| 2208 | MockRead data_reads1[] = { |
| 2209 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2210 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2211 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2212 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2213 | MockRead("Unauthorized\r\n"), |
| 2214 | |
| 2215 | // Lastly, the server responds with the actual content. |
| 2216 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2217 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2218 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2219 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2220 | }; |
| 2221 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2222 | // If there is a regression where we disconnect a Keep-Alive |
| 2223 | // connection during an auth roundtrip, we'll end up reading this. |
| 2224 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2225 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2226 | }; |
| 2227 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2228 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2229 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2231 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2232 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2233 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2235 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2236 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2237 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2239 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2240 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2241 | |
| 2242 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2243 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2244 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2245 | LoadTimingInfo load_timing_info1; |
| 2246 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2247 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2248 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2249 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2250 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2251 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2253 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2255 | rv = trans->RestartWithAuth( |
| 2256 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2258 | |
| 2259 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2260 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2261 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2262 | LoadTimingInfo load_timing_info2; |
| 2263 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2264 | TestLoadTimingReused(load_timing_info2); |
| 2265 | // The load timing after restart should have the same socket ID, and times |
| 2266 | // those of the first load timing. |
| 2267 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2268 | load_timing_info2.send_start); |
| 2269 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2270 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2271 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2272 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2274 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2275 | |
| 2276 | std::string response_data; |
| 2277 | rv = ReadTransaction(trans.get(), &response_data); |
| 2278 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2279 | |
| 2280 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2281 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2282 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2283 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2287 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2288 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2289 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2290 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2291 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2292 | request.load_flags = 0; |
| 2293 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2294 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2295 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2296 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2297 | MockWrite( |
| 2298 | "GET / HTTP/1.1\r\n" |
| 2299 | "Host: www.example.org\r\n" |
| 2300 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2301 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2302 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2303 | // be issuing -- the final header line contains the credentials. |
| 2304 | MockWrite( |
| 2305 | "GET / HTTP/1.1\r\n" |
| 2306 | "Host: www.example.org\r\n" |
| 2307 | "Connection: keep-alive\r\n" |
| 2308 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2309 | }; |
| 2310 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2311 | MockRead data_reads1[] = { |
| 2312 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2313 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2314 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2315 | |
| 2316 | // Lastly, the server responds with the actual content. |
| 2317 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2318 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2319 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2320 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2321 | }; |
| 2322 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2323 | // An incorrect reconnect would cause this to be read. |
| 2324 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2325 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2326 | }; |
| 2327 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2328 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2329 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2330 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2331 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2332 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2333 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2335 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2336 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2337 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2339 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2341 | |
| 2342 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2343 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2344 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2346 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2347 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2349 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2351 | rv = trans->RestartWithAuth( |
| 2352 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2354 | |
| 2355 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2356 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2357 | |
| 2358 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2359 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2360 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2361 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2365 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2366 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2367 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2369 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2370 | request.load_flags = 0; |
| 2371 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2372 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2373 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2374 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2375 | MockWrite( |
| 2376 | "GET / HTTP/1.1\r\n" |
| 2377 | "Host: www.example.org\r\n" |
| 2378 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2379 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2380 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2381 | // be issuing -- the final header line contains the credentials. |
| 2382 | MockWrite( |
| 2383 | "GET / HTTP/1.1\r\n" |
| 2384 | "Host: www.example.org\r\n" |
| 2385 | "Connection: keep-alive\r\n" |
| 2386 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2387 | }; |
| 2388 | |
| 2389 | // Respond with 5 kb of response body. |
| 2390 | std::string large_body_string("Unauthorized"); |
| 2391 | large_body_string.append(5 * 1024, ' '); |
| 2392 | large_body_string.append("\r\n"); |
| 2393 | |
| 2394 | MockRead data_reads1[] = { |
| 2395 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2396 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2397 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2398 | // 5134 = 12 + 5 * 1024 + 2 |
| 2399 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2400 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2401 | |
| 2402 | // Lastly, the server responds with the actual content. |
| 2403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2404 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2405 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2406 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2407 | }; |
| 2408 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2409 | // An incorrect reconnect would cause this to be read. |
| 2410 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2411 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2412 | }; |
| 2413 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2414 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2415 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2416 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2417 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2418 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2421 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2422 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2423 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2425 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2426 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2427 | |
| 2428 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2429 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2430 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2431 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2432 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2433 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2435 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2437 | rv = trans->RestartWithAuth( |
| 2438 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2440 | |
| 2441 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2442 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2443 | |
| 2444 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2445 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2446 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2447 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2451 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2452 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2453 | HttpRequestInfo request; |
| 2454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2455 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2456 | request.load_flags = 0; |
| 2457 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2458 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2459 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2460 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2461 | MockWrite( |
| 2462 | "GET / HTTP/1.1\r\n" |
| 2463 | "Host: www.example.org\r\n" |
| 2464 | "Connection: keep-alive\r\n\r\n"), |
| 2465 | // This simulates the seemingly successful write to a closed connection |
| 2466 | // if the bug is not fixed. |
| 2467 | MockWrite( |
| 2468 | "GET / HTTP/1.1\r\n" |
| 2469 | "Host: www.example.org\r\n" |
| 2470 | "Connection: keep-alive\r\n" |
| 2471 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2472 | }; |
| 2473 | |
| 2474 | MockRead data_reads1[] = { |
| 2475 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2476 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2477 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2478 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2479 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2480 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2481 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2482 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2483 | }; |
| 2484 | |
| 2485 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2486 | // be issuing -- the final header line contains the credentials. |
| 2487 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2488 | MockWrite( |
| 2489 | "GET / HTTP/1.1\r\n" |
| 2490 | "Host: www.example.org\r\n" |
| 2491 | "Connection: keep-alive\r\n" |
| 2492 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2493 | }; |
| 2494 | |
| 2495 | // Lastly, the server responds with the actual content. |
| 2496 | MockRead data_reads2[] = { |
| 2497 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2498 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2499 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2500 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2501 | }; |
| 2502 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2503 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2504 | data_writes1, arraysize(data_writes1)); |
| 2505 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2506 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2508 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2510 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2511 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2512 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2514 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2516 | |
| 2517 | rv = callback1.WaitForResult(); |
| 2518 | EXPECT_EQ(OK, rv); |
| 2519 | |
| 2520 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2521 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2522 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2524 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2526 | rv = trans->RestartWithAuth( |
| 2527 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2528 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2529 | |
| 2530 | rv = callback2.WaitForResult(); |
| 2531 | EXPECT_EQ(OK, rv); |
| 2532 | |
| 2533 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2534 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2535 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2536 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2537 | } |
| 2538 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2539 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2540 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2541 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2542 | HttpRequestInfo request; |
| 2543 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2544 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2545 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2546 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2547 | |
| 2548 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2549 | session_deps_.proxy_service = |
| 2550 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2551 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2552 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2553 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2554 | |
| 2555 | // Since we have proxy, should try to establish tunnel. |
| 2556 | MockWrite data_writes1[] = { |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2557 | MockWrite( |
| 2558 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2559 | "Host: www.example.org\r\n" |
| 2560 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2561 | |
| 2562 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2563 | // be issuing -- the final header line contains the credentials. |
| 2564 | MockWrite( |
| 2565 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2566 | "Host: www.example.org\r\n" |
| 2567 | "Proxy-Connection: keep-alive\r\n" |
| 2568 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2569 | |
| 2570 | MockWrite( |
| 2571 | "GET / HTTP/1.1\r\n" |
| 2572 | "Host: www.example.org\r\n" |
| 2573 | "Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2574 | }; |
| 2575 | |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2576 | // The proxy responds to the connect with a 407, using a persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2577 | // connection. |
| 2578 | MockRead data_reads1[] = { |
| 2579 | // No credentials. |
| 2580 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2581 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2582 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2583 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2584 | |
| 2585 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2586 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2587 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2588 | MockRead(SYNCHRONOUS, "hello"), |
| 2589 | }; |
| 2590 | |
| 2591 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2592 | data_writes1, arraysize(data_writes1)); |
| 2593 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2594 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2596 | |
| 2597 | TestCompletionCallback callback1; |
| 2598 | |
| 2599 | scoped_ptr<HttpTransaction> trans( |
| 2600 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2601 | |
| 2602 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2603 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2604 | |
| 2605 | rv = callback1.WaitForResult(); |
| 2606 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2607 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2608 | log.GetEntries(&entries); |
| 2609 | size_t pos = ExpectLogContainsSomewhere( |
| 2610 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2611 | NetLog::PHASE_NONE); |
| 2612 | ExpectLogContainsSomewhere( |
| 2613 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2614 | NetLog::PHASE_NONE); |
| 2615 | |
| 2616 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2617 | ASSERT_TRUE(response != NULL); |
| 2618 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2619 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2620 | EXPECT_EQ(407, response->headers->response_code()); |
| 2621 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2622 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2623 | |
| 2624 | LoadTimingInfo load_timing_info; |
| 2625 | // CONNECT requests and responses are handled at the connect job level, so |
| 2626 | // the transaction does not yet have a connection. |
| 2627 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2628 | |
| 2629 | TestCompletionCallback callback2; |
| 2630 | |
| 2631 | rv = |
| 2632 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2633 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2634 | |
| 2635 | rv = callback2.WaitForResult(); |
| 2636 | EXPECT_EQ(OK, rv); |
| 2637 | |
| 2638 | response = trans->GetResponseInfo(); |
| 2639 | ASSERT_TRUE(response != NULL); |
| 2640 | |
| 2641 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2642 | EXPECT_EQ(200, response->headers->response_code()); |
| 2643 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2644 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2645 | |
| 2646 | // The password prompt info should not be set. |
| 2647 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2648 | |
| 2649 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2650 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2651 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2652 | |
| 2653 | trans.reset(); |
| 2654 | session->CloseAllConnections(); |
| 2655 | } |
| 2656 | |
| 2657 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2658 | // that requires a restart when setting up an SSL tunnel. |
| 2659 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2660 | HttpRequestInfo request; |
| 2661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2662 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2663 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2664 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2665 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2666 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2667 | session_deps_.proxy_service = |
| 2668 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2669 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2670 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2671 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2672 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2673 | // Since we have proxy, should try to establish tunnel. |
| 2674 | MockWrite data_writes1[] = { |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2675 | MockWrite( |
| 2676 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2677 | "Host: www.example.org\r\n" |
| 2678 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2679 | |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2680 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2681 | // be issuing -- the final header line contains the credentials. |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2682 | MockWrite( |
| 2683 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2684 | "Host: www.example.org\r\n" |
| 2685 | "Proxy-Connection: keep-alive\r\n" |
| 2686 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2687 | |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2688 | MockWrite( |
| 2689 | "GET / HTTP/1.1\r\n" |
| 2690 | "Host: www.example.org\r\n" |
| 2691 | "Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2692 | }; |
| 2693 | |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2694 | // The proxy responds to the connect with a 407, using a persistent |
| 2695 | // connection. |
| 2696 | MockRead data_reads1[] = { |
| 2697 | // No credentials. |
| 2698 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2699 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2700 | MockRead("Proxy-Connection: close\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2701 | |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 2702 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2703 | |
| 2704 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2705 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2706 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2707 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2708 | }; |
| 2709 | |
| 2710 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2711 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2712 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2713 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2716 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2717 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2718 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2719 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2721 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2723 | |
| 2724 | rv = callback1.WaitForResult(); |
| 2725 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2726 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2727 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2728 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2729 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2730 | NetLog::PHASE_NONE); |
| 2731 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2732 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2733 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2734 | NetLog::PHASE_NONE); |
| 2735 | |
| 2736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2737 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2738 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2739 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2740 | EXPECT_EQ(407, response->headers->response_code()); |
| 2741 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2742 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2743 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2744 | LoadTimingInfo load_timing_info; |
| 2745 | // CONNECT requests and responses are handled at the connect job level, so |
| 2746 | // the transaction does not yet have a connection. |
| 2747 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2749 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2751 | rv = trans->RestartWithAuth( |
| 2752 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2754 | |
| 2755 | rv = callback2.WaitForResult(); |
| 2756 | EXPECT_EQ(OK, rv); |
| 2757 | |
| 2758 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2759 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2760 | |
| 2761 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2762 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2763 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2764 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2765 | |
| 2766 | // The password prompt info should not be set. |
| 2767 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2768 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2769 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2770 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2771 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2772 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2773 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2774 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2775 | } |
| 2776 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2777 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2778 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2779 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2780 | HttpRequestInfo request; |
| 2781 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2782 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2783 | // Ensure that proxy authentication is attempted even |
| 2784 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2785 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2786 | |
| 2787 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2788 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2789 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2790 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2791 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2792 | |
| 2793 | scoped_ptr<HttpTransaction> trans( |
| 2794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2795 | |
| 2796 | // Since we have proxy, should try to establish tunnel. |
| 2797 | MockWrite data_writes1[] = { |
| 2798 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2799 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2800 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2801 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2802 | |
| 2803 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2804 | // be issuing -- the final header line contains the credentials. |
| 2805 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2806 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2807 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2808 | "Proxy-Connection: keep-alive\r\n" |
| 2809 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2810 | }; |
| 2811 | |
| 2812 | // The proxy responds to the connect with a 407, using a persistent |
| 2813 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2814 | MockRead data_reads1[] = { |
| 2815 | // No credentials. |
| 2816 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2817 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2818 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2819 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2820 | MockRead("0123456789"), |
| 2821 | |
| 2822 | // Wrong credentials (wrong password). |
| 2823 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2824 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2825 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2826 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2827 | // No response body because the test stops reading here. |
| 2828 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2829 | }; |
| 2830 | |
| 2831 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2832 | data_writes1, arraysize(data_writes1)); |
| 2833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2834 | |
| 2835 | TestCompletionCallback callback1; |
| 2836 | |
| 2837 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2838 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2839 | |
| 2840 | rv = callback1.WaitForResult(); |
| 2841 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2842 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2843 | log.GetEntries(&entries); |
| 2844 | size_t pos = ExpectLogContainsSomewhere( |
| 2845 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2846 | NetLog::PHASE_NONE); |
| 2847 | ExpectLogContainsSomewhere( |
| 2848 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2849 | NetLog::PHASE_NONE); |
| 2850 | |
| 2851 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2852 | ASSERT_TRUE(response); |
| 2853 | ASSERT_TRUE(response->headers); |
| 2854 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2855 | EXPECT_EQ(407, response->headers->response_code()); |
| 2856 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2857 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2858 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2859 | |
| 2860 | TestCompletionCallback callback2; |
| 2861 | |
| 2862 | // Wrong password (should be "bar"). |
| 2863 | rv = |
| 2864 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2866 | |
| 2867 | rv = callback2.WaitForResult(); |
| 2868 | EXPECT_EQ(OK, rv); |
| 2869 | |
| 2870 | response = trans->GetResponseInfo(); |
| 2871 | ASSERT_TRUE(response); |
| 2872 | ASSERT_TRUE(response->headers); |
| 2873 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2874 | EXPECT_EQ(407, response->headers->response_code()); |
| 2875 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2876 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2877 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2878 | |
| 2879 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2880 | // out of scope. |
| 2881 | session->CloseAllConnections(); |
| 2882 | } |
| 2883 | |
| 2884 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2885 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2886 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2887 | HttpRequestInfo request; |
| 2888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2889 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2890 | // Ensure that proxy authentication is attempted even |
| 2891 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2892 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2893 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2894 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2895 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2896 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2897 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2898 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2900 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2901 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2902 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2903 | // Since we have proxy, should try to establish tunnel. |
| 2904 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2905 | MockWrite( |
| 2906 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2907 | "Host: www.example.org\r\n" |
| 2908 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2909 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2910 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2911 | // be issuing -- the final header line contains the credentials. |
| 2912 | MockWrite( |
| 2913 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2914 | "Host: www.example.org\r\n" |
| 2915 | "Proxy-Connection: keep-alive\r\n" |
| 2916 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2917 | }; |
| 2918 | |
| 2919 | // The proxy responds to the connect with a 407, using a persistent |
| 2920 | // connection. |
| 2921 | MockRead data_reads1[] = { |
| 2922 | // No credentials. |
| 2923 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2924 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2925 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2926 | MockRead("0123456789"), |
| 2927 | |
| 2928 | // Wrong credentials (wrong password). |
| 2929 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2930 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2931 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2932 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2933 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2934 | }; |
| 2935 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2936 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2937 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2938 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2940 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2942 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2943 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2944 | |
| 2945 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2946 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2947 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2948 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2949 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2950 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2951 | NetLog::PHASE_NONE); |
| 2952 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2953 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2954 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2955 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2957 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2958 | ASSERT_TRUE(response); |
| 2959 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2960 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2961 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2962 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2963 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2964 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2966 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
| 2968 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2969 | rv = trans->RestartWithAuth( |
| 2970 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2971 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2972 | |
| 2973 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2974 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
| 2976 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2977 | ASSERT_TRUE(response); |
| 2978 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2980 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2981 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2982 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2983 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2984 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2985 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2986 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2987 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2988 | } |
| 2989 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2990 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2991 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2992 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2993 | HttpRequestInfo request; |
| 2994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2995 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2996 | request.load_flags = 0; |
| 2997 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2998 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2999 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3000 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3001 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3002 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3003 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3005 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3006 | // Since we have proxy, should try to establish tunnel. |
| 3007 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3008 | MockWrite( |
| 3009 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3010 | "Host: www.example.org\r\n" |
| 3011 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3012 | }; |
| 3013 | |
| 3014 | // The proxy responds to the connect with a 407. |
| 3015 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3016 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3017 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3018 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3019 | MockRead("0123456789"), // Should not be reached. |
| 3020 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3021 | }; |
| 3022 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3023 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3024 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3025 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3027 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3029 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3030 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3031 | |
| 3032 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3033 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3034 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3035 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3036 | ASSERT_TRUE(response); |
| 3037 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3038 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3039 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3040 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3041 | |
| 3042 | std::string response_data; |
| 3043 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3044 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3045 | |
| 3046 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3047 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3048 | } |
| 3049 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3050 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3051 | // caller when the proxy responds to CONNECT with 407. |
| 3052 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3053 | HttpRequestInfo request; |
| 3054 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3055 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3056 | request.load_flags = 0; |
| 3057 | |
| 3058 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3059 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3060 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3061 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3062 | |
| 3063 | scoped_ptr<HttpTransaction> trans( |
| 3064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3065 | |
| 3066 | // Since we have proxy, should try to establish tunnel. |
| 3067 | MockWrite data_writes[] = { |
| 3068 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3069 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3070 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3071 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3072 | }; |
| 3073 | |
| 3074 | // The proxy responds to the connect with a 407. |
| 3075 | MockRead data_reads[] = { |
| 3076 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3077 | MockRead("X-Foo: bar\r\n"), |
| 3078 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3079 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3080 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3081 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3082 | }; |
| 3083 | |
| 3084 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3085 | arraysize(data_writes)); |
| 3086 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3087 | |
| 3088 | TestCompletionCallback callback; |
| 3089 | |
| 3090 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3092 | |
| 3093 | rv = callback.WaitForResult(); |
| 3094 | EXPECT_EQ(OK, rv); |
| 3095 | |
| 3096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3097 | ASSERT_TRUE(response); |
| 3098 | ASSERT_TRUE(response->headers); |
| 3099 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3100 | EXPECT_EQ(407, response->headers->response_code()); |
| 3101 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3102 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3103 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3104 | |
| 3105 | std::string response_data; |
| 3106 | rv = ReadTransaction(trans.get(), &response_data); |
| 3107 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3108 | |
| 3109 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3110 | session->CloseAllConnections(); |
| 3111 | } |
| 3112 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3113 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3114 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3115 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3116 | HttpRequestInfo request; |
| 3117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3118 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3119 | request.load_flags = 0; |
| 3120 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3121 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3122 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3123 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3124 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3125 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3126 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3127 | MockWrite( |
| 3128 | "GET / HTTP/1.1\r\n" |
| 3129 | "Host: www.example.org\r\n" |
| 3130 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3131 | }; |
| 3132 | |
| 3133 | MockRead data_reads1[] = { |
| 3134 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3135 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3136 | // Large content-length -- won't matter, as connection will be reset. |
| 3137 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3138 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3139 | }; |
| 3140 | |
| 3141 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3142 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3143 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3145 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3147 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3148 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3149 | |
| 3150 | rv = callback.WaitForResult(); |
| 3151 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3152 | } |
| 3153 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3154 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3155 | // through a non-authenticating proxy. The request should fail with |
| 3156 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3157 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3158 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3159 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3160 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3161 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3162 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3163 | HttpRequestInfo request; |
| 3164 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3165 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3166 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3167 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3168 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3169 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3170 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3171 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3172 | // Since we have proxy, should try to establish tunnel. |
| 3173 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3174 | MockWrite( |
| 3175 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3176 | "Host: www.example.org\r\n" |
| 3177 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3178 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3179 | MockWrite( |
| 3180 | "GET / HTTP/1.1\r\n" |
| 3181 | "Host: www.example.org\r\n" |
| 3182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3183 | }; |
| 3184 | |
| 3185 | MockRead data_reads1[] = { |
| 3186 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3187 | |
| 3188 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3189 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3190 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3191 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3192 | }; |
| 3193 | |
| 3194 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3195 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3196 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3197 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3200 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3201 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3202 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3205 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3206 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3207 | |
| 3208 | rv = callback1.WaitForResult(); |
| 3209 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3210 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3211 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3212 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3213 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3214 | NetLog::PHASE_NONE); |
| 3215 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3216 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3217 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3218 | NetLog::PHASE_NONE); |
| 3219 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3220 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3221 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3222 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3223 | HttpRequestInfo request1; |
| 3224 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3225 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3226 | |
| 3227 | HttpRequestInfo request2; |
| 3228 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3229 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3230 | |
| 3231 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3232 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3233 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3234 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3235 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3236 | |
| 3237 | // Since we have proxy, should try to establish tunnel. |
| 3238 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3239 | MockWrite( |
| 3240 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3241 | "Host: www.example.org\r\n" |
| 3242 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3243 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3244 | MockWrite( |
| 3245 | "GET /1 HTTP/1.1\r\n" |
| 3246 | "Host: www.example.org\r\n" |
| 3247 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3248 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3249 | MockWrite( |
| 3250 | "GET /2 HTTP/1.1\r\n" |
| 3251 | "Host: www.example.org\r\n" |
| 3252 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3253 | }; |
| 3254 | |
| 3255 | // The proxy responds to the connect with a 407, using a persistent |
| 3256 | // connection. |
| 3257 | MockRead data_reads1[] = { |
| 3258 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3259 | |
| 3260 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3261 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3262 | MockRead(SYNCHRONOUS, "1"), |
| 3263 | |
| 3264 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3265 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3266 | MockRead(SYNCHRONOUS, "22"), |
| 3267 | }; |
| 3268 | |
| 3269 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3270 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3271 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3272 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3274 | |
| 3275 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3276 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3278 | |
| 3279 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3281 | |
| 3282 | rv = callback1.WaitForResult(); |
| 3283 | EXPECT_EQ(OK, rv); |
| 3284 | |
| 3285 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3286 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3287 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3288 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3289 | |
| 3290 | LoadTimingInfo load_timing_info1; |
| 3291 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3292 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3293 | |
| 3294 | trans1.reset(); |
| 3295 | |
| 3296 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3297 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3299 | |
| 3300 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3301 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3302 | |
| 3303 | rv = callback2.WaitForResult(); |
| 3304 | EXPECT_EQ(OK, rv); |
| 3305 | |
| 3306 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3307 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3308 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3309 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3310 | |
| 3311 | LoadTimingInfo load_timing_info2; |
| 3312 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3313 | TestLoadTimingReused(load_timing_info2); |
| 3314 | |
| 3315 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3316 | |
| 3317 | trans2.reset(); |
| 3318 | session->CloseAllConnections(); |
| 3319 | } |
| 3320 | |
| 3321 | // 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] | 3322 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3323 | HttpRequestInfo request1; |
| 3324 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3325 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3326 | |
| 3327 | HttpRequestInfo request2; |
| 3328 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3329 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3330 | |
| 3331 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3332 | session_deps_.proxy_service = |
| 3333 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3334 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3335 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3336 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3337 | |
| 3338 | // Since we have proxy, should try to establish tunnel. |
| 3339 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3340 | MockWrite( |
| 3341 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3342 | "Host: www.example.org\r\n" |
| 3343 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3344 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3345 | MockWrite( |
| 3346 | "GET /1 HTTP/1.1\r\n" |
| 3347 | "Host: www.example.org\r\n" |
| 3348 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3349 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3350 | MockWrite( |
| 3351 | "GET /2 HTTP/1.1\r\n" |
| 3352 | "Host: www.example.org\r\n" |
| 3353 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3354 | }; |
| 3355 | |
| 3356 | // The proxy responds to the connect with a 407, using a persistent |
| 3357 | // connection. |
| 3358 | MockRead data_reads1[] = { |
| 3359 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3360 | |
| 3361 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3362 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3363 | MockRead(SYNCHRONOUS, "1"), |
| 3364 | |
| 3365 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3366 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3367 | MockRead(SYNCHRONOUS, "22"), |
| 3368 | }; |
| 3369 | |
| 3370 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3371 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3372 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3373 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3375 | |
| 3376 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3377 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3379 | |
| 3380 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3381 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3382 | |
| 3383 | rv = callback1.WaitForResult(); |
| 3384 | EXPECT_EQ(OK, rv); |
| 3385 | |
| 3386 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3387 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3388 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3389 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3390 | |
| 3391 | LoadTimingInfo load_timing_info1; |
| 3392 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3393 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3394 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3395 | |
| 3396 | trans1.reset(); |
| 3397 | |
| 3398 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3399 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3400 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3401 | |
| 3402 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3404 | |
| 3405 | rv = callback2.WaitForResult(); |
| 3406 | EXPECT_EQ(OK, rv); |
| 3407 | |
| 3408 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3409 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3410 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3411 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3412 | |
| 3413 | LoadTimingInfo load_timing_info2; |
| 3414 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3415 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3416 | |
| 3417 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3418 | |
| 3419 | trans2.reset(); |
| 3420 | session->CloseAllConnections(); |
| 3421 | } |
| 3422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3423 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3424 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3425 | HttpRequestInfo request; |
| 3426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3427 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3428 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3429 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3430 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3431 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3432 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3433 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3434 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3435 | // Since we have proxy, should use full url |
| 3436 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3437 | MockWrite( |
| 3438 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3439 | "Host: www.example.org\r\n" |
| 3440 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3441 | }; |
| 3442 | |
| 3443 | MockRead data_reads1[] = { |
| 3444 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3445 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3446 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3447 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3448 | }; |
| 3449 | |
| 3450 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3451 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3452 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3453 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3456 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3457 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3458 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3461 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3463 | |
| 3464 | rv = callback1.WaitForResult(); |
| 3465 | EXPECT_EQ(OK, rv); |
| 3466 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3467 | LoadTimingInfo load_timing_info; |
| 3468 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3469 | TestLoadTimingNotReused(load_timing_info, |
| 3470 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3471 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3472 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3473 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3474 | |
| 3475 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3476 | EXPECT_EQ(200, response->headers->response_code()); |
| 3477 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3478 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3479 | |
| 3480 | // The password prompt info should not be set. |
| 3481 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3482 | } |
| 3483 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3484 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3485 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3486 | HttpRequestInfo request; |
| 3487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3488 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3489 | request.load_flags = 0; |
| 3490 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3491 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3492 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3493 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3494 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3495 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3496 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3497 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3498 | scoped_ptr<SpdyFrame> req( |
| 3499 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3500 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3502 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3503 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3504 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3505 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3506 | }; |
| 3507 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3508 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3509 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3510 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3511 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3512 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3513 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3516 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3517 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3518 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3519 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3521 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3522 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3523 | |
| 3524 | rv = callback1.WaitForResult(); |
| 3525 | EXPECT_EQ(OK, rv); |
| 3526 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3527 | LoadTimingInfo load_timing_info; |
| 3528 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3529 | TestLoadTimingNotReused(load_timing_info, |
| 3530 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3531 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3532 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3533 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3534 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3535 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3536 | |
| 3537 | std::string response_data; |
| 3538 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3539 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3540 | } |
| 3541 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3542 | // Verifies that a session which races and wins against the owning transaction |
| 3543 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3544 | // Regression test for crbug.com/334413. |
| 3545 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3546 | HttpRequestInfo request; |
| 3547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3548 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3549 | request.load_flags = 0; |
| 3550 | |
| 3551 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3552 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3553 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3554 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3555 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3556 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3557 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3558 | scoped_ptr<SpdyFrame> req( |
| 3559 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3560 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3561 | |
| 3562 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3563 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3564 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3565 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3566 | }; |
| 3567 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3568 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3569 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3570 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3571 | |
| 3572 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3573 | ssl.SetNextProto(GetParam()); |
| 3574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3575 | |
| 3576 | TestCompletionCallback callback1; |
| 3577 | |
| 3578 | scoped_ptr<HttpTransaction> trans( |
| 3579 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3580 | |
| 3581 | // Stall the hostname resolution begun by the transaction. |
| 3582 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3583 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3584 | |
| 3585 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3587 | |
| 3588 | // Race a session to the proxy, which completes first. |
| 3589 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3590 | SpdySessionKey key( |
| 3591 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3592 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3593 | CreateSecureSpdySession(session, key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3594 | |
| 3595 | // Unstall the resolution begun by the transaction. |
| 3596 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3597 | session_deps_.host_resolver->ResolveAllPending(); |
| 3598 | |
| 3599 | EXPECT_FALSE(callback1.have_result()); |
| 3600 | rv = callback1.WaitForResult(); |
| 3601 | EXPECT_EQ(OK, rv); |
| 3602 | |
| 3603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3604 | ASSERT_TRUE(response != NULL); |
| 3605 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3606 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3607 | |
| 3608 | std::string response_data; |
| 3609 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3610 | EXPECT_EQ(kUploadData, response_data); |
| 3611 | } |
| 3612 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3613 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3614 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3615 | HttpRequestInfo request; |
| 3616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3617 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3618 | request.load_flags = 0; |
| 3619 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3620 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3621 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3622 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3623 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3624 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3625 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3626 | // The first request will be a bare GET, the second request will be a |
| 3627 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3628 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3629 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3630 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3631 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3632 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3633 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3634 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3635 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3636 | false, |
| 3637 | 3, |
| 3638 | LOWEST, |
| 3639 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3640 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3641 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3642 | }; |
| 3643 | |
| 3644 | // The first response is a 407 proxy authentication challenge, and the second |
| 3645 | // response will be a 200 response since the second request includes a valid |
| 3646 | // Authorization header. |
| 3647 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3648 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3649 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3650 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3651 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3652 | "407 Proxy Authentication Required", |
| 3653 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3654 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3655 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3656 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3657 | scoped_ptr<SpdyFrame> resp_data( |
| 3658 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3659 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3660 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3661 | CreateMockRead(*resp_authentication, 1), |
| 3662 | CreateMockRead(*body_authentication, 2), |
| 3663 | CreateMockRead(*resp_data, 4), |
| 3664 | CreateMockRead(*body_data, 5), |
| 3665 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3666 | }; |
| 3667 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3668 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3669 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3671 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3672 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3673 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3674 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3676 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3677 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3678 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3679 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3681 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3682 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3683 | |
| 3684 | rv = callback1.WaitForResult(); |
| 3685 | EXPECT_EQ(OK, rv); |
| 3686 | |
| 3687 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3688 | |
| 3689 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3690 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3691 | EXPECT_EQ(407, response->headers->response_code()); |
| 3692 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3693 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3694 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3695 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3696 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3697 | rv = trans->RestartWithAuth( |
| 3698 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3699 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3700 | |
| 3701 | rv = callback2.WaitForResult(); |
| 3702 | EXPECT_EQ(OK, rv); |
| 3703 | |
| 3704 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3705 | |
| 3706 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3707 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3708 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3709 | // The password prompt info should not be set. |
| 3710 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3711 | } |
| 3712 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3713 | // 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] | 3714 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3715 | HttpRequestInfo request; |
| 3716 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3717 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3718 | request.load_flags = 0; |
| 3719 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3720 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3721 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3722 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3723 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3724 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3725 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3726 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3727 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3728 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3729 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3730 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3731 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3732 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3733 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3734 | const char get[] = |
| 3735 | "GET / HTTP/1.1\r\n" |
| 3736 | "Host: www.example.org\r\n" |
| 3737 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3738 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3739 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3740 | scoped_ptr<SpdyFrame> conn_resp( |
| 3741 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3742 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3743 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3744 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3745 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3746 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3747 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3748 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3749 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3750 | |
| 3751 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3752 | CreateMockWrite(*connect, 0), |
| 3753 | CreateMockWrite(*wrapped_get, 2), |
| 3754 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3755 | }; |
| 3756 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3757 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3758 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3759 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3760 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3761 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3762 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3763 | }; |
| 3764 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3765 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3766 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3767 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3768 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3769 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3770 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3772 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3775 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3777 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3779 | |
| 3780 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3781 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3782 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3783 | LoadTimingInfo load_timing_info; |
| 3784 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3785 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3786 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3787 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3788 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3789 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3790 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3791 | |
| 3792 | std::string response_data; |
| 3793 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3794 | EXPECT_EQ("1234567890", response_data); |
| 3795 | } |
| 3796 | |
| 3797 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3798 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3799 | HttpRequestInfo request; |
| 3800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3801 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3802 | request.load_flags = 0; |
| 3803 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3804 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3805 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3806 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3807 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3808 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3809 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3810 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3812 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3813 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3814 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3815 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3816 | // fetch https://www.example.org/ via SPDY |
| 3817 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3818 | scoped_ptr<SpdyFrame> get( |
| 3819 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3820 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3821 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3822 | scoped_ptr<SpdyFrame> conn_resp( |
| 3823 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3824 | scoped_ptr<SpdyFrame> get_resp( |
| 3825 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3826 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3827 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3828 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3829 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3830 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3831 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3832 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3833 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3834 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3835 | |
| 3836 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3837 | CreateMockWrite(*connect, 0), |
| 3838 | CreateMockWrite(*wrapped_get, 2), |
| 3839 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3840 | CreateMockWrite(*window_update_body, 7), |
| 3841 | }; |
| 3842 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3843 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3844 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3845 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3846 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3847 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3848 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3849 | }; |
| 3850 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3851 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3852 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3853 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3854 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3855 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3856 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3858 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3859 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3862 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3864 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3866 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3867 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3868 | base::MessageLoop::current()->RunUntilIdle(); |
| 3869 | // Now allow the read of the response to complete. |
| 3870 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3871 | rv = callback1.WaitForResult(); |
| 3872 | EXPECT_EQ(OK, rv); |
| 3873 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3874 | LoadTimingInfo load_timing_info; |
| 3875 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3876 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3877 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3878 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3879 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3880 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3881 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3882 | |
| 3883 | std::string response_data; |
| 3884 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3885 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3889 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3890 | HttpRequestInfo request; |
| 3891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3892 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3893 | request.load_flags = 0; |
| 3894 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3895 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3896 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3897 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3898 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3899 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3900 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3901 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3902 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3903 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3904 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3905 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3906 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3907 | scoped_ptr<SpdyFrame> get( |
| 3908 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3909 | |
| 3910 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3911 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3912 | }; |
| 3913 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3914 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3915 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3916 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3917 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3918 | }; |
| 3919 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3920 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3921 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3922 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3923 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3924 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3925 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3926 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3927 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3928 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3931 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3933 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3934 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3935 | |
| 3936 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3937 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3938 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3939 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3940 | } |
| 3941 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3942 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3943 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3944 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3945 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3946 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3947 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3948 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3949 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3950 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3951 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3952 | |
| 3953 | HttpRequestInfo request1; |
| 3954 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3955 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3956 | request1.load_flags = 0; |
| 3957 | |
| 3958 | HttpRequestInfo request2; |
| 3959 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3960 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3961 | request2.load_flags = 0; |
| 3962 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3963 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3964 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3965 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3966 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3967 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3968 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3969 | // Fetch https://www.example.org/ via HTTP. |
| 3970 | const char get1[] = |
| 3971 | "GET / HTTP/1.1\r\n" |
| 3972 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3973 | "Connection: keep-alive\r\n\r\n"; |
| 3974 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3975 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3976 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3977 | "Content-Length: 1\r\n\r\n"; |
| 3978 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3979 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3980 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3981 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3982 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3983 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3984 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3985 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3986 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3987 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3988 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 3989 | if (GetParam() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3990 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 3991 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3992 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3993 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3994 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3995 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3996 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3997 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3998 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3999 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4000 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4001 | // Fetch https://mail.example.org/ via HTTP. |
| 4002 | const char get2[] = |
| 4003 | "GET / HTTP/1.1\r\n" |
| 4004 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4005 | "Connection: keep-alive\r\n\r\n"; |
| 4006 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4007 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4008 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4009 | "Content-Length: 2\r\n\r\n"; |
| 4010 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4011 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4012 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4013 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4014 | |
| 4015 | MockWrite spdy_writes[] = { |
| 4016 | CreateMockWrite(*connect1, 0), |
| 4017 | CreateMockWrite(*wrapped_get1, 2), |
| 4018 | CreateMockWrite(*connect2, 5), |
| 4019 | CreateMockWrite(*wrapped_get2, 7), |
| 4020 | }; |
| 4021 | |
| 4022 | MockRead spdy_reads[] = { |
| 4023 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4024 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4025 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4026 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4027 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4028 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4029 | MockRead(ASYNC, 0, 10), |
| 4030 | }; |
| 4031 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4032 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4033 | arraysize(spdy_writes)); |
| 4034 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4035 | |
| 4036 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4037 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4039 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4041 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4043 | |
| 4044 | TestCompletionCallback callback; |
| 4045 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4046 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4047 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4048 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4049 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4050 | |
| 4051 | LoadTimingInfo load_timing_info; |
| 4052 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4053 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4054 | |
| 4055 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4056 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4057 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4058 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4059 | |
| 4060 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4061 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4062 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4063 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4064 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4065 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4066 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4067 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4068 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4069 | |
| 4070 | LoadTimingInfo load_timing_info2; |
| 4071 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4072 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4073 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4074 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4075 | |
| 4076 | // The requests should have different IDs, since they each are using their own |
| 4077 | // separate stream. |
| 4078 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4079 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4080 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4081 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4085 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4086 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4087 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4088 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4089 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4090 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4091 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4092 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4093 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4094 | |
| 4095 | HttpRequestInfo request1; |
| 4096 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4097 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4098 | request1.load_flags = 0; |
| 4099 | |
| 4100 | HttpRequestInfo request2; |
| 4101 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4102 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4103 | request2.load_flags = 0; |
| 4104 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4105 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4106 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4107 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4108 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4109 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4111 | // Fetch https://www.example.org/ via HTTP. |
| 4112 | const char get1[] = |
| 4113 | "GET / HTTP/1.1\r\n" |
| 4114 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4115 | "Connection: keep-alive\r\n\r\n"; |
| 4116 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4117 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4118 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4119 | "Content-Length: 1\r\n\r\n"; |
| 4120 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4121 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4122 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4123 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4124 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4125 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4126 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4127 | // Fetch https://www.example.org/2 via HTTP. |
| 4128 | const char get2[] = |
| 4129 | "GET /2 HTTP/1.1\r\n" |
| 4130 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4131 | "Connection: keep-alive\r\n\r\n"; |
| 4132 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4133 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4134 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4135 | "Content-Length: 2\r\n\r\n"; |
| 4136 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4137 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4138 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4139 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4140 | |
| 4141 | MockWrite spdy_writes[] = { |
| 4142 | CreateMockWrite(*connect1, 0), |
| 4143 | CreateMockWrite(*wrapped_get1, 2), |
| 4144 | CreateMockWrite(*wrapped_get2, 5), |
| 4145 | }; |
| 4146 | |
| 4147 | MockRead spdy_reads[] = { |
| 4148 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4149 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4150 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4151 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4152 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4153 | MockRead(ASYNC, 0, 8), |
| 4154 | }; |
| 4155 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4156 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4157 | arraysize(spdy_writes)); |
| 4158 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4159 | |
| 4160 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4161 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4163 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4165 | |
| 4166 | TestCompletionCallback callback; |
| 4167 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4168 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4169 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4170 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4171 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4172 | |
| 4173 | rv = callback.WaitForResult(); |
| 4174 | EXPECT_EQ(OK, rv); |
| 4175 | |
| 4176 | LoadTimingInfo load_timing_info; |
| 4177 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4178 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4179 | |
| 4180 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4181 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4182 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4183 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4184 | |
| 4185 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4186 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4187 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4188 | trans.reset(); |
| 4189 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4190 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4192 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4193 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4194 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4195 | rv = callback.WaitForResult(); |
| 4196 | EXPECT_EQ(OK, rv); |
| 4197 | |
| 4198 | LoadTimingInfo load_timing_info2; |
| 4199 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4200 | TestLoadTimingReused(load_timing_info2); |
| 4201 | |
| 4202 | // The requests should have the same ID. |
| 4203 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4204 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4205 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4209 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4210 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4211 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4212 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4213 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4214 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4215 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4216 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4217 | |
| 4218 | HttpRequestInfo request1; |
| 4219 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4220 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4221 | request1.load_flags = 0; |
| 4222 | |
| 4223 | HttpRequestInfo request2; |
| 4224 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4225 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4226 | request2.load_flags = 0; |
| 4227 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4228 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4229 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4230 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4231 | scoped_ptr<SpdyFrame> get1( |
| 4232 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4233 | scoped_ptr<SpdyFrame> get_resp1( |
| 4234 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4235 | scoped_ptr<SpdyFrame> body1( |
| 4236 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4237 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4238 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4239 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4240 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4241 | scoped_ptr<SpdyFrame> get2( |
| 4242 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4243 | scoped_ptr<SpdyFrame> get_resp2( |
| 4244 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4245 | scoped_ptr<SpdyFrame> body2( |
| 4246 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4247 | |
| 4248 | MockWrite spdy_writes[] = { |
| 4249 | CreateMockWrite(*get1, 0), |
| 4250 | CreateMockWrite(*get2, 3), |
| 4251 | }; |
| 4252 | |
| 4253 | MockRead spdy_reads[] = { |
| 4254 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4255 | CreateMockRead(*body1, 2, ASYNC), |
| 4256 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4257 | CreateMockRead(*body2, 5, ASYNC), |
| 4258 | MockRead(ASYNC, 0, 6), |
| 4259 | }; |
| 4260 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4261 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4262 | arraysize(spdy_writes)); |
| 4263 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4264 | |
| 4265 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4266 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4268 | |
| 4269 | TestCompletionCallback callback; |
| 4270 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4271 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4273 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4274 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4275 | |
| 4276 | LoadTimingInfo load_timing_info; |
| 4277 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4278 | TestLoadTimingNotReused(load_timing_info, |
| 4279 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4280 | |
| 4281 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4282 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4283 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4284 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4285 | |
| 4286 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4287 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4288 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4289 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4290 | // Delete the first request, so the second one can reuse the socket. |
| 4291 | trans.reset(); |
| 4292 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4293 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4295 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4296 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4297 | |
| 4298 | LoadTimingInfo load_timing_info2; |
| 4299 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4300 | TestLoadTimingReused(load_timing_info2); |
| 4301 | |
| 4302 | // The requests should have the same ID. |
| 4303 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4304 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4305 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4306 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4307 | } |
| 4308 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4309 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4310 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4311 | HttpRequestInfo request; |
| 4312 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4313 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4314 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4315 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4316 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4317 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4318 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4319 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4320 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4321 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4322 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4323 | // Since we have proxy, should use full url |
| 4324 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4325 | MockWrite( |
| 4326 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4327 | "Host: www.example.org\r\n" |
| 4328 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4329 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4330 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4331 | // be issuing -- the final header line contains the credentials. |
| 4332 | MockWrite( |
| 4333 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4334 | "Host: www.example.org\r\n" |
| 4335 | "Proxy-Connection: keep-alive\r\n" |
| 4336 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4337 | }; |
| 4338 | |
| 4339 | // The proxy responds to the GET with a 407, using a persistent |
| 4340 | // connection. |
| 4341 | MockRead data_reads1[] = { |
| 4342 | // No credentials. |
| 4343 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4344 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4345 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4346 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4347 | |
| 4348 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4349 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4350 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4351 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4352 | }; |
| 4353 | |
| 4354 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4355 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4356 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4357 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4360 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4361 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4362 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4363 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4365 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4366 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4367 | |
| 4368 | rv = callback1.WaitForResult(); |
| 4369 | EXPECT_EQ(OK, rv); |
| 4370 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4371 | LoadTimingInfo load_timing_info; |
| 4372 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4373 | TestLoadTimingNotReused(load_timing_info, |
| 4374 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4375 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4376 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4377 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4378 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4379 | EXPECT_EQ(407, response->headers->response_code()); |
| 4380 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4381 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4383 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4385 | rv = trans->RestartWithAuth( |
| 4386 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4387 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4388 | |
| 4389 | rv = callback2.WaitForResult(); |
| 4390 | EXPECT_EQ(OK, rv); |
| 4391 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4392 | load_timing_info = LoadTimingInfo(); |
| 4393 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4394 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4395 | TestLoadTimingReused(load_timing_info); |
| 4396 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4397 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4398 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4399 | |
| 4400 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4401 | EXPECT_EQ(200, response->headers->response_code()); |
| 4402 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4403 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4404 | |
| 4405 | // The password prompt info should not be set. |
| 4406 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4407 | } |
| 4408 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4409 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4410 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4411 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4412 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4413 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4414 | request.load_flags = 0; |
| 4415 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4416 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4417 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4418 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4419 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4420 | // Since we have proxy, should try to establish tunnel. |
| 4421 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4422 | MockWrite( |
| 4423 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4424 | "Host: www.example.org\r\n" |
| 4425 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4426 | }; |
| 4427 | |
| 4428 | MockRead data_reads[] = { |
| 4429 | status, |
| 4430 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4431 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4432 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4433 | }; |
| 4434 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4435 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4436 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4439 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4440 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4441 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4446 | |
| 4447 | rv = callback.WaitForResult(); |
| 4448 | EXPECT_EQ(expected_status, rv); |
| 4449 | } |
| 4450 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4451 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4452 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4453 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4454 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4455 | } |
| 4456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4457 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4458 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4459 | } |
| 4460 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4461 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4462 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4463 | } |
| 4464 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4465 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4466 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4467 | } |
| 4468 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4469 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4470 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4471 | } |
| 4472 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4473 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4474 | ConnectStatusHelper( |
| 4475 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4476 | } |
| 4477 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4478 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4479 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4480 | } |
| 4481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4482 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4483 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4484 | } |
| 4485 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4486 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4487 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4488 | } |
| 4489 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4490 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4491 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4492 | } |
| 4493 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4494 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4495 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4496 | } |
| 4497 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4498 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4499 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4500 | } |
| 4501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4502 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4503 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4504 | } |
| 4505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4506 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4507 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4508 | } |
| 4509 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4510 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4511 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4512 | } |
| 4513 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4514 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4515 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4516 | } |
| 4517 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4518 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4519 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4520 | } |
| 4521 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4522 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4523 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4524 | } |
| 4525 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4526 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4527 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4528 | } |
| 4529 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4530 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4531 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4532 | } |
| 4533 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4534 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4535 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4536 | } |
| 4537 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4538 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4539 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4540 | } |
| 4541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4542 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4543 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4544 | } |
| 4545 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4546 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4547 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4548 | } |
| 4549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4550 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4551 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4552 | } |
| 4553 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4554 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4555 | ConnectStatusHelperWithExpectedStatus( |
| 4556 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4557 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4558 | } |
| 4559 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4560 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4561 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4562 | } |
| 4563 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4564 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4565 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4566 | } |
| 4567 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4568 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4569 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4570 | } |
| 4571 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4572 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4573 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4574 | } |
| 4575 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4576 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4577 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4578 | } |
| 4579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4580 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4581 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4582 | } |
| 4583 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4584 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4585 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4586 | } |
| 4587 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4588 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4589 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4590 | } |
| 4591 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4592 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4593 | ConnectStatusHelper( |
| 4594 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4595 | } |
| 4596 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4597 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4598 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4599 | } |
| 4600 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4601 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4602 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4603 | } |
| 4604 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4605 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4606 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4607 | } |
| 4608 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4609 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4610 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4611 | } |
| 4612 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4613 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4614 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4615 | } |
| 4616 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4617 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4618 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4619 | } |
| 4620 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4621 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4622 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4623 | } |
| 4624 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4625 | // Test the flow when both the proxy server AND origin server require |
| 4626 | // authentication. Again, this uses basic auth for both since that is |
| 4627 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4628 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4629 | HttpRequestInfo request; |
| 4630 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4631 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4632 | request.load_flags = 0; |
| 4633 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4634 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4635 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4636 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4637 | |
| 4638 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4640 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4641 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4642 | MockWrite( |
| 4643 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4644 | "Host: www.example.org\r\n" |
| 4645 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4646 | }; |
| 4647 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4648 | MockRead data_reads1[] = { |
| 4649 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4650 | // Give a couple authenticate options (only the middle one is actually |
| 4651 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4652 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4653 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4654 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4655 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4656 | // Large content-length -- won't matter, as connection will be reset. |
| 4657 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4658 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4659 | }; |
| 4660 | |
| 4661 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4662 | // request we should be issuing -- the final header line contains the |
| 4663 | // proxy's credentials. |
| 4664 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4665 | MockWrite( |
| 4666 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4667 | "Host: www.example.org\r\n" |
| 4668 | "Proxy-Connection: keep-alive\r\n" |
| 4669 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4670 | }; |
| 4671 | |
| 4672 | // Now the proxy server lets the request pass through to origin server. |
| 4673 | // The origin server responds with a 401. |
| 4674 | MockRead data_reads2[] = { |
| 4675 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4676 | // Note: We are using the same realm-name as the proxy server. This is |
| 4677 | // completely valid, as realms are unique across hosts. |
| 4678 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4679 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4680 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4681 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4682 | }; |
| 4683 | |
| 4684 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4685 | // the credentials for both the proxy and origin server. |
| 4686 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4687 | MockWrite( |
| 4688 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4689 | "Host: www.example.org\r\n" |
| 4690 | "Proxy-Connection: keep-alive\r\n" |
| 4691 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4692 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4693 | }; |
| 4694 | |
| 4695 | // Lastly we get the desired content. |
| 4696 | MockRead data_reads3[] = { |
| 4697 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4698 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4699 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4700 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4701 | }; |
| 4702 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4703 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4704 | data_writes1, arraysize(data_writes1)); |
| 4705 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4706 | data_writes2, arraysize(data_writes2)); |
| 4707 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4708 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4709 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4710 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4711 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4713 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4715 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4716 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4717 | |
| 4718 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4719 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4720 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4722 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4723 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4725 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4727 | rv = trans->RestartWithAuth( |
| 4728 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4730 | |
| 4731 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4732 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4733 | |
| 4734 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4735 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4736 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4738 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4740 | rv = trans->RestartWithAuth( |
| 4741 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4743 | |
| 4744 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4745 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4746 | |
| 4747 | response = trans->GetResponseInfo(); |
| 4748 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4749 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4750 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4751 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4752 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4753 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4754 | // authorization headers. |
| 4755 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4756 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4757 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4758 | // bytes in the debugger. |
| 4759 | |
| 4760 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4761 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4762 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4763 | request.method = "GET"; |
| 4764 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4765 | |
| 4766 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4767 | // to other auth schemes. |
| 4768 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4769 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4770 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4771 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4772 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4773 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4774 | MockWrite data_writes1[] = { |
| 4775 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4776 | "Host: 172.22.68.17\r\n" |
| 4777 | "Connection: keep-alive\r\n\r\n"), |
| 4778 | }; |
| 4779 | |
| 4780 | MockRead data_reads1[] = { |
| 4781 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4782 | // Negotiate and NTLM are often requested together. However, we only want |
| 4783 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4784 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4785 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4786 | MockRead("Connection: close\r\n"), |
| 4787 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4788 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4789 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4790 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4791 | }; |
| 4792 | |
| 4793 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4794 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4795 | // request we should be issuing -- the final header line contains a Type |
| 4796 | // 1 message. |
| 4797 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4798 | "Host: 172.22.68.17\r\n" |
| 4799 | "Connection: keep-alive\r\n" |
| 4800 | "Authorization: NTLM " |
| 4801 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4802 | |
| 4803 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4804 | // (the credentials for the origin server). The second request continues |
| 4805 | // on the same connection. |
| 4806 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4807 | "Host: 172.22.68.17\r\n" |
| 4808 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4809 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4810 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4811 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4812 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4813 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4814 | }; |
| 4815 | |
| 4816 | MockRead data_reads2[] = { |
| 4817 | // The origin server responds with a Type 2 message. |
| 4818 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4819 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4820 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4821 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4822 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4823 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4824 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4825 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4826 | "BtAAAAAAA=\r\n"), |
| 4827 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4828 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4829 | MockRead("You are not authorized to view this page\r\n"), |
| 4830 | |
| 4831 | // Lastly we get the desired content. |
| 4832 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4833 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4834 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4835 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4836 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4837 | }; |
| 4838 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4839 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4840 | data_writes1, arraysize(data_writes1)); |
| 4841 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4842 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4843 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4844 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4846 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4851 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4853 | |
| 4854 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4855 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4856 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4857 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4858 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4859 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4860 | ASSERT_FALSE(response == NULL); |
| 4861 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4863 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4864 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4865 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4866 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4868 | |
| 4869 | rv = callback2.WaitForResult(); |
| 4870 | EXPECT_EQ(OK, rv); |
| 4871 | |
| 4872 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4873 | |
| 4874 | response = trans->GetResponseInfo(); |
| 4875 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4876 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4878 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4880 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4881 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4882 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4883 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4884 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4885 | |
| 4886 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4887 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4888 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4889 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4890 | } |
| 4891 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4892 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4893 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4894 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4895 | request.method = "GET"; |
| 4896 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4897 | request.load_flags = 0; |
| 4898 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4899 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4900 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4901 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4902 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4903 | MockWrite data_writes1[] = { |
| 4904 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4905 | "Host: 172.22.68.17\r\n" |
| 4906 | "Connection: keep-alive\r\n\r\n"), |
| 4907 | }; |
| 4908 | |
| 4909 | MockRead data_reads1[] = { |
| 4910 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4911 | // Negotiate and NTLM are often requested together. However, we only want |
| 4912 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4913 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4914 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4915 | MockRead("Connection: close\r\n"), |
| 4916 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4917 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4918 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4919 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4920 | }; |
| 4921 | |
| 4922 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4923 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4924 | // request we should be issuing -- the final header line contains a Type |
| 4925 | // 1 message. |
| 4926 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4927 | "Host: 172.22.68.17\r\n" |
| 4928 | "Connection: keep-alive\r\n" |
| 4929 | "Authorization: NTLM " |
| 4930 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4931 | |
| 4932 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4933 | // (the credentials for the origin server). The second request continues |
| 4934 | // on the same connection. |
| 4935 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4936 | "Host: 172.22.68.17\r\n" |
| 4937 | "Connection: keep-alive\r\n" |
| 4938 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4939 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4940 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4941 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4942 | "4Ww7b7E=\r\n\r\n"), |
| 4943 | }; |
| 4944 | |
| 4945 | MockRead data_reads2[] = { |
| 4946 | // The origin server responds with a Type 2 message. |
| 4947 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4948 | MockRead("WWW-Authenticate: NTLM " |
| 4949 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4950 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4951 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4952 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4953 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4954 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4955 | "BtAAAAAAA=\r\n"), |
| 4956 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4957 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4958 | MockRead("You are not authorized to view this page\r\n"), |
| 4959 | |
| 4960 | // Wrong password. |
| 4961 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4962 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4963 | MockRead("Connection: close\r\n"), |
| 4964 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4965 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4966 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4967 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4968 | }; |
| 4969 | |
| 4970 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4971 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4972 | // request we should be issuing -- the final header line contains a Type |
| 4973 | // 1 message. |
| 4974 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4975 | "Host: 172.22.68.17\r\n" |
| 4976 | "Connection: keep-alive\r\n" |
| 4977 | "Authorization: NTLM " |
| 4978 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4979 | |
| 4980 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4981 | // (the credentials for the origin server). The second request continues |
| 4982 | // on the same connection. |
| 4983 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4984 | "Host: 172.22.68.17\r\n" |
| 4985 | "Connection: keep-alive\r\n" |
| 4986 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4987 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4988 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4989 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4990 | "+4MUm7c=\r\n\r\n"), |
| 4991 | }; |
| 4992 | |
| 4993 | MockRead data_reads3[] = { |
| 4994 | // The origin server responds with a Type 2 message. |
| 4995 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4996 | MockRead("WWW-Authenticate: NTLM " |
| 4997 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4998 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4999 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5000 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5001 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5002 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5003 | "BtAAAAAAA=\r\n"), |
| 5004 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5005 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5006 | MockRead("You are not authorized to view this page\r\n"), |
| 5007 | |
| 5008 | // Lastly we get the desired content. |
| 5009 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5010 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5011 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5012 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5014 | }; |
| 5015 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5016 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5017 | data_writes1, arraysize(data_writes1)); |
| 5018 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5019 | data_writes2, arraysize(data_writes2)); |
| 5020 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5021 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5022 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5023 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5024 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5026 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5027 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5028 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5031 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5033 | |
| 5034 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5035 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5036 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5037 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5038 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5039 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5040 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5041 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5043 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5044 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5045 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5046 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5047 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5048 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5049 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5050 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5051 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5052 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5053 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5054 | TestCompletionCallback callback3; |
| 5055 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5056 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5057 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5058 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5059 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5060 | |
| 5061 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5062 | ASSERT_FALSE(response == NULL); |
| 5063 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5065 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5066 | |
| 5067 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5068 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5069 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5071 | |
| 5072 | rv = callback4.WaitForResult(); |
| 5073 | EXPECT_EQ(OK, rv); |
| 5074 | |
| 5075 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5077 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5078 | |
| 5079 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5080 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5082 | |
| 5083 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5084 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5085 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5086 | response = trans->GetResponseInfo(); |
| 5087 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5088 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5089 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5090 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5091 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5092 | // Test reading a server response which has only headers, and no body. |
| 5093 | // After some maximum number of bytes is consumed, the transaction should |
| 5094 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5095 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5096 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5097 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5098 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5099 | request.load_flags = 0; |
| 5100 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5101 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5102 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5103 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5104 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5105 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5106 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5107 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5108 | |
| 5109 | MockRead data_reads[] = { |
| 5110 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5111 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5112 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5113 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5114 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5115 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5116 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5118 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5120 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5122 | |
| 5123 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5124 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5125 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5126 | |
| 5127 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5128 | // establish tunnel. |
| 5129 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5130 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5131 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5132 | HttpRequestInfo request; |
| 5133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5134 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5135 | request.load_flags = 0; |
| 5136 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5137 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5138 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5139 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5140 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5141 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5142 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5144 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5145 | // Since we have proxy, should try to establish tunnel. |
| 5146 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5147 | MockWrite( |
| 5148 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5149 | "Host: www.example.org\r\n" |
| 5150 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5151 | }; |
| 5152 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5153 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5154 | // connection. Usually a proxy would return 501 (not implemented), |
| 5155 | // or 200 (tunnel established). |
| 5156 | MockRead data_reads1[] = { |
| 5157 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5158 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5159 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5160 | }; |
| 5161 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5162 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5163 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5164 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5166 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5167 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5168 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5169 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5170 | |
| 5171 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5172 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5173 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5174 | // Empty the current queue. This is necessary because idle sockets are |
| 5175 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5176 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5177 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5178 | // We now check to make sure the TCPClientSocket was not added back to |
| 5179 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5180 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5181 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5182 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5183 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5184 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5185 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5186 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5187 | // 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] | 5188 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5189 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5191 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5192 | request.load_flags = 0; |
| 5193 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5194 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5195 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5196 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5197 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5198 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5199 | MockRead data_reads[] = { |
| 5200 | // A part of the response body is received with the response headers. |
| 5201 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5202 | // The rest of the response body is received in two parts. |
| 5203 | MockRead("lo"), |
| 5204 | MockRead(" world"), |
| 5205 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5206 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5207 | }; |
| 5208 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5209 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5212 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5214 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5215 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5216 | |
| 5217 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5218 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5219 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5220 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5221 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5222 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5223 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5224 | std::string status_line = response->headers->GetStatusLine(); |
| 5225 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5226 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5227 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5228 | |
| 5229 | std::string response_data; |
| 5230 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5231 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5232 | EXPECT_EQ("hello world", response_data); |
| 5233 | |
| 5234 | // Empty the current queue. This is necessary because idle sockets are |
| 5235 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5236 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5237 | |
| 5238 | // 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] | 5239 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5240 | } |
| 5241 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5242 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5243 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5244 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5245 | HttpRequestInfo request; |
| 5246 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5247 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5248 | request.load_flags = 0; |
| 5249 | |
| 5250 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5251 | MockWrite( |
| 5252 | "GET / HTTP/1.1\r\n" |
| 5253 | "Host: www.example.org\r\n" |
| 5254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5255 | }; |
| 5256 | |
| 5257 | MockRead data_reads[] = { |
| 5258 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5259 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5260 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5261 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5262 | }; |
| 5263 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5264 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5266 | |
| 5267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5268 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5271 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5272 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5273 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5274 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5277 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5278 | |
| 5279 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5280 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5281 | |
| 5282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5283 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5284 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5285 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5286 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5287 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5288 | |
| 5289 | std::string response_data; |
| 5290 | rv = ReadTransaction(trans.get(), &response_data); |
| 5291 | EXPECT_EQ(OK, rv); |
| 5292 | EXPECT_EQ("hello world", response_data); |
| 5293 | |
| 5294 | // Empty the current queue. This is necessary because idle sockets are |
| 5295 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5296 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5297 | |
| 5298 | // 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] | 5299 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5303 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5304 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5305 | HttpRequestInfo request; |
| 5306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5307 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5308 | request.load_flags = 0; |
| 5309 | |
| 5310 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5311 | MockWrite( |
| 5312 | "GET / HTTP/1.1\r\n" |
| 5313 | "Host: www.example.org\r\n" |
| 5314 | "Connection: keep-alive\r\n\r\n"), |
| 5315 | MockWrite( |
| 5316 | "GET / HTTP/1.1\r\n" |
| 5317 | "Host: www.example.org\r\n" |
| 5318 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5319 | }; |
| 5320 | |
| 5321 | MockRead data_reads[] = { |
| 5322 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5323 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5324 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5325 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5326 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5327 | }; |
| 5328 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5329 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5330 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5331 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5333 | |
| 5334 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5335 | data_writes, arraysize(data_writes)); |
| 5336 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5337 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5338 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5339 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5341 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5342 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5344 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5347 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5348 | |
| 5349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5350 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5351 | |
| 5352 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5353 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5354 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5355 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5356 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5357 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5358 | |
| 5359 | std::string response_data; |
| 5360 | rv = ReadTransaction(trans.get(), &response_data); |
| 5361 | EXPECT_EQ(OK, rv); |
| 5362 | EXPECT_EQ("hello world", response_data); |
| 5363 | |
| 5364 | // Empty the current queue. This is necessary because idle sockets are |
| 5365 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5366 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5367 | |
| 5368 | // 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] | 5369 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5370 | |
| 5371 | // Now start the second transaction, which should reuse the previous socket. |
| 5372 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5373 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5375 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5376 | |
| 5377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5378 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5379 | |
| 5380 | response = trans->GetResponseInfo(); |
| 5381 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5382 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5383 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5384 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5385 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5386 | |
| 5387 | rv = ReadTransaction(trans.get(), &response_data); |
| 5388 | EXPECT_EQ(OK, rv); |
| 5389 | EXPECT_EQ("hello world", response_data); |
| 5390 | |
| 5391 | // Empty the current queue. This is necessary because idle sockets are |
| 5392 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5393 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5394 | |
| 5395 | // 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] | 5396 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5397 | } |
| 5398 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5399 | // Make sure that we recycle a socket after a zero-length response. |
| 5400 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5401 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5402 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5403 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5404 | request.url = GURL( |
| 5405 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5406 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5407 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5408 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5409 | request.load_flags = 0; |
| 5410 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5411 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5412 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5413 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5414 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5415 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5416 | MockRead data_reads[] = { |
| 5417 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5418 | "Content-Length: 0\r\n" |
| 5419 | "Content-Type: text/html\r\n\r\n"), |
| 5420 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5422 | }; |
| 5423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5427 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5429 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5431 | |
| 5432 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5433 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5434 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5435 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5436 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5437 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5438 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5439 | std::string status_line = response->headers->GetStatusLine(); |
| 5440 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5441 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5442 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5443 | |
| 5444 | std::string response_data; |
| 5445 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5446 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5447 | EXPECT_EQ("", response_data); |
| 5448 | |
| 5449 | // Empty the current queue. This is necessary because idle sockets are |
| 5450 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5451 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5452 | |
| 5453 | // 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] | 5454 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5455 | } |
| 5456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5457 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5458 | ScopedVector<UploadElementReader> element_readers; |
| 5459 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5460 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5461 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5462 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5463 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5464 | // after use. |
| 5465 | request[0].method = "GET"; |
| 5466 | request[0].url = GURL("http://www.google.com/"); |
| 5467 | request[0].load_flags = 0; |
| 5468 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5469 | // transaction 1. The first attempts fails when writing the POST data. |
| 5470 | // This causes the transaction to retry with a new socket. The second |
| 5471 | // attempt succeeds. |
| 5472 | request[1].method = "POST"; |
| 5473 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5474 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5475 | request[1].load_flags = 0; |
| 5476 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5477 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5478 | |
| 5479 | // The first socket is used for transaction 1 and the first attempt of |
| 5480 | // transaction 2. |
| 5481 | |
| 5482 | // The response of transaction 1. |
| 5483 | MockRead data_reads1[] = { |
| 5484 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5485 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5486 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5487 | }; |
| 5488 | // The mock write results of transaction 1 and the first attempt of |
| 5489 | // transaction 2. |
| 5490 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5491 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5492 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5493 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5494 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5495 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5496 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5497 | |
| 5498 | // The second socket is used for the second attempt of transaction 2. |
| 5499 | |
| 5500 | // The response of transaction 2. |
| 5501 | MockRead data_reads2[] = { |
| 5502 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5503 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5504 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5505 | }; |
| 5506 | // The mock write results of the second attempt of transaction 2. |
| 5507 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5508 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5509 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5510 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5511 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5512 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5513 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5515 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5516 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5517 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5518 | "hello world", "welcome" |
| 5519 | }; |
| 5520 | |
| 5521 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5522 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5523 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5524 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5525 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5527 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5528 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5529 | |
| 5530 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5531 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5532 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5533 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5534 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5535 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5536 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5538 | |
| 5539 | std::string response_data; |
| 5540 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5541 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5542 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5543 | } |
| 5544 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5545 | |
| 5546 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5547 | // 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] | 5548 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5549 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5550 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5552 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5553 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5554 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5555 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5556 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5558 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5559 | // The password contains an escaped character -- for this test to pass it |
| 5560 | // will need to be unescaped by HttpNetworkTransaction. |
| 5561 | EXPECT_EQ("b%40r", request.url.password()); |
| 5562 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5563 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5564 | MockWrite( |
| 5565 | "GET / HTTP/1.1\r\n" |
| 5566 | "Host: www.example.org\r\n" |
| 5567 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5568 | }; |
| 5569 | |
| 5570 | MockRead data_reads1[] = { |
| 5571 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5572 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5573 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5574 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5575 | }; |
| 5576 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5577 | // After the challenge above, the transaction will be restarted using the |
| 5578 | // identity from the url (foo, b@r) to answer the challenge. |
| 5579 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5580 | MockWrite( |
| 5581 | "GET / HTTP/1.1\r\n" |
| 5582 | "Host: www.example.org\r\n" |
| 5583 | "Connection: keep-alive\r\n" |
| 5584 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5585 | }; |
| 5586 | |
| 5587 | MockRead data_reads2[] = { |
| 5588 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5589 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5590 | MockRead(SYNCHRONOUS, OK), |
| 5591 | }; |
| 5592 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5593 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5594 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5595 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5596 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5597 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5598 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5600 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5601 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5603 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5604 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5605 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5606 | |
| 5607 | TestCompletionCallback callback2; |
| 5608 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5610 | rv = callback2.WaitForResult(); |
| 5611 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5612 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5613 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5614 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5615 | ASSERT_TRUE(response != NULL); |
| 5616 | |
| 5617 | // There is no challenge info, since the identity in URL worked. |
| 5618 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5619 | |
| 5620 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5621 | |
| 5622 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5623 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5627 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5628 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5629 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5630 | HttpRequestInfo request; |
| 5631 | request.method = "GET"; |
| 5632 | // Note: the URL has a username:password in it. The password "baz" is |
| 5633 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5634 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5635 | |
| 5636 | request.load_flags = LOAD_NORMAL; |
| 5637 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5638 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5639 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5640 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5641 | |
| 5642 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5643 | MockWrite( |
| 5644 | "GET / HTTP/1.1\r\n" |
| 5645 | "Host: www.example.org\r\n" |
| 5646 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5647 | }; |
| 5648 | |
| 5649 | MockRead data_reads1[] = { |
| 5650 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5651 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5652 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5653 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5654 | }; |
| 5655 | |
| 5656 | // After the challenge above, the transaction will be restarted using the |
| 5657 | // identity from the url (foo, baz) to answer the challenge. |
| 5658 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5659 | MockWrite( |
| 5660 | "GET / HTTP/1.1\r\n" |
| 5661 | "Host: www.example.org\r\n" |
| 5662 | "Connection: keep-alive\r\n" |
| 5663 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5664 | }; |
| 5665 | |
| 5666 | MockRead data_reads2[] = { |
| 5667 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5668 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5669 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5670 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5671 | }; |
| 5672 | |
| 5673 | // After the challenge above, the transaction will be restarted using the |
| 5674 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5675 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | MockWrite( |
| 5677 | "GET / HTTP/1.1\r\n" |
| 5678 | "Host: www.example.org\r\n" |
| 5679 | "Connection: keep-alive\r\n" |
| 5680 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5681 | }; |
| 5682 | |
| 5683 | MockRead data_reads3[] = { |
| 5684 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5685 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5686 | MockRead(SYNCHRONOUS, OK), |
| 5687 | }; |
| 5688 | |
| 5689 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5690 | data_writes1, arraysize(data_writes1)); |
| 5691 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5692 | data_writes2, arraysize(data_writes2)); |
| 5693 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5694 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5695 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5696 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5697 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5698 | |
| 5699 | TestCompletionCallback callback1; |
| 5700 | |
| 5701 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5703 | |
| 5704 | rv = callback1.WaitForResult(); |
| 5705 | EXPECT_EQ(OK, rv); |
| 5706 | |
| 5707 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5708 | TestCompletionCallback callback2; |
| 5709 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5711 | rv = callback2.WaitForResult(); |
| 5712 | EXPECT_EQ(OK, rv); |
| 5713 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5714 | |
| 5715 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5716 | ASSERT_TRUE(response != NULL); |
| 5717 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5718 | |
| 5719 | TestCompletionCallback callback3; |
| 5720 | rv = trans->RestartWithAuth( |
| 5721 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5723 | rv = callback3.WaitForResult(); |
| 5724 | EXPECT_EQ(OK, rv); |
| 5725 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5726 | |
| 5727 | response = trans->GetResponseInfo(); |
| 5728 | ASSERT_TRUE(response != NULL); |
| 5729 | |
| 5730 | // There is no challenge info, since the identity worked. |
| 5731 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5732 | |
| 5733 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5734 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5735 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5736 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5737 | } |
| 5738 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5739 | |
| 5740 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5741 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5742 | // from the URL should never be used. |
| 5743 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5744 | HttpRequestInfo request; |
| 5745 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5746 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5747 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5748 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5749 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5750 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5751 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5752 | |
| 5753 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5754 | MockWrite( |
| 5755 | "GET / HTTP/1.1\r\n" |
| 5756 | "Host: www.example.org\r\n" |
| 5757 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5758 | }; |
| 5759 | |
| 5760 | MockRead data_reads1[] = { |
| 5761 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5762 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5763 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5764 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5765 | }; |
| 5766 | |
| 5767 | // After the challenge above, the transaction will be restarted using the |
| 5768 | // identity supplied by the user, not the one in the URL, to answer the |
| 5769 | // challenge. |
| 5770 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5771 | MockWrite( |
| 5772 | "GET / HTTP/1.1\r\n" |
| 5773 | "Host: www.example.org\r\n" |
| 5774 | "Connection: keep-alive\r\n" |
| 5775 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5776 | }; |
| 5777 | |
| 5778 | MockRead data_reads3[] = { |
| 5779 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5780 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5781 | MockRead(SYNCHRONOUS, OK), |
| 5782 | }; |
| 5783 | |
| 5784 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5785 | data_writes1, arraysize(data_writes1)); |
| 5786 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5787 | data_writes3, arraysize(data_writes3)); |
| 5788 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5789 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5790 | |
| 5791 | TestCompletionCallback callback1; |
| 5792 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5794 | rv = callback1.WaitForResult(); |
| 5795 | EXPECT_EQ(OK, rv); |
| 5796 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5797 | |
| 5798 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5799 | ASSERT_TRUE(response != NULL); |
| 5800 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5801 | |
| 5802 | TestCompletionCallback callback3; |
| 5803 | rv = trans->RestartWithAuth( |
| 5804 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5805 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5806 | rv = callback3.WaitForResult(); |
| 5807 | EXPECT_EQ(OK, rv); |
| 5808 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5809 | |
| 5810 | response = trans->GetResponseInfo(); |
| 5811 | ASSERT_TRUE(response != NULL); |
| 5812 | |
| 5813 | // There is no challenge info, since the identity worked. |
| 5814 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5815 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5816 | |
| 5817 | // Empty the current queue. |
| 5818 | base::MessageLoop::current()->RunUntilIdle(); |
| 5819 | } |
| 5820 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5821 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5822 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5823 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5824 | |
| 5825 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5826 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5827 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5829 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5830 | request.load_flags = 0; |
| 5831 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5832 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5833 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5834 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5835 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5836 | MockWrite( |
| 5837 | "GET /x/y/z HTTP/1.1\r\n" |
| 5838 | "Host: www.example.org\r\n" |
| 5839 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5840 | }; |
| 5841 | |
| 5842 | MockRead data_reads1[] = { |
| 5843 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5844 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5845 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5846 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5847 | }; |
| 5848 | |
| 5849 | // Resend with authorization (username=foo, password=bar) |
| 5850 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5851 | MockWrite( |
| 5852 | "GET /x/y/z HTTP/1.1\r\n" |
| 5853 | "Host: www.example.org\r\n" |
| 5854 | "Connection: keep-alive\r\n" |
| 5855 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5856 | }; |
| 5857 | |
| 5858 | // Sever accepts the authorization. |
| 5859 | MockRead data_reads2[] = { |
| 5860 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5861 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5862 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5863 | }; |
| 5864 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5865 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5866 | data_writes1, arraysize(data_writes1)); |
| 5867 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5868 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5870 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5872 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5874 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5876 | |
| 5877 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5878 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5879 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5881 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5882 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5884 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5886 | rv = trans->RestartWithAuth( |
| 5887 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5889 | |
| 5890 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5891 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5892 | |
| 5893 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5894 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5895 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5896 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5897 | } |
| 5898 | |
| 5899 | // ------------------------------------------------------------------------ |
| 5900 | |
| 5901 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5902 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5903 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5904 | request.method = "GET"; |
| 5905 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5906 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5907 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5908 | request.load_flags = 0; |
| 5909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5910 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5912 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5913 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5914 | MockWrite( |
| 5915 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5916 | "Host: www.example.org\r\n" |
| 5917 | "Connection: keep-alive\r\n" |
| 5918 | // Send preemptive authorization for MyRealm1 |
| 5919 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5920 | }; |
| 5921 | |
| 5922 | // The server didn't like the preemptive authorization, and |
| 5923 | // challenges us for a different realm (MyRealm2). |
| 5924 | MockRead data_reads1[] = { |
| 5925 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5926 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5927 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5928 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5929 | }; |
| 5930 | |
| 5931 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5932 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5933 | MockWrite( |
| 5934 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5935 | "Host: www.example.org\r\n" |
| 5936 | "Connection: keep-alive\r\n" |
| 5937 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5938 | }; |
| 5939 | |
| 5940 | // Sever accepts the authorization. |
| 5941 | MockRead data_reads2[] = { |
| 5942 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5943 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5945 | }; |
| 5946 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5947 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5948 | data_writes1, arraysize(data_writes1)); |
| 5949 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5950 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5951 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5952 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5954 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5956 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5958 | |
| 5959 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5960 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5961 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5962 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5963 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5964 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5965 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5966 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5967 | response->auth_challenge->challenger.ToString()); |
| 5968 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5969 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5971 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5973 | rv = trans->RestartWithAuth( |
| 5974 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5976 | |
| 5977 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5978 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5979 | |
| 5980 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5981 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5982 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5983 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5984 | } |
| 5985 | |
| 5986 | // ------------------------------------------------------------------------ |
| 5987 | |
| 5988 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5989 | // succeed with preemptive authorization. |
| 5990 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5991 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5993 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5994 | request.load_flags = 0; |
| 5995 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5996 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5998 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5999 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6000 | MockWrite( |
| 6001 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6002 | "Host: www.example.org\r\n" |
| 6003 | "Connection: keep-alive\r\n" |
| 6004 | // The authorization for MyRealm1 gets sent preemptively |
| 6005 | // (since the url is in the same protection space) |
| 6006 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6007 | }; |
| 6008 | |
| 6009 | // Sever accepts the preemptive authorization |
| 6010 | MockRead data_reads1[] = { |
| 6011 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6012 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6013 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6014 | }; |
| 6015 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6016 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6017 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6018 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6019 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6020 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6022 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6023 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6024 | |
| 6025 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6026 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6027 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6028 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6029 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6030 | |
| 6031 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6032 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6033 | } |
| 6034 | |
| 6035 | // ------------------------------------------------------------------------ |
| 6036 | |
| 6037 | // Transaction 4: request another URL in MyRealm (however the |
| 6038 | // url is not known to belong to the protection space, so no pre-auth). |
| 6039 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6040 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6042 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6043 | request.load_flags = 0; |
| 6044 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6045 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6046 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6047 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6048 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6049 | MockWrite( |
| 6050 | "GET /x/1 HTTP/1.1\r\n" |
| 6051 | "Host: www.example.org\r\n" |
| 6052 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6053 | }; |
| 6054 | |
| 6055 | MockRead data_reads1[] = { |
| 6056 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6057 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6058 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6059 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6060 | }; |
| 6061 | |
| 6062 | // Resend with authorization from MyRealm's cache. |
| 6063 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6064 | MockWrite( |
| 6065 | "GET /x/1 HTTP/1.1\r\n" |
| 6066 | "Host: www.example.org\r\n" |
| 6067 | "Connection: keep-alive\r\n" |
| 6068 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6069 | }; |
| 6070 | |
| 6071 | // Sever accepts the authorization. |
| 6072 | MockRead data_reads2[] = { |
| 6073 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6074 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6075 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6076 | }; |
| 6077 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6078 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6079 | data_writes1, arraysize(data_writes1)); |
| 6080 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6081 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6082 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6083 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6085 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6087 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6089 | |
| 6090 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6091 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6092 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6093 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6094 | TestCompletionCallback callback2; |
| 6095 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6096 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6097 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6098 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6099 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6100 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6102 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6103 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6104 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6105 | } |
| 6106 | |
| 6107 | // ------------------------------------------------------------------------ |
| 6108 | |
| 6109 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6110 | // cached identity. Should invalidate and re-prompt. |
| 6111 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6112 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6113 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6114 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6115 | request.load_flags = 0; |
| 6116 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6117 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6119 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6120 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6121 | MockWrite( |
| 6122 | "GET /p/q/t HTTP/1.1\r\n" |
| 6123 | "Host: www.example.org\r\n" |
| 6124 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6125 | }; |
| 6126 | |
| 6127 | MockRead data_reads1[] = { |
| 6128 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6129 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6130 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6131 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6132 | }; |
| 6133 | |
| 6134 | // Resend with authorization from cache for MyRealm. |
| 6135 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6136 | MockWrite( |
| 6137 | "GET /p/q/t HTTP/1.1\r\n" |
| 6138 | "Host: www.example.org\r\n" |
| 6139 | "Connection: keep-alive\r\n" |
| 6140 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6141 | }; |
| 6142 | |
| 6143 | // Sever rejects the authorization. |
| 6144 | MockRead data_reads2[] = { |
| 6145 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6146 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6147 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6148 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6149 | }; |
| 6150 | |
| 6151 | // At this point we should prompt for new credentials for MyRealm. |
| 6152 | // Restart with username=foo3, password=foo4. |
| 6153 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6154 | MockWrite( |
| 6155 | "GET /p/q/t HTTP/1.1\r\n" |
| 6156 | "Host: www.example.org\r\n" |
| 6157 | "Connection: keep-alive\r\n" |
| 6158 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6159 | }; |
| 6160 | |
| 6161 | // Sever accepts the authorization. |
| 6162 | MockRead data_reads3[] = { |
| 6163 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6164 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6165 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6166 | }; |
| 6167 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6168 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6169 | data_writes1, arraysize(data_writes1)); |
| 6170 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6171 | data_writes2, arraysize(data_writes2)); |
| 6172 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6173 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6174 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6175 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6176 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6178 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6180 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6182 | |
| 6183 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6184 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6185 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6186 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6187 | TestCompletionCallback callback2; |
| 6188 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6189 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6190 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6191 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6192 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6193 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6194 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6195 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6196 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6198 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6200 | rv = trans->RestartWithAuth( |
| 6201 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6203 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6204 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6205 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6206 | |
| 6207 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6208 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6209 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6210 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6211 | } |
| 6212 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6213 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6214 | // Tests that nonce count increments when multiple auth attempts |
| 6215 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6216 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6217 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6218 | new HttpAuthHandlerDigest::Factory(); |
| 6219 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6220 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6221 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6222 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6223 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6224 | |
| 6225 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6226 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6227 | HttpRequestInfo request; |
| 6228 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6229 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6230 | request.load_flags = 0; |
| 6231 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6232 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6233 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6234 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6235 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6236 | MockWrite( |
| 6237 | "GET /x/y/z HTTP/1.1\r\n" |
| 6238 | "Host: www.example.org\r\n" |
| 6239 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6240 | }; |
| 6241 | |
| 6242 | MockRead data_reads1[] = { |
| 6243 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6244 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6245 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6247 | }; |
| 6248 | |
| 6249 | // Resend with authorization (username=foo, password=bar) |
| 6250 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6251 | MockWrite( |
| 6252 | "GET /x/y/z HTTP/1.1\r\n" |
| 6253 | "Host: www.example.org\r\n" |
| 6254 | "Connection: keep-alive\r\n" |
| 6255 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6256 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6257 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6258 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6259 | }; |
| 6260 | |
| 6261 | // Sever accepts the authorization. |
| 6262 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6263 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6265 | }; |
| 6266 | |
| 6267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6268 | data_writes1, arraysize(data_writes1)); |
| 6269 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6270 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6271 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6272 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6274 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6276 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6278 | |
| 6279 | rv = callback1.WaitForResult(); |
| 6280 | EXPECT_EQ(OK, rv); |
| 6281 | |
| 6282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6283 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6284 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6286 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6288 | rv = trans->RestartWithAuth( |
| 6289 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6291 | |
| 6292 | rv = callback2.WaitForResult(); |
| 6293 | EXPECT_EQ(OK, rv); |
| 6294 | |
| 6295 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6296 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6297 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6298 | } |
| 6299 | |
| 6300 | // ------------------------------------------------------------------------ |
| 6301 | |
| 6302 | // Transaction 2: Request another resource in digestive's protection space. |
| 6303 | // This will preemptively add an Authorization header which should have an |
| 6304 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6305 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6306 | HttpRequestInfo request; |
| 6307 | request.method = "GET"; |
| 6308 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6309 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6310 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6311 | request.load_flags = 0; |
| 6312 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6313 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6314 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6315 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6316 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | MockWrite( |
| 6318 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6319 | "Host: www.example.org\r\n" |
| 6320 | "Connection: keep-alive\r\n" |
| 6321 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6322 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6323 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6324 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6325 | }; |
| 6326 | |
| 6327 | // Sever accepts the authorization. |
| 6328 | MockRead data_reads1[] = { |
| 6329 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6330 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6331 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6332 | }; |
| 6333 | |
| 6334 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6335 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6338 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6340 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6342 | |
| 6343 | rv = callback1.WaitForResult(); |
| 6344 | EXPECT_EQ(OK, rv); |
| 6345 | |
| 6346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6347 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6348 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6349 | } |
| 6350 | } |
| 6351 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6352 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6353 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6354 | // Create a transaction (the dependencies aren't important). |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6355 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6356 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6357 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6358 | |
| 6359 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6360 | trans->read_buf_ = new IOBuffer(15); |
| 6361 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6362 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6363 | |
| 6364 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6365 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6366 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6367 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6368 | response->response_time = base::Time::Now(); |
| 6369 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6370 | |
| 6371 | { // Setup state for response_.vary_data |
| 6372 | HttpRequestInfo request; |
| 6373 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6374 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6375 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6376 | request.extra_headers.SetHeader("Foo", "1"); |
| 6377 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6378 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6379 | } |
| 6380 | |
| 6381 | // Cause the above state to be reset. |
| 6382 | trans->ResetStateForRestart(); |
| 6383 | |
| 6384 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6385 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6386 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6387 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6388 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6389 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6390 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6391 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6392 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6393 | } |
| 6394 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6395 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6396 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6397 | HttpRequestInfo request; |
| 6398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6399 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6400 | request.load_flags = 0; |
| 6401 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6402 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6403 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6404 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6405 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6406 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6407 | MockWrite( |
| 6408 | "GET / HTTP/1.1\r\n" |
| 6409 | "Host: www.example.org\r\n" |
| 6410 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6411 | }; |
| 6412 | |
| 6413 | MockRead data_reads[] = { |
| 6414 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6415 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6416 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6417 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6418 | }; |
| 6419 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6420 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6421 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6422 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6423 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6424 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6425 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6426 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6427 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6431 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6433 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6435 | |
| 6436 | rv = callback.WaitForResult(); |
| 6437 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6439 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6441 | |
| 6442 | rv = callback.WaitForResult(); |
| 6443 | EXPECT_EQ(OK, rv); |
| 6444 | |
| 6445 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6446 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6447 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6448 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6449 | } |
| 6450 | |
| 6451 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6452 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6453 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6454 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6455 | |
| 6456 | HttpRequestInfo request; |
| 6457 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6458 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6459 | request.load_flags = 0; |
| 6460 | |
| 6461 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6462 | MockWrite( |
| 6463 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6464 | "Host: www.example.org\r\n" |
| 6465 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6466 | }; |
| 6467 | |
| 6468 | MockRead proxy_reads[] = { |
| 6469 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6470 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6471 | }; |
| 6472 | |
| 6473 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6474 | MockWrite( |
| 6475 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6476 | "Host: www.example.org\r\n" |
| 6477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6478 | MockWrite( |
| 6479 | "GET / HTTP/1.1\r\n" |
| 6480 | "Host: www.example.org\r\n" |
| 6481 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6482 | }; |
| 6483 | |
| 6484 | MockRead data_reads[] = { |
| 6485 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6486 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6487 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6488 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6489 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6490 | }; |
| 6491 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6492 | StaticSocketDataProvider ssl_bad_certificate( |
| 6493 | proxy_reads, arraysize(proxy_reads), |
| 6494 | proxy_writes, arraysize(proxy_writes)); |
| 6495 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6496 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6497 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6498 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6499 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6500 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6505 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6506 | |
| 6507 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6508 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6509 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6510 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6511 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6514 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6516 | |
| 6517 | rv = callback.WaitForResult(); |
| 6518 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6520 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6521 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6522 | |
| 6523 | rv = callback.WaitForResult(); |
| 6524 | EXPECT_EQ(OK, rv); |
| 6525 | |
| 6526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6527 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6528 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6529 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6530 | } |
| 6531 | } |
| 6532 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6533 | |
| 6534 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6535 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6536 | session_deps_.proxy_service = |
| 6537 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6538 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6539 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6540 | |
| 6541 | HttpRequestInfo request; |
| 6542 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6543 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6544 | request.load_flags = 0; |
| 6545 | |
| 6546 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6547 | MockWrite( |
| 6548 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6549 | "Host: www.example.org\r\n" |
| 6550 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6551 | MockWrite( |
| 6552 | "GET / HTTP/1.1\r\n" |
| 6553 | "Host: www.example.org\r\n" |
| 6554 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6555 | }; |
| 6556 | |
| 6557 | MockRead data_reads[] = { |
| 6558 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6559 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6560 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6561 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6563 | }; |
| 6564 | |
| 6565 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6566 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6567 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6568 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6569 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6574 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6575 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6576 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6577 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6578 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6580 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6581 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6582 | |
| 6583 | rv = callback.WaitForResult(); |
| 6584 | EXPECT_EQ(OK, rv); |
| 6585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6586 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6587 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6588 | |
| 6589 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6590 | EXPECT_EQ(200, response->headers->response_code()); |
| 6591 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6592 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6593 | |
| 6594 | LoadTimingInfo load_timing_info; |
| 6595 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6596 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6597 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6598 | } |
| 6599 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6600 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6601 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6602 | session_deps_.proxy_service = |
| 6603 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6604 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6605 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6606 | |
| 6607 | HttpRequestInfo request; |
| 6608 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6609 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6610 | request.load_flags = 0; |
| 6611 | |
| 6612 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6613 | MockWrite( |
| 6614 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6615 | "Host: www.example.org\r\n" |
| 6616 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6617 | }; |
| 6618 | |
| 6619 | MockRead data_reads[] = { |
| 6620 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6621 | MockRead("Location: http://login.example.com/\r\n"), |
| 6622 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6624 | }; |
| 6625 | |
| 6626 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6627 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6628 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6629 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6630 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6633 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6634 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6635 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6636 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6637 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6639 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6641 | |
| 6642 | rv = callback.WaitForResult(); |
| 6643 | EXPECT_EQ(OK, rv); |
| 6644 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6645 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6646 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6647 | |
| 6648 | EXPECT_EQ(302, response->headers->response_code()); |
| 6649 | std::string url; |
| 6650 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6651 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6652 | |
| 6653 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6654 | // timing for the proxy connection instead of the connection to the host, |
| 6655 | // and no send / receive times. |
| 6656 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6657 | LoadTimingInfo load_timing_info; |
| 6658 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6659 | |
| 6660 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6661 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6662 | |
| 6663 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6664 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6665 | load_timing_info.proxy_resolve_end); |
| 6666 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6667 | load_timing_info.connect_timing.connect_start); |
| 6668 | ExpectConnectTimingHasTimes( |
| 6669 | load_timing_info.connect_timing, |
| 6670 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6671 | |
| 6672 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6673 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6674 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6678 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6679 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | |
| 6681 | HttpRequestInfo request; |
| 6682 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6683 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6684 | request.load_flags = 0; |
| 6685 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6686 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6687 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6688 | scoped_ptr<SpdyFrame> goaway( |
| 6689 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6690 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6691 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6692 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6693 | }; |
| 6694 | |
| 6695 | static const char* const kExtraHeaders[] = { |
| 6696 | "location", |
| 6697 | "http://login.example.com/", |
| 6698 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6699 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6700 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6701 | arraysize(kExtraHeaders)/2, 1)); |
| 6702 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6703 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6704 | }; |
| 6705 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6706 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6707 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6708 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6709 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6710 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6714 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6715 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6716 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6717 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6718 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6720 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6722 | |
| 6723 | rv = callback.WaitForResult(); |
| 6724 | EXPECT_EQ(OK, rv); |
| 6725 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6726 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6727 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6728 | |
| 6729 | EXPECT_EQ(302, response->headers->response_code()); |
| 6730 | std::string url; |
| 6731 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6732 | EXPECT_EQ("http://login.example.com/", url); |
| 6733 | } |
| 6734 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6735 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6736 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6737 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6738 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6739 | |
| 6740 | HttpRequestInfo request; |
| 6741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6742 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6743 | request.load_flags = 0; |
| 6744 | |
| 6745 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6746 | MockWrite( |
| 6747 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6748 | "Host: www.example.org\r\n" |
| 6749 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6750 | }; |
| 6751 | |
| 6752 | MockRead data_reads[] = { |
| 6753 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6754 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6755 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6756 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6757 | }; |
| 6758 | |
| 6759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6760 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6761 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6762 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6766 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6767 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6768 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6769 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6772 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6774 | |
| 6775 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6776 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6777 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6778 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6779 | } |
| 6780 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6781 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6782 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6783 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6784 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6785 | |
| 6786 | HttpRequestInfo request; |
| 6787 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6788 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6789 | request.load_flags = 0; |
| 6790 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6791 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6792 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6793 | scoped_ptr<SpdyFrame> rst( |
| 6794 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6795 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6796 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6797 | }; |
| 6798 | |
| 6799 | static const char* const kExtraHeaders[] = { |
| 6800 | "location", |
| 6801 | "http://login.example.com/", |
| 6802 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6803 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6804 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6805 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6806 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6807 | spdy_util_.ConstructSpdyBodyFrame( |
| 6808 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6809 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6810 | CreateMockRead(*resp.get(), 1), |
| 6811 | CreateMockRead(*body.get(), 2), |
| 6812 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6813 | }; |
| 6814 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6815 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6816 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6817 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6818 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6819 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6821 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6823 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6824 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6825 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6826 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6827 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6829 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6830 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6831 | |
| 6832 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6833 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6834 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6835 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6836 | } |
| 6837 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6838 | // Test the request-challenge-retry sequence for basic auth, through |
| 6839 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6840 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6841 | HttpRequestInfo request; |
| 6842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6843 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6844 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6845 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6846 | |
| 6847 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6848 | session_deps_.proxy_service = |
| 6849 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6850 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6851 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6852 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6853 | |
| 6854 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6855 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6856 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6857 | scoped_ptr<SpdyFrame> rst( |
| 6858 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6859 | |
| 6860 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6861 | // be issuing -- the final header line contains the credentials. |
| 6862 | const char* const kAuthCredentials[] = { |
| 6863 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6864 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6865 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6866 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6867 | HostPortPair("www.example.org", 443))); |
| 6868 | // fetch https://www.example.org/ via HTTP |
| 6869 | const char get[] = |
| 6870 | "GET / HTTP/1.1\r\n" |
| 6871 | "Host: www.example.org\r\n" |
| 6872 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6873 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6874 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6875 | |
| 6876 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6877 | CreateMockWrite(*req, 0, ASYNC), |
| 6878 | CreateMockWrite(*rst, 2, ASYNC), |
| 6879 | CreateMockWrite(*connect2, 3), |
| 6880 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6881 | }; |
| 6882 | |
| 6883 | // The proxy responds to the connect with a 407, using a persistent |
| 6884 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6885 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6886 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6887 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6888 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6889 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6890 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6891 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6892 | scoped_ptr<SpdyFrame> conn_resp( |
| 6893 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6894 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6895 | "Content-Length: 5\r\n\r\n"; |
| 6896 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6897 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6898 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6899 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6900 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6901 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6902 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6903 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6904 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6905 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6906 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6907 | }; |
| 6908 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6909 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6910 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6911 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6912 | // Negotiate SPDY to the proxy |
| 6913 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6914 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6916 | // Vanilla SSL to the server |
| 6917 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6918 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6919 | |
| 6920 | TestCompletionCallback callback1; |
| 6921 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6922 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6923 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6924 | |
| 6925 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6927 | |
| 6928 | rv = callback1.WaitForResult(); |
| 6929 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6930 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6931 | log.GetEntries(&entries); |
| 6932 | size_t pos = ExpectLogContainsSomewhere( |
| 6933 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6934 | NetLog::PHASE_NONE); |
| 6935 | ExpectLogContainsSomewhere( |
| 6936 | entries, pos, |
| 6937 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6938 | NetLog::PHASE_NONE); |
| 6939 | |
| 6940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6941 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6942 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6943 | EXPECT_EQ(407, response->headers->response_code()); |
| 6944 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6945 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6946 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6947 | |
| 6948 | TestCompletionCallback callback2; |
| 6949 | |
| 6950 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6951 | callback2.callback()); |
| 6952 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6953 | |
| 6954 | rv = callback2.WaitForResult(); |
| 6955 | EXPECT_EQ(OK, rv); |
| 6956 | |
| 6957 | response = trans->GetResponseInfo(); |
| 6958 | ASSERT_TRUE(response != NULL); |
| 6959 | |
| 6960 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6961 | EXPECT_EQ(200, response->headers->response_code()); |
| 6962 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6963 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6964 | |
| 6965 | // The password prompt info should not be set. |
| 6966 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6967 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6968 | LoadTimingInfo load_timing_info; |
| 6969 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6970 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6971 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6972 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6973 | trans.reset(); |
| 6974 | session->CloseAllConnections(); |
| 6975 | } |
| 6976 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6977 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6978 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6979 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6980 | HttpRequestInfo request; |
| 6981 | HttpRequestInfo push_request; |
| 6982 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6983 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6984 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6985 | push_request.method = "GET"; |
| 6986 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6987 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6988 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6989 | session_deps_.proxy_service = |
| 6990 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6991 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6992 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6993 | |
| 6994 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6995 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6996 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6997 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6998 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6999 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7000 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7001 | |
| 7002 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7003 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7004 | }; |
| 7005 | |
| 7006 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7007 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7008 | |
| 7009 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7010 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7011 | |
| 7012 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7013 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7014 | 0, |
| 7015 | 2, |
| 7016 | 1, |
| 7017 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7018 | const char kPushedData[] = "pushed"; |
| 7019 | scoped_ptr<SpdyFrame> stream2_body( |
| 7020 | spdy_util_.ConstructSpdyBodyFrame( |
| 7021 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7022 | |
| 7023 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7024 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7025 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7026 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7027 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7028 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7029 | }; |
| 7030 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7031 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7032 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7033 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7034 | // Negotiate SPDY to the proxy |
| 7035 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7036 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7038 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7039 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7040 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7041 | TestCompletionCallback callback; |
| 7042 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7044 | |
| 7045 | rv = callback.WaitForResult(); |
| 7046 | EXPECT_EQ(OK, rv); |
| 7047 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7048 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7049 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7051 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7053 | |
| 7054 | rv = callback.WaitForResult(); |
| 7055 | EXPECT_EQ(OK, rv); |
| 7056 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7057 | |
| 7058 | ASSERT_TRUE(response != NULL); |
| 7059 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7060 | |
| 7061 | EXPECT_EQ(200, response->headers->response_code()); |
| 7062 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7063 | |
| 7064 | std::string response_data; |
| 7065 | rv = ReadTransaction(trans.get(), &response_data); |
| 7066 | EXPECT_EQ(OK, rv); |
| 7067 | EXPECT_EQ("hello!", response_data); |
| 7068 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7069 | LoadTimingInfo load_timing_info; |
| 7070 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7071 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7072 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7073 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7074 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7075 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7076 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7077 | |
| 7078 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7079 | EXPECT_EQ(OK, rv); |
| 7080 | EXPECT_EQ("pushed", response_data); |
| 7081 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7082 | LoadTimingInfo push_load_timing_info; |
| 7083 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7084 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7085 | // The transactions should share a socket ID, despite being for different |
| 7086 | // origins. |
| 7087 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7088 | push_load_timing_info.socket_log_id); |
| 7089 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7090 | trans.reset(); |
| 7091 | push_trans.reset(); |
| 7092 | session->CloseAllConnections(); |
| 7093 | } |
| 7094 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7095 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7096 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7097 | HttpRequestInfo request; |
| 7098 | |
| 7099 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7100 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7101 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7102 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7103 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7104 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7105 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7106 | |
| 7107 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7108 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7109 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7110 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7111 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7112 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7113 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7114 | |
| 7115 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7116 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7117 | |
| 7118 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7119 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7120 | }; |
| 7121 | |
| 7122 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7123 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7124 | |
| 7125 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7126 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7127 | |
| 7128 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7129 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7130 | 0, |
| 7131 | 2, |
| 7132 | 1, |
| 7133 | "https://www.another-origin.com/foo.dat")); |
| 7134 | |
| 7135 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7136 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7137 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7138 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7139 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7140 | }; |
| 7141 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7142 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7143 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7144 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7145 | // Negotiate SPDY to the proxy |
| 7146 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7147 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7149 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7150 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7151 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7152 | TestCompletionCallback callback; |
| 7153 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7155 | |
| 7156 | rv = callback.WaitForResult(); |
| 7157 | EXPECT_EQ(OK, rv); |
| 7158 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7159 | |
| 7160 | ASSERT_TRUE(response != NULL); |
| 7161 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7162 | |
| 7163 | EXPECT_EQ(200, response->headers->response_code()); |
| 7164 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7165 | |
| 7166 | std::string response_data; |
| 7167 | rv = ReadTransaction(trans.get(), &response_data); |
| 7168 | EXPECT_EQ(OK, rv); |
| 7169 | EXPECT_EQ("hello!", response_data); |
| 7170 | |
| 7171 | trans.reset(); |
| 7172 | session->CloseAllConnections(); |
| 7173 | } |
| 7174 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7175 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7176 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7177 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7178 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7179 | |
| 7180 | HttpRequestInfo request; |
| 7181 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7182 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7183 | request.load_flags = 0; |
| 7184 | |
| 7185 | // Attempt to fetch the URL from a server with a bad cert |
| 7186 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7187 | MockWrite( |
| 7188 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7189 | "Host: www.example.org\r\n" |
| 7190 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7191 | }; |
| 7192 | |
| 7193 | MockRead bad_cert_reads[] = { |
| 7194 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7195 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7196 | }; |
| 7197 | |
| 7198 | // Attempt to fetch the URL with a good cert |
| 7199 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7200 | MockWrite( |
| 7201 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7202 | "Host: www.example.org\r\n" |
| 7203 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7204 | MockWrite( |
| 7205 | "GET / HTTP/1.1\r\n" |
| 7206 | "Host: www.example.org\r\n" |
| 7207 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7208 | }; |
| 7209 | |
| 7210 | MockRead good_cert_reads[] = { |
| 7211 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7212 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7213 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7214 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7216 | }; |
| 7217 | |
| 7218 | StaticSocketDataProvider ssl_bad_certificate( |
| 7219 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7220 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7221 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7222 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7223 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7224 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7225 | |
| 7226 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7228 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7230 | |
| 7231 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7236 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7237 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7238 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [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] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7242 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7244 | |
| 7245 | rv = callback.WaitForResult(); |
| 7246 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7248 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7250 | |
| 7251 | rv = callback.WaitForResult(); |
| 7252 | EXPECT_EQ(OK, rv); |
| 7253 | |
| 7254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7255 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7256 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7257 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7258 | } |
| 7259 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7260 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7261 | HttpRequestInfo request; |
| 7262 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7263 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7264 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7265 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7266 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7267 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7268 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7270 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7271 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7272 | MockWrite( |
| 7273 | "GET / HTTP/1.1\r\n" |
| 7274 | "Host: www.example.org\r\n" |
| 7275 | "Connection: keep-alive\r\n" |
| 7276 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7277 | }; |
| 7278 | |
| 7279 | // Lastly, the server responds with the actual content. |
| 7280 | MockRead data_reads[] = { |
| 7281 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7282 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7283 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7285 | }; |
| 7286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7288 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7291 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7293 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7295 | |
| 7296 | rv = callback.WaitForResult(); |
| 7297 | EXPECT_EQ(OK, rv); |
| 7298 | } |
| 7299 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7300 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7301 | HttpRequestInfo request; |
| 7302 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7303 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7304 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7305 | "Chromium Ultra Awesome X Edition"); |
| 7306 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7307 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7308 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7309 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7310 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7311 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7312 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7313 | MockWrite( |
| 7314 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7315 | "Host: www.example.org\r\n" |
| 7316 | "Proxy-Connection: keep-alive\r\n" |
| 7317 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7318 | }; |
| 7319 | MockRead data_reads[] = { |
| 7320 | // Return an error, so the transaction stops here (this test isn't |
| 7321 | // interested in the rest). |
| 7322 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7323 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7324 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7325 | }; |
| 7326 | |
| 7327 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7328 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7331 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7332 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7333 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7335 | |
| 7336 | rv = callback.WaitForResult(); |
| 7337 | EXPECT_EQ(OK, rv); |
| 7338 | } |
| 7339 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7340 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7341 | HttpRequestInfo request; |
| 7342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7343 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7344 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7345 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7346 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7347 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7348 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7349 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7351 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7352 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7353 | MockWrite( |
| 7354 | "GET / HTTP/1.1\r\n" |
| 7355 | "Host: www.example.org\r\n" |
| 7356 | "Connection: keep-alive\r\n" |
| 7357 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7358 | }; |
| 7359 | |
| 7360 | // Lastly, the server responds with the actual content. |
| 7361 | MockRead data_reads[] = { |
| 7362 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7363 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7364 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7365 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7366 | }; |
| 7367 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7369 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7372 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7374 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7375 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7376 | |
| 7377 | rv = callback.WaitForResult(); |
| 7378 | EXPECT_EQ(OK, rv); |
| 7379 | } |
| 7380 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7381 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7382 | HttpRequestInfo request; |
| 7383 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7384 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7385 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7386 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7387 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7388 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7389 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7390 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7391 | MockWrite( |
| 7392 | "POST / HTTP/1.1\r\n" |
| 7393 | "Host: www.example.org\r\n" |
| 7394 | "Connection: keep-alive\r\n" |
| 7395 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7396 | }; |
| 7397 | |
| 7398 | // Lastly, the server responds with the actual content. |
| 7399 | MockRead data_reads[] = { |
| 7400 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7402 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7403 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7404 | }; |
| 7405 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7406 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7407 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7408 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7410 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7411 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7412 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7413 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7414 | |
| 7415 | rv = callback.WaitForResult(); |
| 7416 | EXPECT_EQ(OK, rv); |
| 7417 | } |
| 7418 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7419 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7420 | HttpRequestInfo request; |
| 7421 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7422 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7423 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7424 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7425 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7426 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7427 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7428 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7429 | MockWrite( |
| 7430 | "PUT / HTTP/1.1\r\n" |
| 7431 | "Host: www.example.org\r\n" |
| 7432 | "Connection: keep-alive\r\n" |
| 7433 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7434 | }; |
| 7435 | |
| 7436 | // Lastly, the server responds with the actual content. |
| 7437 | MockRead data_reads[] = { |
| 7438 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7439 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7440 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7441 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7442 | }; |
| 7443 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7444 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7445 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7448 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7450 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7451 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7452 | |
| 7453 | rv = callback.WaitForResult(); |
| 7454 | EXPECT_EQ(OK, rv); |
| 7455 | } |
| 7456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7457 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7458 | HttpRequestInfo request; |
| 7459 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7460 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7461 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7462 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7463 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7465 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7466 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 7467 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7468 | "Host: www.example.org\r\n" |
| 7469 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7470 | }; |
| 7471 | |
| 7472 | // Lastly, the server responds with the actual content. |
| 7473 | MockRead data_reads[] = { |
| 7474 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7475 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7476 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7477 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7478 | }; |
| 7479 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7480 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7481 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7482 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7484 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7486 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7487 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7488 | |
| 7489 | rv = callback.WaitForResult(); |
| 7490 | EXPECT_EQ(OK, rv); |
| 7491 | } |
| 7492 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7493 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7494 | HttpRequestInfo request; |
| 7495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7496 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7497 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7498 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7499 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7500 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7501 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7502 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7503 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | MockWrite( |
| 7505 | "GET / HTTP/1.1\r\n" |
| 7506 | "Host: www.example.org\r\n" |
| 7507 | "Connection: keep-alive\r\n" |
| 7508 | "Pragma: no-cache\r\n" |
| 7509 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7510 | }; |
| 7511 | |
| 7512 | // Lastly, the server responds with the actual content. |
| 7513 | MockRead data_reads[] = { |
| 7514 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7515 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7516 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7517 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7518 | }; |
| 7519 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7520 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7521 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7524 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7526 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7527 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7528 | |
| 7529 | rv = callback.WaitForResult(); |
| 7530 | EXPECT_EQ(OK, rv); |
| 7531 | } |
| 7532 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7533 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7534 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7535 | HttpRequestInfo request; |
| 7536 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7537 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7538 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7539 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7540 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7541 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7543 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7544 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7545 | MockWrite( |
| 7546 | "GET / HTTP/1.1\r\n" |
| 7547 | "Host: www.example.org\r\n" |
| 7548 | "Connection: keep-alive\r\n" |
| 7549 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7550 | }; |
| 7551 | |
| 7552 | // Lastly, the server responds with the actual content. |
| 7553 | MockRead data_reads[] = { |
| 7554 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7555 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7556 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7557 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7558 | }; |
| 7559 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7560 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7561 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7562 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7564 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7566 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7568 | |
| 7569 | rv = callback.WaitForResult(); |
| 7570 | EXPECT_EQ(OK, rv); |
| 7571 | } |
| 7572 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7573 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7574 | HttpRequestInfo request; |
| 7575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7576 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7577 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7578 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7579 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7580 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7582 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7583 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7584 | MockWrite( |
| 7585 | "GET / HTTP/1.1\r\n" |
| 7586 | "Host: www.example.org\r\n" |
| 7587 | "Connection: keep-alive\r\n" |
| 7588 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7589 | }; |
| 7590 | |
| 7591 | // Lastly, the server responds with the actual content. |
| 7592 | MockRead data_reads[] = { |
| 7593 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7594 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7595 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7596 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7597 | }; |
| 7598 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7599 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7600 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7601 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7603 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7605 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7606 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7607 | |
| 7608 | rv = callback.WaitForResult(); |
| 7609 | EXPECT_EQ(OK, rv); |
| 7610 | } |
| 7611 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7612 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7613 | HttpRequestInfo request; |
| 7614 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7615 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7616 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7617 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7618 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7619 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7620 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7621 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7622 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7623 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7624 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7625 | MockWrite( |
| 7626 | "GET / HTTP/1.1\r\n" |
| 7627 | "Host: www.example.org\r\n" |
| 7628 | "Connection: keep-alive\r\n" |
| 7629 | "referer: www.foo.com\r\n" |
| 7630 | "hEllo: Kitty\r\n" |
| 7631 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7632 | }; |
| 7633 | |
| 7634 | // Lastly, the server responds with the actual content. |
| 7635 | MockRead data_reads[] = { |
| 7636 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7637 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7638 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7639 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7640 | }; |
| 7641 | |
| 7642 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7643 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7646 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7648 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7649 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7650 | |
| 7651 | rv = callback.WaitForResult(); |
| 7652 | EXPECT_EQ(OK, rv); |
| 7653 | } |
| 7654 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7655 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7656 | HttpRequestInfo request; |
| 7657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7658 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7659 | request.load_flags = 0; |
| 7660 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7661 | session_deps_.proxy_service = |
| 7662 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7663 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7664 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7665 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7666 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7667 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7669 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7670 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7671 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7672 | |
| 7673 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7674 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7675 | MockWrite( |
| 7676 | "GET / HTTP/1.1\r\n" |
| 7677 | "Host: www.example.org\r\n" |
| 7678 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7679 | |
| 7680 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7681 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7682 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7684 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7685 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7686 | }; |
| 7687 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7688 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7689 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7692 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7694 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7696 | |
| 7697 | rv = callback.WaitForResult(); |
| 7698 | EXPECT_EQ(OK, rv); |
| 7699 | |
| 7700 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7701 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7702 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7703 | LoadTimingInfo load_timing_info; |
| 7704 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7705 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7706 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7707 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7708 | std::string response_text; |
| 7709 | rv = ReadTransaction(trans.get(), &response_text); |
| 7710 | EXPECT_EQ(OK, rv); |
| 7711 | EXPECT_EQ("Payload", response_text); |
| 7712 | } |
| 7713 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7714 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7715 | HttpRequestInfo request; |
| 7716 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7717 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7718 | request.load_flags = 0; |
| 7719 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7720 | session_deps_.proxy_service = |
| 7721 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7722 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7723 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7724 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7725 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7726 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7727 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7728 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7729 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7730 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7731 | |
| 7732 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7733 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7734 | arraysize(write_buffer)), |
| 7735 | MockWrite( |
| 7736 | "GET / HTTP/1.1\r\n" |
| 7737 | "Host: www.example.org\r\n" |
| 7738 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7739 | |
| 7740 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7741 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7742 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7744 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7745 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7746 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7747 | }; |
| 7748 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7750 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7752 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7753 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7756 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7758 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7759 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7760 | |
| 7761 | rv = callback.WaitForResult(); |
| 7762 | EXPECT_EQ(OK, rv); |
| 7763 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7764 | LoadTimingInfo load_timing_info; |
| 7765 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7766 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7767 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7768 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7769 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7770 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7771 | |
| 7772 | std::string response_text; |
| 7773 | rv = ReadTransaction(trans.get(), &response_text); |
| 7774 | EXPECT_EQ(OK, rv); |
| 7775 | EXPECT_EQ("Payload", response_text); |
| 7776 | } |
| 7777 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7778 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7779 | HttpRequestInfo request; |
| 7780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7781 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7782 | request.load_flags = 0; |
| 7783 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7784 | session_deps_.proxy_service = |
| 7785 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7787 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7788 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7789 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7790 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7792 | |
| 7793 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7794 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7795 | |
| 7796 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7797 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7798 | MockWrite( |
| 7799 | "GET / HTTP/1.1\r\n" |
| 7800 | "Host: www.example.org\r\n" |
| 7801 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7802 | |
| 7803 | MockRead data_reads[] = { |
| 7804 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7805 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7806 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7807 | MockRead("Payload"), |
| 7808 | MockRead(SYNCHRONOUS, OK) |
| 7809 | }; |
| 7810 | |
| 7811 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7812 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7814 | |
| 7815 | TestCompletionCallback callback; |
| 7816 | |
| 7817 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7819 | |
| 7820 | rv = callback.WaitForResult(); |
| 7821 | EXPECT_EQ(OK, rv); |
| 7822 | |
| 7823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7824 | ASSERT_TRUE(response != NULL); |
| 7825 | |
| 7826 | LoadTimingInfo load_timing_info; |
| 7827 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7828 | TestLoadTimingNotReused(load_timing_info, |
| 7829 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7830 | |
| 7831 | std::string response_text; |
| 7832 | rv = ReadTransaction(trans.get(), &response_text); |
| 7833 | EXPECT_EQ(OK, rv); |
| 7834 | EXPECT_EQ("Payload", response_text); |
| 7835 | } |
| 7836 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7837 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7838 | HttpRequestInfo request; |
| 7839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7840 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7841 | request.load_flags = 0; |
| 7842 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7843 | session_deps_.proxy_service = |
| 7844 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7845 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7846 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7847 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7848 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7849 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7850 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7851 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7852 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7853 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7854 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7855 | 0x05, // Version |
| 7856 | 0x01, // Command (CONNECT) |
| 7857 | 0x00, // Reserved. |
| 7858 | 0x03, // Address type (DOMAINNAME). |
| 7859 | 0x0F, // Length of domain (15) |
| 7860 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7861 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7862 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7863 | const char kSOCKS5OkResponse[] = |
| 7864 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7865 | |
| 7866 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7867 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7868 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7869 | MockWrite( |
| 7870 | "GET / HTTP/1.1\r\n" |
| 7871 | "Host: www.example.org\r\n" |
| 7872 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7873 | |
| 7874 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7875 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7876 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7877 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7879 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7880 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7881 | }; |
| 7882 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7884 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7887 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7889 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7890 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7891 | |
| 7892 | rv = callback.WaitForResult(); |
| 7893 | EXPECT_EQ(OK, rv); |
| 7894 | |
| 7895 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7896 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7897 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7898 | LoadTimingInfo load_timing_info; |
| 7899 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7900 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7901 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7902 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7903 | std::string response_text; |
| 7904 | rv = ReadTransaction(trans.get(), &response_text); |
| 7905 | EXPECT_EQ(OK, rv); |
| 7906 | EXPECT_EQ("Payload", response_text); |
| 7907 | } |
| 7908 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7909 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7910 | HttpRequestInfo request; |
| 7911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7912 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7913 | request.load_flags = 0; |
| 7914 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7915 | session_deps_.proxy_service = |
| 7916 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7917 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7918 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7919 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7920 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7921 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7922 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7923 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7924 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7925 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7926 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7927 | 0x05, // Version |
| 7928 | 0x01, // Command (CONNECT) |
| 7929 | 0x00, // Reserved. |
| 7930 | 0x03, // Address type (DOMAINNAME). |
| 7931 | 0x0F, // Length of domain (15) |
| 7932 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7933 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7934 | }; |
| 7935 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7936 | const char kSOCKS5OkResponse[] = |
| 7937 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7938 | |
| 7939 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7940 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7941 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7942 | arraysize(kSOCKS5OkRequest)), |
| 7943 | MockWrite( |
| 7944 | "GET / HTTP/1.1\r\n" |
| 7945 | "Host: www.example.org\r\n" |
| 7946 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7947 | |
| 7948 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7949 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7950 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7951 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7952 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7953 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7954 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7955 | }; |
| 7956 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7957 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7958 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7960 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7961 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7964 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7966 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7968 | |
| 7969 | rv = callback.WaitForResult(); |
| 7970 | EXPECT_EQ(OK, rv); |
| 7971 | |
| 7972 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7973 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7974 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7975 | LoadTimingInfo load_timing_info; |
| 7976 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7977 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7978 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7979 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7980 | std::string response_text; |
| 7981 | rv = ReadTransaction(trans.get(), &response_text); |
| 7982 | EXPECT_EQ(OK, rv); |
| 7983 | EXPECT_EQ("Payload", response_text); |
| 7984 | } |
| 7985 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7986 | namespace { |
| 7987 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7988 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7989 | |
| 7990 | struct GroupNameTest { |
| 7991 | std::string proxy_server; |
| 7992 | std::string url; |
| 7993 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7994 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7995 | }; |
| 7996 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7997 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7998 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | SpdySessionDependencies* session_deps_) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8000 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8001 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8002 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8003 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8004 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8005 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8006 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8007 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8008 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8009 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8010 | |
| 8011 | return session; |
| 8012 | } |
| 8013 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8014 | int GroupNameTransactionHelper( |
| 8015 | const std::string& url, |
| 8016 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8017 | HttpRequestInfo request; |
| 8018 | request.method = "GET"; |
| 8019 | request.url = GURL(url); |
| 8020 | request.load_flags = 0; |
| 8021 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8022 | scoped_ptr<HttpTransaction> trans( |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8023 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8025 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8026 | |
| 8027 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8028 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8029 | } |
| 8030 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8031 | } // namespace |
| 8032 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8033 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8034 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8035 | { |
| 8036 | "", // unused |
| 8037 | "http://www.example.org/direct", |
| 8038 | "www.example.org:80", |
| 8039 | false, |
| 8040 | }, |
| 8041 | { |
| 8042 | "", // unused |
| 8043 | "http://[2001:1418:13:1::25]/direct", |
| 8044 | "[2001:1418:13:1::25]:80", |
| 8045 | false, |
| 8046 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8047 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8048 | // SSL Tests |
| 8049 | { |
| 8050 | "", // unused |
| 8051 | "https://www.example.org/direct_ssl", |
| 8052 | "ssl/www.example.org:443", |
| 8053 | true, |
| 8054 | }, |
| 8055 | { |
| 8056 | "", // unused |
| 8057 | "https://[2001:1418:13:1::25]/direct", |
| 8058 | "ssl/[2001:1418:13:1::25]:443", |
| 8059 | true, |
| 8060 | }, |
| 8061 | { |
| 8062 | "", // unused |
| 8063 | "http://host.with.alternate/direct", |
| 8064 | "ssl/host.with.alternate:443", |
| 8065 | true, |
| 8066 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8067 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8068 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8069 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8070 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8071 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8072 | session_deps_.proxy_service = |
| 8073 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8074 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8075 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8076 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8077 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8078 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8079 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8080 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8081 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8082 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8083 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8084 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8085 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8086 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8087 | |
| 8088 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8089 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8090 | if (tests[i].ssl) |
| 8091 | EXPECT_EQ(tests[i].expected_group_name, |
| 8092 | ssl_conn_pool->last_group_name_received()); |
| 8093 | else |
| 8094 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8095 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8096 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8097 | } |
| 8098 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8099 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8100 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8101 | { |
| 8102 | "http_proxy", |
| 8103 | "http://www.example.org/http_proxy_normal", |
| 8104 | "www.example.org:80", |
| 8105 | false, |
| 8106 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8107 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8108 | // SSL Tests |
| 8109 | { |
| 8110 | "http_proxy", |
| 8111 | "https://www.example.org/http_connect_ssl", |
| 8112 | "ssl/www.example.org:443", |
| 8113 | true, |
| 8114 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8115 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8116 | { |
| 8117 | "http_proxy", |
| 8118 | "http://host.with.alternate/direct", |
| 8119 | "ssl/host.with.alternate:443", |
| 8120 | true, |
| 8121 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8122 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8123 | { |
| 8124 | "http_proxy", |
| 8125 | "ftp://ftp.google.com/http_proxy_normal", |
| 8126 | "ftp/ftp.google.com:21", |
| 8127 | false, |
| 8128 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8129 | }; |
| 8130 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8131 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8132 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8133 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8134 | session_deps_.proxy_service = |
| 8135 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8136 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8137 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8138 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8139 | HttpNetworkSessionPeer peer(session); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8140 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8141 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8142 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8143 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8144 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8145 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8146 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8147 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8148 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8149 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8150 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8151 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8152 | |
| 8153 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8154 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8155 | if (tests[i].ssl) |
| 8156 | EXPECT_EQ(tests[i].expected_group_name, |
| 8157 | ssl_conn_pool->last_group_name_received()); |
| 8158 | else |
| 8159 | EXPECT_EQ(tests[i].expected_group_name, |
| 8160 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8161 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8162 | } |
| 8163 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8164 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8165 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8166 | { |
| 8167 | "socks4://socks_proxy:1080", |
| 8168 | "http://www.example.org/socks4_direct", |
| 8169 | "socks4/www.example.org:80", |
| 8170 | false, |
| 8171 | }, |
| 8172 | { |
| 8173 | "socks5://socks_proxy:1080", |
| 8174 | "http://www.example.org/socks5_direct", |
| 8175 | "socks5/www.example.org:80", |
| 8176 | false, |
| 8177 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8178 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8179 | // SSL Tests |
| 8180 | { |
| 8181 | "socks4://socks_proxy:1080", |
| 8182 | "https://www.example.org/socks4_ssl", |
| 8183 | "socks4/ssl/www.example.org:443", |
| 8184 | true, |
| 8185 | }, |
| 8186 | { |
| 8187 | "socks5://socks_proxy:1080", |
| 8188 | "https://www.example.org/socks5_ssl", |
| 8189 | "socks5/ssl/www.example.org:443", |
| 8190 | true, |
| 8191 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8192 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8193 | { |
| 8194 | "socks4://socks_proxy:1080", |
| 8195 | "http://host.with.alternate/direct", |
| 8196 | "socks4/ssl/host.with.alternate:443", |
| 8197 | true, |
| 8198 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8199 | }; |
| 8200 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8201 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8202 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8203 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8204 | session_deps_.proxy_service = |
| 8205 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8206 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8207 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8208 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8209 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8210 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8211 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8212 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8213 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8214 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8215 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8216 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8217 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8218 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8219 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8220 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8221 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8222 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8223 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8225 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8226 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8227 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8228 | if (tests[i].ssl) |
| 8229 | EXPECT_EQ(tests[i].expected_group_name, |
| 8230 | ssl_conn_pool->last_group_name_received()); |
| 8231 | else |
| 8232 | EXPECT_EQ(tests[i].expected_group_name, |
| 8233 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8234 | } |
| 8235 | } |
| 8236 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8237 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8238 | HttpRequestInfo request; |
| 8239 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8240 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8241 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8242 | session_deps_.proxy_service = |
| 8243 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8244 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8245 | // This simulates failure resolving all hostnames; that means we will fail |
| 8246 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8247 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8248 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8249 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8250 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8253 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8255 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8257 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8258 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8259 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8260 | } |
| 8261 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8262 | // Base test to make sure that when the load flags for a request specify to |
| 8263 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8264 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8265 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8266 | // Issue a request, asking to bypass the cache(s). |
| 8267 | HttpRequestInfo request; |
| 8268 | request.method = "GET"; |
| 8269 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8270 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8271 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8272 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8273 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8274 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8275 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8276 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8278 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8279 | // 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] | 8280 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8281 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8282 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8283 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8284 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8285 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8286 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8287 | EXPECT_EQ(OK, rv); |
| 8288 | |
| 8289 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8290 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8291 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8292 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8293 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8294 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8295 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8296 | // 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] | 8297 | // we can tell if the next lookup hit the cache, or the "network". |
| 8298 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8299 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8300 | |
| 8301 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8302 | // 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] | 8303 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8304 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8306 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8307 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8308 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8309 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8310 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8311 | |
| 8312 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8313 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8314 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8315 | } |
| 8316 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8317 | // There are multiple load flags that should trigger the host cache bypass. |
| 8318 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8319 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8320 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8321 | } |
| 8322 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8323 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8324 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8325 | } |
| 8326 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8327 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8328 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8329 | } |
| 8330 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8331 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8332 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8333 | HttpRequestInfo request; |
| 8334 | request.method = "GET"; |
| 8335 | request.url = GURL("http://www.foo.com/"); |
| 8336 | request.load_flags = 0; |
| 8337 | |
| 8338 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8339 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8340 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8341 | StaticSocketDataProvider data(NULL, 0, |
| 8342 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8344 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8346 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8347 | |
| 8348 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8349 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8351 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8352 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8353 | |
| 8354 | rv = callback.WaitForResult(); |
| 8355 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8356 | |
| 8357 | IPEndPoint endpoint; |
| 8358 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8359 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8360 | } |
| 8361 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8362 | // Check that a connection closed after the start of the headers finishes ok. |
| 8363 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8364 | HttpRequestInfo request; |
| 8365 | request.method = "GET"; |
| 8366 | request.url = GURL("http://www.foo.com/"); |
| 8367 | request.load_flags = 0; |
| 8368 | |
| 8369 | MockRead data_reads[] = { |
| 8370 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8371 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8372 | }; |
| 8373 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8374 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8375 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8376 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8378 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8379 | |
| 8380 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8381 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8385 | |
| 8386 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8387 | EXPECT_EQ(OK, rv); |
| 8388 | |
| 8389 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8390 | ASSERT_TRUE(response != NULL); |
| 8391 | |
| 8392 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8393 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8394 | |
| 8395 | std::string response_data; |
| 8396 | rv = ReadTransaction(trans.get(), &response_data); |
| 8397 | EXPECT_EQ(OK, rv); |
| 8398 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8399 | |
| 8400 | IPEndPoint endpoint; |
| 8401 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8402 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8403 | } |
| 8404 | |
| 8405 | // Make sure that a dropped connection while draining the body for auth |
| 8406 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8407 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8408 | HttpRequestInfo request; |
| 8409 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8410 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8411 | request.load_flags = 0; |
| 8412 | |
| 8413 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8414 | MockWrite( |
| 8415 | "GET / HTTP/1.1\r\n" |
| 8416 | "Host: www.example.org\r\n" |
| 8417 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8418 | }; |
| 8419 | |
| 8420 | MockRead data_reads1[] = { |
| 8421 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8422 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8423 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8424 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8425 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8426 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8427 | }; |
| 8428 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8429 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8430 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8431 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8432 | |
| 8433 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8434 | // be issuing -- the final header line contains the credentials. |
| 8435 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8436 | MockWrite( |
| 8437 | "GET / HTTP/1.1\r\n" |
| 8438 | "Host: www.example.org\r\n" |
| 8439 | "Connection: keep-alive\r\n" |
| 8440 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8441 | }; |
| 8442 | |
| 8443 | // Lastly, the server responds with the actual content. |
| 8444 | MockRead data_reads2[] = { |
| 8445 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8446 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8447 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8448 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8449 | }; |
| 8450 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8451 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8452 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8453 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8454 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8456 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8457 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8458 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8461 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8463 | |
| 8464 | rv = callback1.WaitForResult(); |
| 8465 | EXPECT_EQ(OK, rv); |
| 8466 | |
| 8467 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8468 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8469 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8471 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8473 | rv = trans->RestartWithAuth( |
| 8474 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8475 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8476 | |
| 8477 | rv = callback2.WaitForResult(); |
| 8478 | EXPECT_EQ(OK, rv); |
| 8479 | |
| 8480 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8481 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8482 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8483 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8484 | } |
| 8485 | |
| 8486 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8487 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8488 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8489 | |
| 8490 | HttpRequestInfo request; |
| 8491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8492 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8493 | request.load_flags = 0; |
| 8494 | |
| 8495 | MockRead proxy_reads[] = { |
| 8496 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8497 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8498 | }; |
| 8499 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8500 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8501 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8502 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8503 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8506 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8507 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8508 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8509 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8510 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8511 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8514 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8516 | |
| 8517 | rv = callback.WaitForResult(); |
| 8518 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8519 | } |
| 8520 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8521 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8522 | HttpRequestInfo request; |
| 8523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8524 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8525 | request.load_flags = 0; |
| 8526 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8527 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8528 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8529 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8530 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8531 | MockRead data_reads[] = { |
| 8532 | 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] | 8533 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8534 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8535 | |
| 8536 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8539 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8541 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8543 | |
| 8544 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8545 | |
| 8546 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8547 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8548 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8549 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8550 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8551 | |
| 8552 | std::string response_data; |
| 8553 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8554 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8555 | } |
| 8556 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8557 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8558 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8559 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8560 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8561 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8562 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8563 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8564 | ScopedVector<UploadElementReader> element_readers; |
| 8565 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8566 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8567 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8568 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8569 | |
| 8570 | HttpRequestInfo request; |
| 8571 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8572 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8573 | request.upload_data_stream = &upload_data_stream; |
| 8574 | request.load_flags = 0; |
| 8575 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8576 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8577 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8578 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8579 | |
| 8580 | MockRead data_reads[] = { |
| 8581 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8582 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8584 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8585 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8588 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8590 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8592 | |
| 8593 | rv = callback.WaitForResult(); |
| 8594 | EXPECT_EQ(OK, rv); |
| 8595 | |
| 8596 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8597 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8598 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8599 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8600 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8601 | |
| 8602 | std::string response_data; |
| 8603 | rv = ReadTransaction(trans.get(), &response_data); |
| 8604 | EXPECT_EQ(OK, rv); |
| 8605 | EXPECT_EQ("hello world", response_data); |
| 8606 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8607 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8608 | } |
| 8609 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8610 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8611 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8612 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8613 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8614 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8615 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8616 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8617 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8618 | ScopedVector<UploadElementReader> element_readers; |
| 8619 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8620 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8621 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8622 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8623 | |
| 8624 | HttpRequestInfo request; |
| 8625 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8626 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8627 | request.upload_data_stream = &upload_data_stream; |
| 8628 | request.load_flags = 0; |
| 8629 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8630 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8631 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8632 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8633 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8634 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8635 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8638 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8640 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8642 | |
| 8643 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8644 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8645 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8646 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8647 | } |
| 8648 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8649 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8650 | class FakeUploadElementReader : public UploadElementReader { |
| 8651 | public: |
| 8652 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8653 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8654 | |
| 8655 | const CompletionCallback& callback() const { return callback_; } |
| 8656 | |
| 8657 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8658 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8659 | callback_ = callback; |
| 8660 | return ERR_IO_PENDING; |
| 8661 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8662 | uint64 GetContentLength() const override { return 0; } |
| 8663 | uint64 BytesRemaining() const override { return 0; } |
| 8664 | int Read(IOBuffer* buf, |
| 8665 | int buf_length, |
| 8666 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8667 | return ERR_FAILED; |
| 8668 | } |
| 8669 | |
| 8670 | private: |
| 8671 | CompletionCallback callback_; |
| 8672 | }; |
| 8673 | |
| 8674 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8675 | ScopedVector<UploadElementReader> element_readers; |
| 8676 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8677 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8678 | |
| 8679 | HttpRequestInfo request; |
| 8680 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8681 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8682 | request.upload_data_stream = &upload_data_stream; |
| 8683 | request.load_flags = 0; |
| 8684 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8685 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8686 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8688 | |
| 8689 | StaticSocketDataProvider data; |
| 8690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8691 | |
| 8692 | TestCompletionCallback callback; |
| 8693 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8695 | base::MessageLoop::current()->RunUntilIdle(); |
| 8696 | |
| 8697 | // Transaction is pending on request body initialization. |
| 8698 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8699 | |
| 8700 | // Return Init()'s result after the transaction gets destroyed. |
| 8701 | trans.reset(); |
| 8702 | fake_reader->callback().Run(OK); // Should not crash. |
| 8703 | } |
| 8704 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8705 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8706 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8707 | HttpRequestInfo request; |
| 8708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8709 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8710 | request.load_flags = 0; |
| 8711 | |
| 8712 | // First transaction will request a resource and receive a Basic challenge |
| 8713 | // with realm="first_realm". |
| 8714 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8715 | MockWrite( |
| 8716 | "GET / HTTP/1.1\r\n" |
| 8717 | "Host: www.example.org\r\n" |
| 8718 | "Connection: keep-alive\r\n" |
| 8719 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8720 | }; |
| 8721 | MockRead data_reads1[] = { |
| 8722 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8723 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8724 | "\r\n"), |
| 8725 | }; |
| 8726 | |
| 8727 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8728 | // for first_realm. The server will reject and provide a challenge with |
| 8729 | // second_realm. |
| 8730 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8731 | MockWrite( |
| 8732 | "GET / HTTP/1.1\r\n" |
| 8733 | "Host: www.example.org\r\n" |
| 8734 | "Connection: keep-alive\r\n" |
| 8735 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8736 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8737 | }; |
| 8738 | MockRead data_reads2[] = { |
| 8739 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8740 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8741 | "\r\n"), |
| 8742 | }; |
| 8743 | |
| 8744 | // This again fails, and goes back to first_realm. Make sure that the |
| 8745 | // entry is removed from cache. |
| 8746 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8747 | MockWrite( |
| 8748 | "GET / HTTP/1.1\r\n" |
| 8749 | "Host: www.example.org\r\n" |
| 8750 | "Connection: keep-alive\r\n" |
| 8751 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8752 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8753 | }; |
| 8754 | MockRead data_reads3[] = { |
| 8755 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8756 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8757 | "\r\n"), |
| 8758 | }; |
| 8759 | |
| 8760 | // Try one last time (with the correct password) and get the resource. |
| 8761 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8762 | MockWrite( |
| 8763 | "GET / HTTP/1.1\r\n" |
| 8764 | "Host: www.example.org\r\n" |
| 8765 | "Connection: keep-alive\r\n" |
| 8766 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8767 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8768 | }; |
| 8769 | MockRead data_reads4[] = { |
| 8770 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8771 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8772 | "Content-Length: 5\r\n" |
| 8773 | "\r\n" |
| 8774 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8775 | }; |
| 8776 | |
| 8777 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8778 | data_writes1, arraysize(data_writes1)); |
| 8779 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8780 | data_writes2, arraysize(data_writes2)); |
| 8781 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8782 | data_writes3, arraysize(data_writes3)); |
| 8783 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8784 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8785 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8786 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8787 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8788 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8790 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8791 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8792 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8793 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8795 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8796 | // Issue the first request with Authorize headers. There should be a |
| 8797 | // password prompt for first_realm waiting to be filled in after the |
| 8798 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8799 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8801 | rv = callback1.WaitForResult(); |
| 8802 | EXPECT_EQ(OK, rv); |
| 8803 | const HttpResponseInfo* 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 | const AuthChallengeInfo* 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 second request with an incorrect password. There should be a |
| 8813 | // password prompt for second_realm waiting to be filled in after the |
| 8814 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8815 | TestCompletionCallback callback2; |
| 8816 | rv = trans->RestartWithAuth( |
| 8817 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8819 | rv = callback2.WaitForResult(); |
| 8820 | EXPECT_EQ(OK, rv); |
| 8821 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8822 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8823 | challenge = response->auth_challenge.get(); |
| 8824 | ASSERT_FALSE(challenge == NULL); |
| 8825 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8826 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8827 | EXPECT_EQ("second_realm", challenge->realm); |
| 8828 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8829 | |
| 8830 | // Issue the third request with another incorrect password. There should be |
| 8831 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8832 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8833 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8834 | TestCompletionCallback callback3; |
| 8835 | rv = trans->RestartWithAuth( |
| 8836 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8838 | rv = callback3.WaitForResult(); |
| 8839 | EXPECT_EQ(OK, rv); |
| 8840 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8841 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8842 | challenge = response->auth_challenge.get(); |
| 8843 | ASSERT_FALSE(challenge == NULL); |
| 8844 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8845 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8846 | EXPECT_EQ("first_realm", challenge->realm); |
| 8847 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8848 | |
| 8849 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8850 | TestCompletionCallback callback4; |
| 8851 | rv = trans->RestartWithAuth( |
| 8852 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8854 | rv = callback4.WaitForResult(); |
| 8855 | EXPECT_EQ(OK, rv); |
| 8856 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8857 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8858 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8859 | } |
| 8860 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8861 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 8862 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8863 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8864 | |
| 8865 | std::string alternative_service_http_header = |
| 8866 | GetAlternativeServiceHttpHeader(); |
| 8867 | |
| 8868 | MockRead data_reads[] = { |
| 8869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8870 | MockRead(alternative_service_http_header.c_str()), |
| 8871 | MockRead("\r\n"), |
| 8872 | MockRead("hello world"), |
| 8873 | MockRead(SYNCHRONOUS, OK), |
| 8874 | }; |
| 8875 | |
| 8876 | HttpRequestInfo request; |
| 8877 | request.method = "GET"; |
| 8878 | request.url = GURL("http://www.example.org/"); |
| 8879 | request.load_flags = 0; |
| 8880 | |
| 8881 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8882 | |
| 8883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8884 | |
| 8885 | TestCompletionCallback callback; |
| 8886 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8887 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8888 | scoped_ptr<HttpTransaction> trans( |
| 8889 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8890 | |
| 8891 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8892 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8893 | |
| 8894 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8895 | HttpServerProperties& http_server_properties = |
| 8896 | *session->http_server_properties(); |
| 8897 | AlternativeServiceVector alternative_service_vector = |
| 8898 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8899 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8900 | |
| 8901 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8902 | |
| 8903 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8904 | ASSERT_TRUE(response != NULL); |
| 8905 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8906 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8907 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8908 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8909 | |
| 8910 | std::string response_data; |
| 8911 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8912 | EXPECT_EQ("hello world", response_data); |
| 8913 | |
| 8914 | alternative_service_vector = |
| 8915 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8916 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8917 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8918 | alternative_service_vector[0].protocol); |
| 8919 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8920 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8921 | } |
| 8922 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8923 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 8924 | // is false. |
| 8925 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 8926 | session_deps_.next_protos = SpdyNextProtos(); |
| 8927 | session_deps_.use_alternative_services = false; |
| 8928 | |
| 8929 | std::string alternative_service_http_header = |
| 8930 | GetAlternativeServiceHttpHeader(); |
| 8931 | |
| 8932 | MockRead data_reads[] = { |
| 8933 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8934 | MockRead(alternative_service_http_header.c_str()), |
| 8935 | MockRead("\r\n"), |
| 8936 | MockRead("hello world"), |
| 8937 | MockRead(SYNCHRONOUS, OK), |
| 8938 | }; |
| 8939 | |
| 8940 | HttpRequestInfo request; |
| 8941 | request.method = "GET"; |
| 8942 | request.url = GURL("http://www.example.org/"); |
| 8943 | request.load_flags = 0; |
| 8944 | |
| 8945 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 8946 | |
| 8947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8948 | |
| 8949 | TestCompletionCallback callback; |
| 8950 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8951 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 8952 | scoped_ptr<HttpTransaction> trans( |
| 8953 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8954 | |
| 8955 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8956 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8957 | |
| 8958 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8959 | HttpServerProperties& http_server_properties = |
| 8960 | *session->http_server_properties(); |
| 8961 | AlternativeServiceVector alternative_service_vector = |
| 8962 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8963 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8964 | |
| 8965 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8966 | |
| 8967 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8968 | ASSERT_TRUE(response != nullptr); |
| 8969 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 8970 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8971 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8972 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8973 | |
| 8974 | std::string response_data; |
| 8975 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8976 | EXPECT_EQ("hello world", response_data); |
| 8977 | |
| 8978 | alternative_service_vector = |
| 8979 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8980 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8981 | } |
| 8982 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8983 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 8984 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8985 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8986 | |
| 8987 | MockRead data_reads[] = { |
| 8988 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8989 | MockRead("Alt-Svc: "), |
| 8990 | MockRead(GetAlternateProtocolFromParam()), |
| 8991 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 8992 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 8993 | MockRead("hello world"), |
| 8994 | MockRead(SYNCHRONOUS, OK), |
| 8995 | }; |
| 8996 | |
| 8997 | HttpRequestInfo request; |
| 8998 | request.method = "GET"; |
| 8999 | request.url = GURL("http://www.example.org/"); |
| 9000 | request.load_flags = 0; |
| 9001 | |
| 9002 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9003 | |
| 9004 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9005 | |
| 9006 | TestCompletionCallback callback; |
| 9007 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9008 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9009 | scoped_ptr<HttpTransaction> trans( |
| 9010 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9011 | |
| 9012 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9014 | |
| 9015 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9016 | HttpServerProperties& http_server_properties = |
| 9017 | *session->http_server_properties(); |
| 9018 | AlternativeServiceVector alternative_service_vector = |
| 9019 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9020 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9021 | |
| 9022 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9023 | |
| 9024 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9025 | ASSERT_TRUE(response != NULL); |
| 9026 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9027 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9028 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9029 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9030 | |
| 9031 | std::string response_data; |
| 9032 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9033 | EXPECT_EQ("hello world", response_data); |
| 9034 | |
| 9035 | alternative_service_vector = |
| 9036 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9037 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 9038 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9039 | alternative_service_vector[0].protocol); |
| 9040 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9041 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9042 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9043 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9044 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9045 | } |
| 9046 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9047 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9048 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9049 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9050 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9051 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9052 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9053 | std::string alternate_protocol_http_header = |
| 9054 | GetAlternateProtocolHttpHeader(); |
| 9055 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9056 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9057 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9058 | MockRead(alternate_protocol_http_header.c_str()), |
| 9059 | MockRead("\r\n"), |
| 9060 | MockRead("hello world"), |
| 9061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9062 | }; |
| 9063 | |
| 9064 | HttpRequestInfo request; |
| 9065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9066 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9067 | request.load_flags = 0; |
| 9068 | |
| 9069 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9070 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9073 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9074 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9075 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9076 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9079 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9080 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9081 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9082 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9083 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9084 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9085 | AlternativeServiceVector alternative_service_vector = |
| 9086 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9087 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9088 | |
| 9089 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9090 | |
| 9091 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9092 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9093 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9094 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9095 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9096 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9097 | |
| 9098 | std::string response_data; |
| 9099 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9100 | EXPECT_EQ("hello world", response_data); |
| 9101 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9102 | alternative_service_vector = |
| 9103 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9104 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9105 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9106 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9107 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9108 | } |
| 9109 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9110 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9111 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9112 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9113 | |
| 9114 | MockRead data_reads[] = { |
| 9115 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9116 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9117 | MockRead("hello world"), |
| 9118 | MockRead(SYNCHRONOUS, OK), |
| 9119 | }; |
| 9120 | |
| 9121 | HttpRequestInfo request; |
| 9122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9123 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9124 | request.load_flags = 0; |
| 9125 | |
| 9126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9127 | |
| 9128 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9129 | |
| 9130 | TestCompletionCallback callback; |
| 9131 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9132 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9133 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9134 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9135 | HttpServerProperties& http_server_properties = |
| 9136 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9137 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9138 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9139 | http_server_properties.SetAlternativeService( |
| 9140 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9141 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9142 | AlternativeServiceVector alternative_service_vector = |
| 9143 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9144 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9145 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9146 | |
| 9147 | scoped_ptr<HttpTransaction> trans( |
| 9148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9149 | |
| 9150 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9151 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9152 | |
| 9153 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9154 | |
| 9155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9156 | ASSERT_TRUE(response != NULL); |
| 9157 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9158 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9159 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9160 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9161 | |
| 9162 | std::string response_data; |
| 9163 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9164 | EXPECT_EQ("hello world", response_data); |
| 9165 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9166 | alternative_service_vector = |
| 9167 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9168 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9169 | } |
| 9170 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9171 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9172 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9173 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9174 | |
| 9175 | std::string alternative_service_http_header = |
| 9176 | GetAlternativeServiceHttpHeader(); |
| 9177 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9178 | |
| 9179 | MockRead data_reads[] = { |
| 9180 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9181 | MockRead(alternative_service_http_header.c_str()), |
| 9182 | MockRead(alternate_protocol_http_header.c_str()), |
| 9183 | MockRead("\r\n"), |
| 9184 | MockRead("hello world"), |
| 9185 | MockRead(SYNCHRONOUS, OK), |
| 9186 | }; |
| 9187 | |
| 9188 | HttpRequestInfo request; |
| 9189 | request.method = "GET"; |
| 9190 | request.url = GURL("http://www.example.org/"); |
| 9191 | request.load_flags = 0; |
| 9192 | |
| 9193 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9194 | |
| 9195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9196 | |
| 9197 | TestCompletionCallback callback; |
| 9198 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9199 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9200 | scoped_ptr<HttpTransaction> trans( |
| 9201 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9202 | |
| 9203 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9204 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9205 | |
| 9206 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9207 | HttpServerProperties& http_server_properties = |
| 9208 | *session->http_server_properties(); |
| 9209 | AlternativeServiceVector alternative_service_vector = |
| 9210 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9211 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9212 | |
| 9213 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9214 | |
| 9215 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9216 | ASSERT_TRUE(response != NULL); |
| 9217 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9218 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9219 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9220 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9221 | |
| 9222 | std::string response_data; |
| 9223 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9224 | EXPECT_EQ("hello world", response_data); |
| 9225 | |
| 9226 | alternative_service_vector = |
| 9227 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9228 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9229 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9230 | alternative_service_vector[0].protocol); |
| 9231 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9232 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9233 | } |
| 9234 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9235 | // When |use_alternative_services| is false, do not observe alternative service |
| 9236 | // entries that point to a different host. |
| 9237 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9238 | session_deps_.use_alternative_services = false; |
| 9239 | |
| 9240 | HttpRequestInfo request; |
| 9241 | request.method = "GET"; |
| 9242 | request.url = GURL("http://www.example.org/"); |
| 9243 | request.load_flags = 0; |
| 9244 | |
| 9245 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9246 | StaticSocketDataProvider first_data; |
| 9247 | first_data.set_connect_data(mock_connect); |
| 9248 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9249 | |
| 9250 | MockRead data_reads[] = { |
| 9251 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9252 | MockRead(ASYNC, OK), |
| 9253 | }; |
| 9254 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9255 | nullptr, 0); |
| 9256 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9257 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9258 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9259 | |
| 9260 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9261 | session->http_server_properties(); |
| 9262 | AlternativeService alternative_service( |
| 9263 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9264 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9265 | http_server_properties->SetAlternativeService( |
| 9266 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9267 | |
| 9268 | scoped_ptr<HttpTransaction> trans( |
| 9269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9270 | TestCompletionCallback callback; |
| 9271 | |
| 9272 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9273 | // The connetion to origin was refused, and the alternative service should not |
| 9274 | // be used (even though mock data are there), therefore the request should |
| 9275 | // fail. |
| 9276 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9277 | } |
| 9278 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9279 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9280 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9281 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9282 | |
| 9283 | HttpRequestInfo request; |
| 9284 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9285 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9286 | request.load_flags = 0; |
| 9287 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9288 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9289 | StaticSocketDataProvider first_data; |
| 9290 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9291 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9292 | |
| 9293 | MockRead data_reads[] = { |
| 9294 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9295 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9296 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9297 | }; |
| 9298 | StaticSocketDataProvider second_data( |
| 9299 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9300 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9301 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9302 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9303 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9304 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9305 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9306 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9307 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9308 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9309 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9310 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9311 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9312 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9313 | http_server_properties->SetAlternativeService( |
| 9314 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9315 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9316 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9318 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9320 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9322 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9323 | |
| 9324 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9325 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9326 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9327 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9328 | |
| 9329 | std::string response_data; |
| 9330 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9331 | EXPECT_EQ("hello world", response_data); |
| 9332 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9333 | const AlternativeServiceVector alternative_service_vector = |
| 9334 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9335 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9336 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9337 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9338 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9339 | } |
| 9340 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9341 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9342 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9343 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9344 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9345 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9346 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9347 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9348 | |
| 9349 | HttpRequestInfo restricted_port_request; |
| 9350 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9351 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9352 | restricted_port_request.load_flags = 0; |
| 9353 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9354 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9355 | StaticSocketDataProvider first_data; |
| 9356 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9357 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9358 | |
| 9359 | MockRead data_reads[] = { |
| 9360 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9361 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9362 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9363 | }; |
| 9364 | StaticSocketDataProvider second_data( |
| 9365 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9366 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9367 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9368 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9369 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9370 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9371 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9372 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9373 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9374 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9375 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9376 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9377 | http_server_properties->SetAlternativeService( |
| 9378 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9379 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9380 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9381 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9382 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9383 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9385 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9386 | &restricted_port_request, |
| 9387 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9388 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9389 | // Invalid change to unrestricted port should fail. |
| 9390 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9391 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9392 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9393 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9394 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9395 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9396 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9397 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9398 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9399 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9400 | |
| 9401 | HttpRequestInfo restricted_port_request; |
| 9402 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9403 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9404 | restricted_port_request.load_flags = 0; |
| 9405 | |
| 9406 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9407 | StaticSocketDataProvider first_data; |
| 9408 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9409 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9410 | |
| 9411 | MockRead data_reads[] = { |
| 9412 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9413 | MockRead("hello world"), |
| 9414 | MockRead(ASYNC, OK), |
| 9415 | }; |
| 9416 | StaticSocketDataProvider second_data( |
| 9417 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9418 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9419 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9420 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9421 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9422 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9423 | session->http_server_properties(); |
| 9424 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9425 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9426 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9427 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9428 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9429 | http_server_properties->SetAlternativeService( |
| 9430 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9431 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9432 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9433 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9434 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9435 | TestCompletionCallback callback; |
| 9436 | |
| 9437 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9438 | &restricted_port_request, |
| 9439 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9440 | // Change to unrestricted port should succeed. |
| 9441 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9442 | } |
| 9443 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9444 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9445 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9446 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9447 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9448 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9449 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9450 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9451 | |
| 9452 | HttpRequestInfo restricted_port_request; |
| 9453 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9454 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9455 | restricted_port_request.load_flags = 0; |
| 9456 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9457 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9458 | StaticSocketDataProvider first_data; |
| 9459 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9460 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9461 | |
| 9462 | MockRead data_reads[] = { |
| 9463 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9464 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9465 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9466 | }; |
| 9467 | StaticSocketDataProvider second_data( |
| 9468 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9469 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9470 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9471 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9472 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9473 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9474 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9475 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9476 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9477 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9478 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9479 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9480 | http_server_properties->SetAlternativeService( |
| 9481 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9482 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9483 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9484 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9486 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9488 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9489 | &restricted_port_request, |
| 9490 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9491 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9492 | // Valid change to restricted port should pass. |
| 9493 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9494 | } |
| 9495 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9496 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9497 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9498 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9499 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9500 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9501 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9502 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9503 | |
| 9504 | HttpRequestInfo unrestricted_port_request; |
| 9505 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9506 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9507 | unrestricted_port_request.load_flags = 0; |
| 9508 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9509 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9510 | StaticSocketDataProvider first_data; |
| 9511 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9512 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9513 | |
| 9514 | MockRead data_reads[] = { |
| 9515 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9516 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9517 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9518 | }; |
| 9519 | StaticSocketDataProvider second_data( |
| 9520 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9521 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9522 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9523 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9524 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9525 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9526 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9527 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9528 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9529 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9530 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9531 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9532 | http_server_properties->SetAlternativeService( |
| 9533 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9534 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9535 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9536 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9537 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9538 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9540 | int rv = trans->Start( |
| 9541 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9543 | // Valid change to restricted port should pass. |
| 9544 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9545 | } |
| 9546 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9547 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9548 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9549 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9550 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9551 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9552 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9553 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9554 | |
| 9555 | HttpRequestInfo unrestricted_port_request; |
| 9556 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9557 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9558 | unrestricted_port_request.load_flags = 0; |
| 9559 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9560 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9561 | StaticSocketDataProvider first_data; |
| 9562 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9563 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9564 | |
| 9565 | MockRead data_reads[] = { |
| 9566 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9567 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9568 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9569 | }; |
| 9570 | StaticSocketDataProvider second_data( |
| 9571 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9572 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9573 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9574 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9575 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9576 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9577 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 9578 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9579 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9580 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9581 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9582 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9583 | http_server_properties->SetAlternativeService( |
| 9584 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9585 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9586 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9587 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9589 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9591 | int rv = trans->Start( |
| 9592 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9593 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9594 | // Valid change to an unrestricted port should pass. |
| 9595 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9596 | } |
| 9597 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9598 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9599 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 9600 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9601 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9602 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9603 | |
| 9604 | HttpRequestInfo request; |
| 9605 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9606 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9607 | request.load_flags = 0; |
| 9608 | |
| 9609 | // The alternate protocol request will error out before we attempt to connect, |
| 9610 | // so only the standard HTTP request will try to connect. |
| 9611 | MockRead data_reads[] = { |
| 9612 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9613 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9614 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9615 | }; |
| 9616 | StaticSocketDataProvider data( |
| 9617 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9619 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9620 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9621 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9622 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9623 | session->http_server_properties(); |
| 9624 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9625 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9626 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9627 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9628 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9629 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9630 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9631 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9632 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9633 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9634 | TestCompletionCallback callback; |
| 9635 | |
| 9636 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9637 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9638 | // The HTTP request should succeed. |
| 9639 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9640 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9641 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9642 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9643 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9644 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9645 | |
| 9646 | std::string response_data; |
| 9647 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9648 | EXPECT_EQ("hello world", response_data); |
| 9649 | } |
| 9650 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9651 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9652 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9653 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9654 | |
| 9655 | HttpRequestInfo request; |
| 9656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9657 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9658 | request.load_flags = 0; |
| 9659 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9660 | std::string alternate_protocol_http_header = |
| 9661 | GetAlternateProtocolHttpHeader(); |
| 9662 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9663 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9664 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9665 | MockRead(alternate_protocol_http_header.c_str()), |
| 9666 | MockRead("\r\n"), |
| 9667 | MockRead("hello world"), |
| 9668 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9669 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9670 | |
| 9671 | StaticSocketDataProvider first_transaction( |
| 9672 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9673 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9674 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9675 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9676 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9677 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9678 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9680 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9681 | scoped_ptr<SpdyFrame> req( |
| 9682 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9683 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9684 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9685 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9686 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9687 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9688 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9689 | }; |
| 9690 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9691 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9692 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9693 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9694 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9695 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9696 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9697 | NULL, 0, NULL, 0); |
| 9698 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9699 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9700 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9701 | &hanging_non_alternate_protocol_socket); |
| 9702 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9703 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9704 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9705 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9706 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9707 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9709 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9711 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9712 | |
| 9713 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9714 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9715 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9716 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9717 | |
| 9718 | std::string response_data; |
| 9719 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9720 | EXPECT_EQ("hello world", response_data); |
| 9721 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9722 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9724 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9725 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9726 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9727 | |
| 9728 | response = trans->GetResponseInfo(); |
| 9729 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9730 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9731 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9732 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9733 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9734 | |
| 9735 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9736 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9737 | } |
| 9738 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9739 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9740 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9741 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9742 | |
| 9743 | HttpRequestInfo request; |
| 9744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9745 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9746 | request.load_flags = 0; |
| 9747 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9748 | std::string alternate_protocol_http_header = |
| 9749 | GetAlternateProtocolHttpHeader(); |
| 9750 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9751 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9752 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9753 | MockRead(alternate_protocol_http_header.c_str()), |
| 9754 | MockRead("\r\n"), |
| 9755 | MockRead("hello world"), |
| 9756 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9757 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9758 | }; |
| 9759 | |
| 9760 | StaticSocketDataProvider first_transaction( |
| 9761 | data_reads, arraysize(data_reads), NULL, 0); |
| 9762 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9764 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9765 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9766 | StaticSocketDataProvider hanging_socket( |
| 9767 | NULL, 0, NULL, 0); |
| 9768 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9769 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9770 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9771 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9772 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9773 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9774 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9775 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9776 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9777 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9779 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9780 | scoped_ptr<SpdyFrame> req1( |
| 9781 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9782 | scoped_ptr<SpdyFrame> req2( |
| 9783 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9784 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9785 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9786 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9787 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9788 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9789 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9790 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9791 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9792 | CreateMockRead(*resp1, 2), |
| 9793 | CreateMockRead(*data1, 3), |
| 9794 | CreateMockRead(*resp2, 4), |
| 9795 | CreateMockRead(*data2, 5), |
| 9796 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9797 | }; |
| 9798 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9799 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9800 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9801 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9802 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9803 | |
| 9804 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9805 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9806 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9807 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9808 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9809 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9811 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9812 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9813 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9814 | |
| 9815 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9816 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9817 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9818 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9819 | |
| 9820 | std::string response_data; |
| 9821 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9822 | EXPECT_EQ("hello world", response_data); |
| 9823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9824 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9825 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9826 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9827 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9829 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9830 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9831 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9833 | |
| 9834 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9835 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9836 | |
| 9837 | response = trans2.GetResponseInfo(); |
| 9838 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9839 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9840 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9841 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9842 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9843 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9844 | EXPECT_EQ("hello!", response_data); |
| 9845 | |
| 9846 | response = trans3.GetResponseInfo(); |
| 9847 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9848 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9850 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9851 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9852 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9853 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9854 | } |
| 9855 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9856 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9857 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9858 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9859 | |
| 9860 | HttpRequestInfo request; |
| 9861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9862 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9863 | request.load_flags = 0; |
| 9864 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9865 | std::string alternate_protocol_http_header = |
| 9866 | GetAlternateProtocolHttpHeader(); |
| 9867 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9868 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9870 | MockRead(alternate_protocol_http_header.c_str()), |
| 9871 | MockRead("\r\n"), |
| 9872 | MockRead("hello world"), |
| 9873 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9874 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9875 | }; |
| 9876 | |
| 9877 | StaticSocketDataProvider first_transaction( |
| 9878 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9879 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9880 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9881 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9882 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9884 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9885 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9886 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9887 | NULL, 0, NULL, 0); |
| 9888 | hanging_alternate_protocol_socket.set_connect_data( |
| 9889 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9890 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9891 | &hanging_alternate_protocol_socket); |
| 9892 | |
| 9893 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9894 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9896 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9897 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9898 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9899 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9900 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9902 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9903 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9904 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9905 | |
| 9906 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9907 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9908 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9909 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9910 | |
| 9911 | std::string response_data; |
| 9912 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9913 | EXPECT_EQ("hello world", response_data); |
| 9914 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9915 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9917 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9919 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9920 | |
| 9921 | response = trans->GetResponseInfo(); |
| 9922 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9923 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9924 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9925 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9926 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9927 | |
| 9928 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9929 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9930 | } |
| 9931 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9932 | class CapturingProxyResolver : public ProxyResolver { |
| 9933 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9934 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9935 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9936 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9937 | int GetProxyForURL(const GURL& url, |
| 9938 | ProxyInfo* results, |
| 9939 | const CompletionCallback& callback, |
| 9940 | RequestHandle* request, |
| 9941 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9942 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9943 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9944 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9945 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9946 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9947 | } |
| 9948 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9949 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9950 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9951 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9952 | NOTREACHED(); |
| 9953 | return LOAD_STATE_IDLE; |
| 9954 | } |
| 9955 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9956 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9957 | |
| 9958 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9959 | std::vector<GURL> resolved_; |
| 9960 | |
| 9961 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9962 | }; |
| 9963 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9964 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9965 | public: |
| 9966 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9967 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9968 | |
| 9969 | int CreateProxyResolver( |
| 9970 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9971 | scoped_ptr<ProxyResolver>* resolver, |
| 9972 | const net::CompletionCallback& callback, |
| 9973 | scoped_ptr<Request>* request) override { |
| 9974 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9975 | return OK; |
| 9976 | } |
| 9977 | |
| 9978 | private: |
| 9979 | ProxyResolver* resolver_; |
| 9980 | }; |
| 9981 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9982 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9983 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9984 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9985 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9986 | |
| 9987 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9988 | proxy_config.set_auto_detect(true); |
| 9989 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9990 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9991 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9992 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 9993 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9994 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9995 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9996 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9997 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9998 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9999 | |
| 10000 | HttpRequestInfo request; |
| 10001 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10002 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10003 | request.load_flags = 0; |
| 10004 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10005 | std::string alternate_protocol_http_header = |
| 10006 | GetAlternateProtocolHttpHeader(); |
| 10007 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10008 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10009 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10010 | MockRead(alternate_protocol_http_header.c_str()), |
| 10011 | MockRead("\r\n"), |
| 10012 | MockRead("hello world"), |
| 10013 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10014 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10015 | }; |
| 10016 | |
| 10017 | StaticSocketDataProvider first_transaction( |
| 10018 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10020 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10021 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10022 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10023 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10024 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10026 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10027 | scoped_ptr<SpdyFrame> req( |
| 10028 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10029 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10030 | MockWrite(ASYNC, 0, |
| 10031 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10032 | "Host: www.example.org\r\n" |
| 10033 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10034 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10035 | }; |
| 10036 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10037 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10038 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10039 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10040 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10041 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10042 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10043 | CreateMockRead(*resp.get(), 3), |
| 10044 | CreateMockRead(*data.get(), 4), |
| 10045 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10046 | }; |
| 10047 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10048 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10049 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10050 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10051 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10052 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10053 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10054 | NULL, 0, NULL, 0); |
| 10055 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10056 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10057 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10058 | &hanging_non_alternate_protocol_socket); |
| 10059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10060 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10061 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10062 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10063 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10066 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10067 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10068 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10069 | |
| 10070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10071 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10072 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10073 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10074 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10075 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10076 | |
| 10077 | std::string response_data; |
| 10078 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10079 | EXPECT_EQ("hello world", response_data); |
| 10080 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10081 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10083 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10084 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10085 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10086 | |
| 10087 | response = trans->GetResponseInfo(); |
| 10088 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10089 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10090 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10091 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10092 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10093 | |
| 10094 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10095 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10096 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10097 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10098 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10099 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10100 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10101 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10102 | LoadTimingInfo load_timing_info; |
| 10103 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10104 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10105 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10106 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10107 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10108 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10109 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10110 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10111 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10112 | |
| 10113 | HttpRequestInfo request; |
| 10114 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10115 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10116 | request.load_flags = 0; |
| 10117 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10118 | std::string alternate_protocol_http_header = |
| 10119 | GetAlternateProtocolHttpHeader(); |
| 10120 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10121 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10122 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10123 | MockRead(alternate_protocol_http_header.c_str()), |
| 10124 | MockRead("\r\n"), |
| 10125 | MockRead("hello world"), |
| 10126 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10127 | }; |
| 10128 | |
| 10129 | StaticSocketDataProvider first_transaction( |
| 10130 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10131 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10132 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10133 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10134 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10135 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10136 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10138 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10139 | scoped_ptr<SpdyFrame> req( |
| 10140 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10141 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10142 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10143 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10144 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10145 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10146 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10147 | }; |
| 10148 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10149 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10150 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10151 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10152 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10153 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10154 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10155 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10156 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10157 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10158 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10160 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10161 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10162 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10163 | |
| 10164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10165 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10166 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10167 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10168 | |
| 10169 | std::string response_data; |
| 10170 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10171 | EXPECT_EQ("hello world", response_data); |
| 10172 | |
| 10173 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10174 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10175 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10176 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10177 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10178 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10179 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10180 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10182 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10184 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10185 | |
| 10186 | response = trans->GetResponseInfo(); |
| 10187 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10188 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10189 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10190 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10191 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10192 | |
| 10193 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10194 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10195 | } |
| 10196 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10197 | // GenerateAuthToken is a mighty big test. |
| 10198 | // It tests all permutation of GenerateAuthToken behavior: |
| 10199 | // - Synchronous and Asynchronous completion. |
| 10200 | // - OK or error on completion. |
| 10201 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10202 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10203 | // - Non-authenticating and authenticating backend. |
| 10204 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10205 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10206 | // problems generating an auth token for an authenticating proxy, we don't |
| 10207 | // need to test all permutations of the backend server). |
| 10208 | // |
| 10209 | // The test proceeds by going over each of the configuration cases, and |
| 10210 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10211 | // specifies both the configuration for the test as well as the expectations |
| 10212 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10213 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10214 | static const char kServer[] = "http://www.example.com"; |
| 10215 | static const char kSecureServer[] = "https://www.example.com"; |
| 10216 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10217 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10218 | |
| 10219 | enum AuthTiming { |
| 10220 | AUTH_NONE, |
| 10221 | AUTH_SYNC, |
| 10222 | AUTH_ASYNC, |
| 10223 | }; |
| 10224 | |
| 10225 | const MockWrite kGet( |
| 10226 | "GET / HTTP/1.1\r\n" |
| 10227 | "Host: www.example.com\r\n" |
| 10228 | "Connection: keep-alive\r\n\r\n"); |
| 10229 | const MockWrite kGetProxy( |
| 10230 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10231 | "Host: www.example.com\r\n" |
| 10232 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10233 | const MockWrite kGetAuth( |
| 10234 | "GET / HTTP/1.1\r\n" |
| 10235 | "Host: www.example.com\r\n" |
| 10236 | "Connection: keep-alive\r\n" |
| 10237 | "Authorization: auth_token\r\n\r\n"); |
| 10238 | const MockWrite kGetProxyAuth( |
| 10239 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10240 | "Host: www.example.com\r\n" |
| 10241 | "Proxy-Connection: keep-alive\r\n" |
| 10242 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10243 | const MockWrite kGetAuthThroughProxy( |
| 10244 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10245 | "Host: www.example.com\r\n" |
| 10246 | "Proxy-Connection: keep-alive\r\n" |
| 10247 | "Authorization: auth_token\r\n\r\n"); |
| 10248 | const MockWrite kGetAuthWithProxyAuth( |
| 10249 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10250 | "Host: www.example.com\r\n" |
| 10251 | "Proxy-Connection: keep-alive\r\n" |
| 10252 | "Proxy-Authorization: auth_token\r\n" |
| 10253 | "Authorization: auth_token\r\n\r\n"); |
| 10254 | const MockWrite kConnect( |
| 10255 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10256 | "Host: www.example.com\r\n" |
| 10257 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10258 | const MockWrite kConnectProxyAuth( |
| 10259 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10260 | "Host: www.example.com\r\n" |
| 10261 | "Proxy-Connection: keep-alive\r\n" |
| 10262 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10263 | |
| 10264 | const MockRead kSuccess( |
| 10265 | "HTTP/1.1 200 OK\r\n" |
| 10266 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10267 | "Content-Length: 3\r\n\r\n" |
| 10268 | "Yes"); |
| 10269 | const MockRead kFailure( |
| 10270 | "Should not be called."); |
| 10271 | const MockRead kServerChallenge( |
| 10272 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10273 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10274 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10275 | "Content-Length: 14\r\n\r\n" |
| 10276 | "Unauthorized\r\n"); |
| 10277 | const MockRead kProxyChallenge( |
| 10278 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10279 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10280 | "Proxy-Connection: close\r\n" |
| 10281 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10282 | "Content-Length: 14\r\n\r\n" |
| 10283 | "Unauthorized\r\n"); |
| 10284 | const MockRead kProxyConnected( |
| 10285 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10286 | |
| 10287 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10288 | // no constructors, but the C++ compiler on Windows warns about |
| 10289 | // unspecified data in compound literals. So, moved to using constructors, |
| 10290 | // and TestRound's created with the default constructor should not be used. |
| 10291 | struct TestRound { |
| 10292 | TestRound() |
| 10293 | : expected_rv(ERR_UNEXPECTED), |
| 10294 | extra_write(NULL), |
| 10295 | extra_read(NULL) { |
| 10296 | } |
| 10297 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10298 | int expected_rv_arg) |
| 10299 | : write(write_arg), |
| 10300 | read(read_arg), |
| 10301 | expected_rv(expected_rv_arg), |
| 10302 | extra_write(NULL), |
| 10303 | extra_read(NULL) { |
| 10304 | } |
| 10305 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10306 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10307 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10308 | : write(write_arg), |
| 10309 | read(read_arg), |
| 10310 | expected_rv(expected_rv_arg), |
| 10311 | extra_write(extra_write_arg), |
| 10312 | extra_read(extra_read_arg) { |
| 10313 | } |
| 10314 | MockWrite write; |
| 10315 | MockRead read; |
| 10316 | int expected_rv; |
| 10317 | const MockWrite* extra_write; |
| 10318 | const MockRead* extra_read; |
| 10319 | }; |
| 10320 | |
| 10321 | static const int kNoSSL = 500; |
| 10322 | |
| 10323 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10324 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10325 | AuthTiming proxy_auth_timing; |
| 10326 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10327 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10328 | AuthTiming server_auth_timing; |
| 10329 | int server_auth_rv; |
| 10330 | int num_auth_rounds; |
| 10331 | int first_ssl_round; |
| 10332 | TestRound rounds[3]; |
| 10333 | } test_configs[] = { |
| 10334 | // Non-authenticating HTTP server with a direct connection. |
| 10335 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10336 | { TestRound(kGet, kSuccess, OK)}}, |
| 10337 | // Authenticating HTTP server with a direct connection. |
| 10338 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10339 | { TestRound(kGet, kServerChallenge, OK), |
| 10340 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10341 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10342 | { TestRound(kGet, kServerChallenge, OK), |
| 10343 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10344 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10345 | { TestRound(kGet, kServerChallenge, OK), |
| 10346 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10347 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10348 | { TestRound(kGet, kServerChallenge, OK), |
| 10349 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10350 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10351 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10352 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10353 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10354 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10355 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10356 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10357 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10358 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10359 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10360 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10361 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10362 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10363 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10364 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10365 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10366 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10367 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10368 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10369 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10370 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10371 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10372 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10373 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10374 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10375 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10376 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10377 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10378 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10379 | // Authenticating HTTP server through an authenticating proxy. |
| 10380 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10381 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10382 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10383 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10384 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10385 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10386 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10387 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10388 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10389 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10390 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10391 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10392 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10393 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10394 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10395 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10396 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10397 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10398 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10399 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10400 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10401 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10402 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10403 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10404 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10405 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10406 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10407 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10408 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10409 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10410 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10411 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10412 | // Non-authenticating HTTPS server with a direct connection. |
| 10413 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10414 | { TestRound(kGet, kSuccess, OK)}}, |
| 10415 | // Authenticating HTTPS server with a direct connection. |
| 10416 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10417 | { TestRound(kGet, kServerChallenge, OK), |
| 10418 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10419 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10420 | { TestRound(kGet, kServerChallenge, OK), |
| 10421 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10422 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10423 | { TestRound(kGet, kServerChallenge, OK), |
| 10424 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10425 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10426 | { TestRound(kGet, kServerChallenge, OK), |
| 10427 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10428 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10429 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10430 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10431 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10432 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10433 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10434 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10435 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10436 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10437 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10438 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10439 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10440 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10441 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10442 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10443 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10444 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10445 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10446 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10447 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10448 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10449 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10450 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10451 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10452 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10453 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10454 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10455 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10456 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10457 | // Authenticating HTTPS server through an authenticating proxy. |
| 10458 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10459 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10460 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10461 | &kGet, &kServerChallenge), |
| 10462 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10463 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10464 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10465 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10466 | &kGet, &kServerChallenge), |
| 10467 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10468 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10469 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10470 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10471 | &kGet, &kServerChallenge), |
| 10472 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10473 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10474 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10475 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10476 | &kGet, &kServerChallenge), |
| 10477 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10478 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10479 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10480 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10481 | &kGet, &kServerChallenge), |
| 10482 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10483 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10484 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10485 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10486 | &kGet, &kServerChallenge), |
| 10487 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10488 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10489 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10490 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10491 | &kGet, &kServerChallenge), |
| 10492 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10493 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10494 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10495 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10496 | &kGet, &kServerChallenge), |
| 10497 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10498 | }; |
| 10499 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10500 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10501 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10502 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10503 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10504 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10505 | |
| 10506 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10507 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10508 | for (int n = 0; n < 2; n++) { |
| 10509 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10510 | std::string auth_challenge = "Mock realm=proxy"; |
| 10511 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10512 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10513 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10514 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10515 | origin, BoundNetLog()); |
| 10516 | auth_handler->SetGenerateExpectation( |
| 10517 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10518 | test_config.proxy_auth_rv); |
| 10519 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10520 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10521 | } |
| 10522 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10523 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10524 | std::string auth_challenge = "Mock realm=server"; |
| 10525 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10526 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10527 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10528 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10529 | origin, BoundNetLog()); |
| 10530 | auth_handler->SetGenerateExpectation( |
| 10531 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10532 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10533 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10534 | } |
| 10535 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10536 | session_deps_.proxy_service = |
| 10537 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10538 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10539 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10540 | } |
| 10541 | |
| 10542 | HttpRequestInfo request; |
| 10543 | request.method = "GET"; |
| 10544 | request.url = GURL(test_config.server_url); |
| 10545 | request.load_flags = 0; |
| 10546 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10547 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10549 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10550 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10551 | |
| 10552 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10553 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10554 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10555 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10556 | |
| 10557 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10558 | mock_reads.back().push_back(read_write_round.read); |
| 10559 | mock_writes.back().push_back(read_write_round.write); |
| 10560 | |
| 10561 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10562 | // socket is closed and a new one will be created for the next request. |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 10563 | if (read_write_round.read.data == kProxyChallenge.data && |
| 10564 | read_write_round.write.data != kConnect.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10565 | mock_reads.push_back(std::vector<MockRead>()); |
| 10566 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10567 | } |
| 10568 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10569 | if (read_write_round.extra_read) { |
| 10570 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10571 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10572 | if (read_write_round.extra_write) { |
| 10573 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10574 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10575 | |
| 10576 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10577 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10578 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10579 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10580 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10581 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10582 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10583 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10584 | data_providers.push_back(new StaticSocketDataProvider( |
| 10585 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10586 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10587 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10588 | data_providers.back()); |
| 10589 | } |
| 10590 | |
| 10591 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10592 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10593 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10594 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10595 | int rv; |
| 10596 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10597 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10598 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10599 | rv = trans.RestartWithAuth( |
| 10600 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10601 | } |
| 10602 | if (rv == ERR_IO_PENDING) |
| 10603 | rv = callback.WaitForResult(); |
| 10604 | |
| 10605 | // Compare results with expected data. |
| 10606 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10607 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10608 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10609 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10610 | continue; |
| 10611 | } |
| 10612 | if (round + 1 < test_config.num_auth_rounds) { |
| 10613 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10614 | } else { |
| 10615 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10616 | } |
| 10617 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10618 | } |
| 10619 | } |
| 10620 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10621 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10622 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10623 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10624 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10625 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10626 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10627 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10628 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10629 | |
| 10630 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10631 | auth_handler->set_connection_based(true); |
| 10632 | std::string auth_challenge = "Mock realm=server"; |
| 10633 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10634 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10635 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10636 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10637 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10638 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10639 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10640 | int rv = OK; |
| 10641 | const HttpResponseInfo* response = NULL; |
| 10642 | HttpRequestInfo request; |
| 10643 | request.method = "GET"; |
| 10644 | request.url = origin; |
| 10645 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10646 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10647 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10648 | |
| 10649 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10650 | // to validate that the TCP socket is not released to the pool between |
| 10651 | // each round of multi-round authentication. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10652 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10653 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10654 | 50, // Max sockets for pool |
| 10655 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10656 | session_deps_.host_resolver.get(), |
| 10657 | session_deps_.socket_factory.get(), |
| 10658 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10659 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10660 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10661 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10662 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10663 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10664 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10666 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10667 | |
| 10668 | const MockWrite kGet( |
| 10669 | "GET / HTTP/1.1\r\n" |
| 10670 | "Host: www.example.com\r\n" |
| 10671 | "Connection: keep-alive\r\n\r\n"); |
| 10672 | const MockWrite kGetAuth( |
| 10673 | "GET / HTTP/1.1\r\n" |
| 10674 | "Host: www.example.com\r\n" |
| 10675 | "Connection: keep-alive\r\n" |
| 10676 | "Authorization: auth_token\r\n\r\n"); |
| 10677 | |
| 10678 | const MockRead kServerChallenge( |
| 10679 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10680 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10681 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10682 | "Content-Length: 14\r\n\r\n" |
| 10683 | "Unauthorized\r\n"); |
| 10684 | const MockRead kSuccess( |
| 10685 | "HTTP/1.1 200 OK\r\n" |
| 10686 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10687 | "Content-Length: 3\r\n\r\n" |
| 10688 | "Yes"); |
| 10689 | |
| 10690 | MockWrite writes[] = { |
| 10691 | // First round |
| 10692 | kGet, |
| 10693 | // Second round |
| 10694 | kGetAuth, |
| 10695 | // Third round |
| 10696 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10697 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10698 | kGetAuth, |
| 10699 | // Competing request |
| 10700 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10701 | }; |
| 10702 | MockRead reads[] = { |
| 10703 | // First round |
| 10704 | kServerChallenge, |
| 10705 | // Second round |
| 10706 | kServerChallenge, |
| 10707 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10708 | kServerChallenge, |
| 10709 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10710 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10711 | // Competing response |
| 10712 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10713 | }; |
| 10714 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10715 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10716 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10717 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10718 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10719 | |
| 10720 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10721 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10722 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10723 | if (rv == ERR_IO_PENDING) |
| 10724 | rv = callback.WaitForResult(); |
| 10725 | EXPECT_EQ(OK, rv); |
| 10726 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10727 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10728 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10729 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10730 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10731 | // In between rounds, another request comes in for the same domain. |
| 10732 | // It should not be able to grab the TCP socket that trans has already |
| 10733 | // claimed. |
| 10734 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10735 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10736 | TestCompletionCallback callback_compete; |
| 10737 | rv = trans_compete->Start( |
| 10738 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10739 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10740 | // callback_compete.WaitForResult at this point would stall forever, |
| 10741 | // since the HttpNetworkTransaction does not release the request back to |
| 10742 | // the pool until after authentication completes. |
| 10743 | |
| 10744 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10745 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10746 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10747 | if (rv == ERR_IO_PENDING) |
| 10748 | rv = callback.WaitForResult(); |
| 10749 | EXPECT_EQ(OK, rv); |
| 10750 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10751 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10752 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10753 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10754 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10755 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10756 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10757 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10758 | if (rv == ERR_IO_PENDING) |
| 10759 | rv = callback.WaitForResult(); |
| 10760 | EXPECT_EQ(OK, rv); |
| 10761 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10762 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10763 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10764 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10765 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10766 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10767 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10768 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10769 | if (rv == ERR_IO_PENDING) |
| 10770 | rv = callback.WaitForResult(); |
| 10771 | EXPECT_EQ(OK, rv); |
| 10772 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10773 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10774 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10775 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10776 | |
| 10777 | // Read the body since the fourth round was successful. This will also |
| 10778 | // release the socket back to the pool. |
| 10779 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10780 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10781 | if (rv == ERR_IO_PENDING) |
| 10782 | rv = callback.WaitForResult(); |
| 10783 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10784 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10785 | EXPECT_EQ(0, rv); |
| 10786 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10787 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10788 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10789 | |
| 10790 | // The competing request can now finish. Wait for the headers and then |
| 10791 | // read the body. |
| 10792 | rv = callback_compete.WaitForResult(); |
| 10793 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10794 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10795 | if (rv == ERR_IO_PENDING) |
| 10796 | rv = callback.WaitForResult(); |
| 10797 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10798 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10799 | EXPECT_EQ(0, rv); |
| 10800 | |
| 10801 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10802 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10803 | } |
| 10804 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10805 | // This tests the case that a request is issued via http instead of spdy after |
| 10806 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10807 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10808 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10809 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10810 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10811 | session_deps_.next_protos = next_protos; |
| 10812 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10813 | HttpRequestInfo request; |
| 10814 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10815 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10816 | request.load_flags = 0; |
| 10817 | |
| 10818 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10819 | MockWrite( |
| 10820 | "GET / HTTP/1.1\r\n" |
| 10821 | "Host: www.example.org\r\n" |
| 10822 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10823 | }; |
| 10824 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10825 | std::string alternate_protocol_http_header = |
| 10826 | GetAlternateProtocolHttpHeader(); |
| 10827 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10828 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10829 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10830 | MockRead(alternate_protocol_http_header.c_str()), |
| 10831 | MockRead("\r\n"), |
| 10832 | MockRead("hello world"), |
| 10833 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10834 | }; |
| 10835 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10836 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10837 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10838 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10839 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10840 | |
| 10841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10842 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10845 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10846 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10847 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10851 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10852 | |
| 10853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10854 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10855 | |
| 10856 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10857 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10858 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10859 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10860 | |
| 10861 | std::string response_data; |
| 10862 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10863 | EXPECT_EQ("hello world", response_data); |
| 10864 | |
| 10865 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10866 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10867 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10868 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10869 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 10870 | // immediate server closing of the socket. |
| 10871 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10872 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10873 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10874 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10875 | |
| 10876 | HttpRequestInfo request; |
| 10877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10878 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10879 | request.load_flags = 0; |
| 10880 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10881 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10882 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10884 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10885 | scoped_ptr<SpdyFrame> req( |
| 10886 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10887 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10888 | |
| 10889 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10890 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10891 | }; |
| 10892 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10893 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10894 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10895 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10897 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10898 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10899 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10900 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10901 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10903 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10904 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10905 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10906 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10907 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10908 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10909 | // it gets it. This is needed since the auth handler may get destroyed |
| 10910 | // before we get a chance to query it. |
| 10911 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10912 | public: |
| 10913 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10914 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10915 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10916 | |
| 10917 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10918 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10919 | const HttpRequestInfo* request, |
| 10920 | const CompletionCallback& callback, |
| 10921 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10922 | *url_ = request->url; |
| 10923 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10924 | credentials, request, callback, auth_token); |
| 10925 | } |
| 10926 | |
| 10927 | private: |
| 10928 | GURL* url_; |
| 10929 | }; |
| 10930 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10931 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 10932 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10933 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10934 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10935 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10936 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10937 | session_deps_.proxy_service = |
| 10938 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10939 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10940 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10941 | GURL request_url; |
| 10942 | { |
| 10943 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10944 | new HttpAuthHandlerMock::Factory(); |
| 10945 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10946 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10947 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10948 | auth_factory->set_do_init_from_challenge(true); |
| 10949 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10950 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10951 | |
| 10952 | HttpRequestInfo request; |
| 10953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10954 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10955 | request.load_flags = 0; |
| 10956 | |
| 10957 | // First round goes unauthenticated through the proxy. |
| 10958 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10959 | MockWrite( |
| 10960 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10961 | "Host: www.example.org\r\n" |
| 10962 | "Proxy-Connection: keep-alive\r\n" |
| 10963 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10964 | }; |
| 10965 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10966 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10967 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10968 | MockRead("Alternate-Protocol: 443:"), |
| 10969 | MockRead(GetAlternateProtocolFromParam()), |
| 10970 | MockRead("\r\n"), |
| 10971 | MockRead("Proxy-Connection: close\r\n"), |
| 10972 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10973 | }; |
| 10974 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10975 | data_writes_1, arraysize(data_writes_1)); |
| 10976 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10977 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10978 | // Alternate-Protocol announcement in the first round. It fails due |
| 10979 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10980 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10981 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10982 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10983 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10984 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10985 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10986 | // to obtain a new one. |
| 10987 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10988 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10989 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10990 | // establishment and SPDY framing issues. Alas, the |
| 10991 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10992 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10993 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10994 | scoped_ptr<SpdyFrame> req( |
| 10995 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10996 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10997 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10998 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10999 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11000 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11001 | MockWrite(ASYNC, 0, |
| 11002 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11003 | "Host: www.example.org\r\n" |
| 11004 | "Proxy-Connection: keep-alive\r\n" |
| 11005 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11006 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11007 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11008 | MockWrite(ASYNC, 2, |
| 11009 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11010 | "Host: www.example.org\r\n" |
| 11011 | "Proxy-Connection: keep-alive\r\n" |
| 11012 | "Proxy-Authorization: auth_token\r\n" |
| 11013 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11014 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11015 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11016 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11017 | }; |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 11018 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 11019 | "Proxy-Authenticate: Mock\r\n" |
| 11020 | "Proxy-Connection: close\r\n" |
| 11021 | "\r\n"); |
| 11022 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11023 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11024 | // First connection attempt fails |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 11025 | MockRead(ASYNC, kRejectConnectResponse, |
| 11026 | arraysize(kRejectConnectResponse) - 1, 1), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11027 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11028 | // Second connection attempt passes |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 11029 | MockRead(ASYNC, kAcceptConnectResponse, |
| 11030 | arraysize(kAcceptConnectResponse) - 1, 3), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11031 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11032 | // SPDY response |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 11033 | CreateMockRead(*resp.get(), 5), |
| 11034 | CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11035 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11036 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11037 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11038 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11039 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11040 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11041 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11042 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11043 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11044 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11045 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11046 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11047 | NULL, 0, NULL, 0); |
| 11048 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11049 | never_finishing_connect); |
| 11050 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11051 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11052 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11054 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11055 | &hanging_non_alternate_protocol_socket); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11056 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11057 | |
| 11058 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11059 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11060 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11062 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11064 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11065 | |
| 11066 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11067 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11068 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11069 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11070 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11072 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11073 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11074 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11075 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11076 | |
| 11077 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11078 | TestCompletionCallback callback_3; |
| 11079 | rv = trans_2->RestartWithAuth( |
| 11080 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11082 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11083 | |
| 11084 | // After all that work, these two lines (or actually, just the scheme) are |
| 11085 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11086 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11087 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11088 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11089 | LoadTimingInfo load_timing_info; |
| 11090 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11091 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11092 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11093 | } |
| 11094 | |
| 11095 | // Test that if we cancel the transaction as the connection is completing, that |
| 11096 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11097 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11098 | // Setup everything about the connection to complete synchronously, so that |
| 11099 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11100 | // for is the callback from the HttpStreamRequest. |
| 11101 | // Then cancel the transaction. |
| 11102 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11103 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11104 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11105 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11106 | MockRead(SYNCHRONOUS, "hello world"), |
| 11107 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11108 | }; |
| 11109 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11110 | HttpRequestInfo request; |
| 11111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11112 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11113 | request.load_flags = 0; |
| 11114 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11115 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11116 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11117 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11119 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11120 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11121 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11122 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11124 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11125 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11126 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11127 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11129 | trans.reset(); // Cancel the transaction here. |
| 11130 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11131 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11132 | } |
| 11133 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11134 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11135 | // stream is drained properly and added back to the socket pool. The main |
| 11136 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11137 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11138 | // deleted. |
| 11139 | // See http://crbug.com/368418 |
| 11140 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11141 | MockRead data_reads[] = { |
| 11142 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11143 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11144 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11145 | MockRead(ASYNC, "1"), |
| 11146 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11147 | // HttpNetworkTransaction has been deleted. |
| 11148 | MockRead(ASYNC, "2"), |
| 11149 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11150 | }; |
| 11151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11152 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11153 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11154 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11155 | |
| 11156 | { |
| 11157 | HttpRequestInfo request; |
| 11158 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11159 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11160 | request.load_flags = 0; |
| 11161 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11163 | TestCompletionCallback callback; |
| 11164 | |
| 11165 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11167 | callback.WaitForResult(); |
| 11168 | |
| 11169 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11170 | ASSERT_TRUE(response != NULL); |
| 11171 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11172 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11173 | |
| 11174 | // The transaction and HttpRequestInfo are deleted. |
| 11175 | } |
| 11176 | |
| 11177 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11178 | base::MessageLoop::current()->RunUntilIdle(); |
| 11179 | |
| 11180 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11181 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11182 | } |
| 11183 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11184 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11185 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11186 | session_deps_.proxy_service = |
| 11187 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11188 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11189 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11190 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11191 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11192 | HttpRequestInfo request; |
| 11193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11194 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11195 | |
| 11196 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11197 | MockWrite( |
| 11198 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11199 | "Host: www.example.org\r\n" |
| 11200 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11201 | }; |
| 11202 | |
| 11203 | MockRead data_reads1[] = { |
| 11204 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11205 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11206 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11207 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11208 | }; |
| 11209 | |
| 11210 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11211 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11212 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11214 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11215 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11216 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11217 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11218 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11219 | trans->SetBeforeProxyHeadersSentCallback( |
| 11220 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11221 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11223 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11225 | |
| 11226 | rv = callback1.WaitForResult(); |
| 11227 | EXPECT_EQ(OK, rv); |
| 11228 | |
| 11229 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11230 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11231 | |
| 11232 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11233 | EXPECT_EQ(200, response->headers->response_code()); |
| 11234 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11235 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11236 | EXPECT_TRUE( |
| 11237 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11238 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11239 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11240 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11241 | |
| 11242 | LoadTimingInfo load_timing_info; |
| 11243 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11244 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11245 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11246 | } |
| 11247 | |
| 11248 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11249 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11250 | session_deps_.proxy_service = |
| 11251 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11252 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11253 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11254 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11255 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11256 | HttpRequestInfo request; |
| 11257 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11258 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11259 | |
| 11260 | // Since we have proxy, should try to establish tunnel. |
| 11261 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11262 | MockWrite( |
| 11263 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11264 | "Host: www.example.org\r\n" |
| 11265 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11266 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11267 | MockWrite( |
| 11268 | "GET / HTTP/1.1\r\n" |
| 11269 | "Host: www.example.org\r\n" |
| 11270 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11271 | }; |
| 11272 | |
| 11273 | MockRead data_reads1[] = { |
| 11274 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11275 | |
| 11276 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11277 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11278 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11279 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11280 | }; |
| 11281 | |
| 11282 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11283 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11284 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11285 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11288 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11289 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11290 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11291 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11293 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11295 | |
| 11296 | rv = callback1.WaitForResult(); |
| 11297 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11298 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11299 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11300 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11301 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11302 | NetLog::PHASE_NONE); |
| 11303 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11304 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11305 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11306 | NetLog::PHASE_NONE); |
| 11307 | |
| 11308 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11309 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11310 | |
| 11311 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11312 | EXPECT_EQ(200, response->headers->response_code()); |
| 11313 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11314 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11315 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11316 | EXPECT_TRUE( |
| 11317 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11318 | |
| 11319 | LoadTimingInfo load_timing_info; |
| 11320 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11321 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11322 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11323 | } |
| 11324 | |
| 11325 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11326 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11327 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11328 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11329 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11330 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11332 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11333 | HttpRequestInfo request; |
| 11334 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11335 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11336 | |
| 11337 | // Since we have proxy, should try to establish tunnel. |
| 11338 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11339 | MockWrite( |
| 11340 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11341 | "Host: www.example.org\r\n" |
| 11342 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11343 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11344 | MockWrite( |
| 11345 | "GET / HTTP/1.1\r\n" |
| 11346 | "Host: www.example.org\r\n" |
| 11347 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11348 | }; |
| 11349 | |
| 11350 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11351 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11352 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11353 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11354 | }; |
| 11355 | |
| 11356 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11357 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11358 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11359 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11362 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11363 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11364 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11365 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11367 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11369 | |
| 11370 | rv = callback1.WaitForResult(); |
| 11371 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11372 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11373 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11374 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11375 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11376 | NetLog::PHASE_NONE); |
| 11377 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11378 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11379 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11380 | NetLog::PHASE_NONE); |
| 11381 | } |
| 11382 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11383 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11384 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11385 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11386 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11387 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11388 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11389 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11390 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11391 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11392 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11393 | }; |
| 11394 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11395 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11396 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11397 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11398 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11399 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11400 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11402 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11403 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11404 | |
| 11405 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11406 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11407 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11408 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11409 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11410 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11411 | |
| 11412 | HttpRequestInfo request; |
| 11413 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11414 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11415 | request.load_flags = 0; |
| 11416 | |
| 11417 | // This is the important line that marks this as a preconnect. |
| 11418 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11419 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11420 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11421 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11422 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11423 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11424 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11426 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11427 | } |
| 11428 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11429 | // Given a net error, cause that error to be returned from the first Write() |
| 11430 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11431 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11432 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11433 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11434 | request_info.url = GURL("https://www.example.com/"); |
| 11435 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11436 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11437 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11438 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11439 | MockWrite data_writes[] = { |
| 11440 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11441 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11442 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11443 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11444 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11445 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11446 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11447 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11448 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11450 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11451 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11452 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11453 | rv = callback.WaitForResult(); |
| 11454 | ASSERT_EQ(error, rv); |
| 11455 | } |
| 11456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11457 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11458 | // Just check a grab bag of cert errors. |
| 11459 | static const int kErrors[] = { |
| 11460 | ERR_CERT_COMMON_NAME_INVALID, |
| 11461 | ERR_CERT_AUTHORITY_INVALID, |
| 11462 | ERR_CERT_DATE_INVALID, |
| 11463 | }; |
| 11464 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11465 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11466 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11467 | } |
| 11468 | } |
| 11469 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11470 | // Ensure that a client certificate is removed from the SSL client auth |
| 11471 | // cache when: |
| 11472 | // 1) No proxy is involved. |
| 11473 | // 2) TLS False Start is disabled. |
| 11474 | // 3) The initial TLS handshake requests a client certificate. |
| 11475 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11476 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11477 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11478 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11479 | request_info.url = GURL("https://www.example.com/"); |
| 11480 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11481 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11482 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11483 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11484 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11485 | |
| 11486 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11487 | // CertificateRequest is received for the first time, the handshake will |
| 11488 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11489 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11490 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11492 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11494 | |
| 11495 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11496 | // False Start is not being used, the result of the SSL handshake will be |
| 11497 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11498 | // matches the result of a server sending a handshake_failure alert, |
| 11499 | // rather than a Finished message, because it requires a client |
| 11500 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11501 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11502 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11504 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11505 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11506 | |
| 11507 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11508 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11509 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11510 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11511 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11512 | // requiring a client certificate, this fallback handshake should also |
| 11513 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11514 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11515 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11517 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11518 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11519 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11520 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11521 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11522 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11523 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11524 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11525 | // requiring a client certificate, this fallback handshake should also |
| 11526 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11527 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11528 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11530 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11531 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11532 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11533 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11534 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11536 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11537 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11538 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11539 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11540 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11541 | |
| 11542 | // Complete the SSL handshake, which should abort due to requiring a |
| 11543 | // client certificate. |
| 11544 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11545 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11546 | |
| 11547 | // Indicate that no certificate should be supplied. From the perspective |
| 11548 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11549 | // certificate, so this is the same as supply a |
| 11550 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11551 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11552 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11553 | |
| 11554 | // Ensure the certificate was added to the client auth cache before |
| 11555 | // allowing the connection to continue restarting. |
| 11556 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11557 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11558 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11559 | ASSERT_EQ(NULL, client_cert.get()); |
| 11560 | |
| 11561 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11562 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11563 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11564 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11565 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11566 | |
| 11567 | // Ensure that the client certificate is removed from the cache on a |
| 11568 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11569 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11570 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11571 | } |
| 11572 | |
| 11573 | // Ensure that a client certificate is removed from the SSL client auth |
| 11574 | // cache when: |
| 11575 | // 1) No proxy is involved. |
| 11576 | // 2) TLS False Start is enabled. |
| 11577 | // 3) The initial TLS handshake requests a client certificate. |
| 11578 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11579 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11580 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11581 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11582 | request_info.url = GURL("https://www.example.com/"); |
| 11583 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11584 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11585 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11586 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11587 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11588 | |
| 11589 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11590 | // return successfully after reading up to the peer's Certificate message. |
| 11591 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11592 | // enqueue application data to be sent in the same packet as the |
| 11593 | // ChangeCipherSpec and Finished messages. |
| 11594 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11595 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11596 | // Finished messages. If there was an error negotiating with the peer, |
| 11597 | // such as due to the peer requiring a client certificate when none was |
| 11598 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11599 | // called. |
| 11600 | |
| 11601 | // Like the non-False Start case, when a client certificate is requested by |
| 11602 | // the peer, the handshake is aborted during the Connect() call. |
| 11603 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11604 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11605 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11607 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11608 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11609 | |
| 11610 | // When a client certificate is supplied, Connect() will not be aborted |
| 11611 | // when the peer requests the certificate. Instead, the handshake will |
| 11612 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11613 | // the socket. The handshake messages are not processed until Read() is |
| 11614 | // called, which then detects that the handshake was aborted, due to the |
| 11615 | // peer sending a handshake_failure because it requires a client |
| 11616 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11617 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11618 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11620 | MockRead data2_reads[] = { |
| 11621 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11622 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11623 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11624 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11625 | |
| 11626 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11627 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11628 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11629 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11630 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11632 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11633 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11634 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11635 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11636 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11637 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11638 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11639 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11640 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11641 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11642 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11643 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11644 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11645 | ssl_data5.cert_request_info = cert_request.get(); |
| 11646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11647 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11648 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11649 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11650 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11651 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11652 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11653 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11654 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11655 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11656 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11657 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11658 | |
| 11659 | // Complete the SSL handshake, which should abort due to requiring a |
| 11660 | // client certificate. |
| 11661 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11662 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11663 | |
| 11664 | // Indicate that no certificate should be supplied. From the perspective |
| 11665 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11666 | // certificate, so this is the same as supply a |
| 11667 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11668 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11669 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11670 | |
| 11671 | // Ensure the certificate was added to the client auth cache before |
| 11672 | // allowing the connection to continue restarting. |
| 11673 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11674 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11675 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11676 | ASSERT_EQ(NULL, client_cert.get()); |
| 11677 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11678 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11679 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11680 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11681 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11682 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11683 | |
| 11684 | // Ensure that the client certificate is removed from the cache on a |
| 11685 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11686 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11687 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11688 | } |
| 11689 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11690 | // Ensure that a client certificate is removed from the SSL client auth |
| 11691 | // cache when: |
| 11692 | // 1) An HTTPS proxy is involved. |
| 11693 | // 3) The HTTPS proxy requests a client certificate. |
| 11694 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11695 | // proxy. |
| 11696 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11697 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11698 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11699 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11700 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11701 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11702 | |
| 11703 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11704 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11705 | |
| 11706 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11707 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11708 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11709 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11710 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11711 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11713 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11714 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11715 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11716 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11717 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11719 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11720 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11721 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11722 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11723 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11724 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11725 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11727 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11728 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11729 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11730 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11731 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11732 | requests[0].url = GURL("https://www.example.com/"); |
| 11733 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11734 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11735 | |
| 11736 | requests[1].url = GURL("http://www.example.com/"); |
| 11737 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11738 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11739 | |
| 11740 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11741 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11742 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11743 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11744 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11745 | |
| 11746 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11747 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11748 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11749 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11750 | |
| 11751 | // Complete the SSL handshake, which should abort due to requiring a |
| 11752 | // client certificate. |
| 11753 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11754 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11755 | |
| 11756 | // Indicate that no certificate should be supplied. From the perspective |
| 11757 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11758 | // certificate, so this is the same as supply a |
| 11759 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11760 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11761 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11762 | |
| 11763 | // Ensure the certificate was added to the client auth cache before |
| 11764 | // allowing the connection to continue restarting. |
| 11765 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11766 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11767 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11768 | ASSERT_EQ(NULL, client_cert.get()); |
| 11769 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11770 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11771 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11772 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11773 | |
| 11774 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11775 | // then consume ssl_data3, which should also fail. The result code is |
| 11776 | // checked against what ssl_data3 should return. |
| 11777 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11778 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11779 | |
| 11780 | // Now that the new handshake has failed, ensure that the client |
| 11781 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11782 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11783 | HostPortPair("proxy", 70), &client_cert)); |
| 11784 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11785 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11786 | } |
| 11787 | } |
| 11788 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11789 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11790 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11791 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11792 | |
| 11793 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11794 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11795 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11796 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11797 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11798 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11799 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11800 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11802 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11803 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11804 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11805 | scoped_ptr<SpdyFrame> host2_req( |
| 11806 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11807 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11808 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11809 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11810 | scoped_ptr<SpdyFrame> host1_resp( |
| 11811 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11812 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11813 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11814 | scoped_ptr<SpdyFrame> host2_resp( |
| 11815 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11816 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11817 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11818 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11819 | CreateMockRead(*host1_resp, 1), |
| 11820 | CreateMockRead(*host1_resp_body, 2), |
| 11821 | CreateMockRead(*host2_resp, 4), |
| 11822 | CreateMockRead(*host2_resp_body, 5), |
| 11823 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11824 | }; |
| 11825 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11826 | IPAddressNumber ip; |
| 11827 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11828 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11829 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11830 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11831 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11832 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11833 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11834 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11835 | HttpRequestInfo request1; |
| 11836 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11837 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11838 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11839 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11841 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11843 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11844 | |
| 11845 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11846 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11847 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11848 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11849 | |
| 11850 | std::string response_data; |
| 11851 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11852 | EXPECT_EQ("hello!", response_data); |
| 11853 | |
| 11854 | // Preload www.gmail.com into HostCache. |
| 11855 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11856 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11857 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11858 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11859 | DEFAULT_PRIORITY, |
| 11860 | &ignored, |
| 11861 | callback.callback(), |
| 11862 | NULL, |
| 11863 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11865 | rv = callback.WaitForResult(); |
| 11866 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11867 | |
| 11868 | HttpRequestInfo request2; |
| 11869 | request2.method = "GET"; |
| 11870 | request2.url = GURL("https://www.gmail.com/"); |
| 11871 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11872 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11874 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11876 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11877 | |
| 11878 | response = trans2.GetResponseInfo(); |
| 11879 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11880 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11881 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11882 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11883 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11884 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11885 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11886 | } |
| 11887 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11888 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11889 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11890 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11891 | |
| 11892 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11893 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11894 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11895 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11896 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11897 | |
| 11898 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11899 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11901 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11902 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11903 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11904 | scoped_ptr<SpdyFrame> host2_req( |
| 11905 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11906 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11907 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11908 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11909 | scoped_ptr<SpdyFrame> host1_resp( |
| 11910 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11911 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11912 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11913 | scoped_ptr<SpdyFrame> host2_resp( |
| 11914 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11915 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11916 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11917 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11918 | CreateMockRead(*host1_resp, 1), |
| 11919 | CreateMockRead(*host1_resp_body, 2), |
| 11920 | CreateMockRead(*host2_resp, 4), |
| 11921 | CreateMockRead(*host2_resp_body, 5), |
| 11922 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11923 | }; |
| 11924 | |
| 11925 | IPAddressNumber ip; |
| 11926 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11927 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11928 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11929 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11930 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11931 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11932 | |
| 11933 | TestCompletionCallback callback; |
| 11934 | HttpRequestInfo request1; |
| 11935 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11936 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11937 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11938 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11939 | |
| 11940 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11942 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11943 | |
| 11944 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11945 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11946 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11947 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11948 | |
| 11949 | std::string response_data; |
| 11950 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11951 | EXPECT_EQ("hello!", response_data); |
| 11952 | |
| 11953 | HttpRequestInfo request2; |
| 11954 | request2.method = "GET"; |
| 11955 | request2.url = GURL("https://www.gmail.com/"); |
| 11956 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11957 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11958 | |
| 11959 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11961 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11962 | |
| 11963 | response = trans2.GetResponseInfo(); |
| 11964 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11965 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11966 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11967 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11968 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11969 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11970 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11971 | } |
| 11972 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11973 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11974 | public: |
| 11975 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11976 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11977 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11978 | |
| 11979 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11980 | |
| 11981 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11982 | int Resolve(const RequestInfo& info, |
| 11983 | RequestPriority priority, |
| 11984 | AddressList* addresses, |
| 11985 | const CompletionCallback& callback, |
| 11986 | RequestHandle* out_req, |
| 11987 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11988 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11989 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11990 | } |
| 11991 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11992 | int ResolveFromCache(const RequestInfo& info, |
| 11993 | AddressList* addresses, |
| 11994 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11995 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11996 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11997 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11998 | return rv; |
| 11999 | } |
| 12000 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12001 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12002 | host_resolver_.CancelRequest(req); |
| 12003 | } |
| 12004 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12005 | MockCachingHostResolver* GetMockHostResolver() { |
| 12006 | return &host_resolver_; |
| 12007 | } |
| 12008 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12009 | private: |
| 12010 | MockCachingHostResolver host_resolver_; |
| 12011 | const HostPortPair host_port_; |
| 12012 | }; |
| 12013 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12014 | TEST_P(HttpNetworkTransactionTest, |
| 12015 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12016 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12017 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12018 | |
| 12019 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12020 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12021 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12022 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12023 | params.host_resolver = &host_resolver; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12024 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12025 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12026 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12027 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12028 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12029 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12031 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12032 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12033 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12034 | scoped_ptr<SpdyFrame> host2_req( |
| 12035 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12036 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12037 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12038 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12039 | scoped_ptr<SpdyFrame> host1_resp( |
| 12040 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12041 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12042 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12043 | scoped_ptr<SpdyFrame> host2_resp( |
| 12044 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12045 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12046 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12047 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12048 | CreateMockRead(*host1_resp, 1), |
| 12049 | CreateMockRead(*host1_resp_body, 2), |
| 12050 | CreateMockRead(*host2_resp, 4), |
| 12051 | CreateMockRead(*host2_resp_body, 5), |
| 12052 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12053 | }; |
| 12054 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12055 | IPAddressNumber ip; |
| 12056 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12057 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12058 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12059 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12060 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12061 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12062 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12063 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12064 | HttpRequestInfo request1; |
| 12065 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12066 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12067 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12068 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12070 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12072 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12073 | |
| 12074 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12075 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12076 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12077 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12078 | |
| 12079 | std::string response_data; |
| 12080 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12081 | EXPECT_EQ("hello!", response_data); |
| 12082 | |
| 12083 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12084 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12085 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12086 | rv = host_resolver.Resolve(resolve_info, |
| 12087 | DEFAULT_PRIORITY, |
| 12088 | &ignored, |
| 12089 | callback.callback(), |
| 12090 | NULL, |
| 12091 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12092 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12093 | rv = callback.WaitForResult(); |
| 12094 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12095 | |
| 12096 | HttpRequestInfo request2; |
| 12097 | request2.method = "GET"; |
| 12098 | request2.url = GURL("https://www.gmail.com/"); |
| 12099 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12100 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12102 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12104 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12105 | |
| 12106 | response = trans2.GetResponseInfo(); |
| 12107 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12108 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12109 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12110 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12111 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12112 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12113 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12114 | } |
| 12115 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12116 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12117 | const std::string https_url = "https://www.example.org:8080/"; |
| 12118 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12119 | |
| 12120 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12121 | scoped_ptr<SpdyFrame> req1( |
| 12122 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12123 | |
| 12124 | MockWrite writes1[] = { |
| 12125 | CreateMockWrite(*req1, 0), |
| 12126 | }; |
| 12127 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12128 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12129 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12130 | MockRead reads1[] = { |
| 12131 | CreateMockRead(*resp1, 1), |
| 12132 | CreateMockRead(*body1, 2), |
| 12133 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12134 | }; |
| 12135 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12136 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12137 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12138 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12139 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12140 | |
| 12141 | // HTTP GET for the HTTP URL |
| 12142 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12143 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12144 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12145 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12146 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12147 | }; |
| 12148 | |
| 12149 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12150 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12151 | MockRead(ASYNC, 2, "hello"), |
| 12152 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12153 | }; |
| 12154 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12155 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12156 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12157 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12158 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12159 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12162 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12163 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12164 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12165 | |
| 12166 | // Start the first transaction to set up the SpdySession |
| 12167 | HttpRequestInfo request1; |
| 12168 | request1.method = "GET"; |
| 12169 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12170 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12171 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12172 | TestCompletionCallback callback1; |
| 12173 | EXPECT_EQ(ERR_IO_PENDING, |
| 12174 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12175 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12176 | |
| 12177 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12178 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12179 | |
| 12180 | // Now, start the HTTP request |
| 12181 | HttpRequestInfo request2; |
| 12182 | request2.method = "GET"; |
| 12183 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12184 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12185 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12186 | TestCompletionCallback callback2; |
| 12187 | EXPECT_EQ(ERR_IO_PENDING, |
| 12188 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12189 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12190 | |
| 12191 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12192 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12193 | } |
| 12194 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12195 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12196 | public: |
| 12197 | void Run(bool pooling, bool valid) { |
| 12198 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12199 | 443); |
| 12200 | HostPortPair alternative("www.example.org", 443); |
| 12201 | |
| 12202 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12203 | scoped_refptr<X509Certificate> cert( |
| 12204 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12205 | ASSERT_TRUE(cert.get()); |
| 12206 | bool common_name_fallback_used; |
| 12207 | EXPECT_EQ(valid, |
| 12208 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12209 | EXPECT_TRUE( |
| 12210 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12211 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12212 | ssl.SetNextProto(GetParam()); |
| 12213 | ssl.cert = cert; |
| 12214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12215 | |
| 12216 | // If pooling, then start a request to alternative first to create a |
| 12217 | // SpdySession. |
| 12218 | std::string url0 = "https://www.example.org:443"; |
| 12219 | // Second request to origin, which has an alternative service, and could |
| 12220 | // open a connection to the alternative host or pool to the existing one. |
| 12221 | std::string url1("https://"); |
| 12222 | url1.append(origin.host()); |
| 12223 | url1.append(":443"); |
| 12224 | |
| 12225 | scoped_ptr<SpdyFrame> req0; |
| 12226 | scoped_ptr<SpdyFrame> req1; |
| 12227 | scoped_ptr<SpdyFrame> resp0; |
| 12228 | scoped_ptr<SpdyFrame> body0; |
| 12229 | scoped_ptr<SpdyFrame> resp1; |
| 12230 | scoped_ptr<SpdyFrame> body1; |
| 12231 | std::vector<MockWrite> writes; |
| 12232 | std::vector<MockRead> reads; |
| 12233 | |
| 12234 | if (pooling) { |
| 12235 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12236 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12237 | |
| 12238 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12239 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12240 | |
| 12241 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12242 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12243 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12244 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12245 | |
| 12246 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12247 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12248 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12249 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12250 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12251 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12252 | } else { |
| 12253 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12254 | |
| 12255 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12256 | |
| 12257 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12258 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12259 | |
| 12260 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12261 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12262 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12263 | } |
| 12264 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12265 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12266 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12267 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12268 | |
| 12269 | // Connection to the origin fails. |
| 12270 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12271 | StaticSocketDataProvider data_refused; |
| 12272 | data_refused.set_connect_data(mock_connect); |
| 12273 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12274 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12275 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12276 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12277 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12278 | session->http_server_properties(); |
| 12279 | AlternativeService alternative_service( |
| 12280 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12281 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12282 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12283 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12284 | |
| 12285 | // First request to alternative. |
| 12286 | if (pooling) { |
| 12287 | scoped_ptr<HttpTransaction> trans0( |
| 12288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12289 | HttpRequestInfo request0; |
| 12290 | request0.method = "GET"; |
| 12291 | request0.url = GURL(url0); |
| 12292 | request0.load_flags = 0; |
| 12293 | TestCompletionCallback callback0; |
| 12294 | |
| 12295 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12297 | rv = callback0.WaitForResult(); |
| 12298 | EXPECT_EQ(OK, rv); |
| 12299 | } |
| 12300 | |
| 12301 | // Second request to origin. |
| 12302 | scoped_ptr<HttpTransaction> trans1( |
| 12303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12304 | HttpRequestInfo request1; |
| 12305 | request1.method = "GET"; |
| 12306 | request1.url = GURL(url1); |
| 12307 | request1.load_flags = 0; |
| 12308 | TestCompletionCallback callback1; |
| 12309 | |
| 12310 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12311 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12312 | base::MessageLoop::current()->RunUntilIdle(); |
| 12313 | if (data.IsReadPaused()) { |
| 12314 | data.CompleteRead(); |
| 12315 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12316 | rv = callback1.WaitForResult(); |
| 12317 | if (valid) { |
| 12318 | EXPECT_EQ(OK, rv); |
| 12319 | } else { |
| 12320 | if (pooling) { |
| 12321 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12322 | } else { |
| 12323 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12324 | } |
| 12325 | } |
| 12326 | } |
| 12327 | }; |
| 12328 | |
| 12329 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12330 | AltSvcCertificateVerificationTest, |
| 12331 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12332 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12333 | |
| 12334 | // The alternative service host must exhibit a certificate that is valid for the |
| 12335 | // origin host. Test that this is enforced when pooling to an existing |
| 12336 | // connection. |
| 12337 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12338 | Run(true, true); |
| 12339 | } |
| 12340 | |
| 12341 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12342 | Run(true, false); |
| 12343 | } |
| 12344 | |
| 12345 | // The alternative service host must exhibit a certificate that is valid for the |
| 12346 | // origin host. Test that this is enforced when opening a new connection. |
| 12347 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12348 | Run(false, true); |
| 12349 | } |
| 12350 | |
| 12351 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12352 | Run(false, false); |
| 12353 | } |
| 12354 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12355 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12356 | // with the alternative server. That connection should not be used. |
| 12357 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12358 | HostPortPair origin("origin.example.org", 443); |
| 12359 | HostPortPair alternative("alternative.example.org", 443); |
| 12360 | |
| 12361 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12362 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12363 | ssl.SetNextProto(kProtoHTTP11); |
| 12364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12365 | |
| 12366 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12367 | // negotiated. |
| 12368 | StaticSocketDataProvider data; |
| 12369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12370 | |
| 12371 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12372 | // negotiated. In order to test this, a failed connection to the origin is |
| 12373 | // mocked. This way the request relies on the alternate Job. |
| 12374 | StaticSocketDataProvider data_refused; |
| 12375 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12376 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12377 | |
| 12378 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12379 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12380 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12381 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12382 | session->http_server_properties(); |
| 12383 | AlternativeService alternative_service( |
| 12384 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12385 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12386 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12387 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12388 | |
| 12389 | scoped_ptr<HttpTransaction> trans( |
| 12390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12391 | HttpRequestInfo request; |
| 12392 | request.method = "GET"; |
| 12393 | request.url = GURL("https://origin.example.org:443"); |
| 12394 | request.load_flags = 0; |
| 12395 | TestCompletionCallback callback; |
| 12396 | |
| 12397 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12398 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12399 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12400 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12401 | } |
| 12402 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12403 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12404 | // origin, and an alternate one to the alternative server. If the former |
| 12405 | // succeeds, the request should succeed, even if the latter fails because |
| 12406 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12407 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12408 | HostPortPair origin("origin.example.org", 443); |
| 12409 | HostPortPair alternative("alternative.example.org", 443); |
| 12410 | |
| 12411 | // Negotiate HTTP/1.1 with alternative. |
| 12412 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12413 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12415 | |
| 12416 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12417 | // negotiated. |
| 12418 | StaticSocketDataProvider data; |
| 12419 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12420 | |
| 12421 | // Negotiate HTTP/1.1 with origin. |
| 12422 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12423 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12425 | |
| 12426 | MockWrite http_writes[] = { |
| 12427 | MockWrite( |
| 12428 | "GET / HTTP/1.1\r\n" |
| 12429 | "Host: origin.example.org\r\n" |
| 12430 | "Connection: keep-alive\r\n\r\n"), |
| 12431 | MockWrite( |
| 12432 | "GET /second HTTP/1.1\r\n" |
| 12433 | "Host: origin.example.org\r\n" |
| 12434 | "Connection: keep-alive\r\n\r\n"), |
| 12435 | }; |
| 12436 | |
| 12437 | MockRead http_reads[] = { |
| 12438 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12439 | MockRead("Content-Type: text/html\r\n"), |
| 12440 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12441 | MockRead("foobar"), |
| 12442 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12443 | MockRead("Content-Type: text/html\r\n"), |
| 12444 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12445 | MockRead("another"), |
| 12446 | }; |
| 12447 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12448 | http_writes, arraysize(http_writes)); |
| 12449 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12450 | |
| 12451 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12452 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12453 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12454 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12455 | session->http_server_properties(); |
| 12456 | AlternativeService alternative_service( |
| 12457 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12458 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12459 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12460 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12461 | |
| 12462 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12463 | HttpRequestInfo request1; |
| 12464 | request1.method = "GET"; |
| 12465 | request1.url = GURL("https://origin.example.org:443"); |
| 12466 | request1.load_flags = 0; |
| 12467 | TestCompletionCallback callback1; |
| 12468 | |
| 12469 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12470 | rv = callback1.GetResult(rv); |
| 12471 | EXPECT_EQ(OK, rv); |
| 12472 | |
| 12473 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12474 | ASSERT_TRUE(response1 != nullptr); |
| 12475 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12476 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12477 | |
| 12478 | std::string response_data1; |
| 12479 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12480 | EXPECT_EQ("foobar", response_data1); |
| 12481 | |
| 12482 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12483 | // for alternative service. |
| 12484 | EXPECT_TRUE( |
| 12485 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12486 | |
| 12487 | // Since |alternative_service| is broken, a second transaction to origin |
| 12488 | // should not start an alternate Job. It should pool to existing connection |
| 12489 | // to origin. |
| 12490 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12491 | HttpRequestInfo request2; |
| 12492 | request2.method = "GET"; |
| 12493 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12494 | request2.load_flags = 0; |
| 12495 | TestCompletionCallback callback2; |
| 12496 | |
| 12497 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12498 | rv = callback2.GetResult(rv); |
| 12499 | EXPECT_EQ(OK, rv); |
| 12500 | |
| 12501 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12502 | ASSERT_TRUE(response2 != nullptr); |
| 12503 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12504 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12505 | |
| 12506 | std::string response_data2; |
| 12507 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12508 | EXPECT_EQ("another", response_data2); |
| 12509 | } |
| 12510 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12511 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12512 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12513 | // used. |
| 12514 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12515 | HostPortPair origin("origin.example.org", 443); |
| 12516 | HostPortPair alternative("alternative.example.org", 443); |
| 12517 | std::string origin_url = "https://origin.example.org:443"; |
| 12518 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12519 | |
| 12520 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12521 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12522 | ssl.SetNextProto(kProtoHTTP11); |
| 12523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12524 | |
| 12525 | // HTTP/1.1 data for |request1| and |request2|. |
| 12526 | MockWrite http_writes[] = { |
| 12527 | MockWrite( |
| 12528 | "GET / HTTP/1.1\r\n" |
| 12529 | "Host: alternative.example.org\r\n" |
| 12530 | "Connection: keep-alive\r\n\r\n"), |
| 12531 | MockWrite( |
| 12532 | "GET / HTTP/1.1\r\n" |
| 12533 | "Host: alternative.example.org\r\n" |
| 12534 | "Connection: keep-alive\r\n\r\n"), |
| 12535 | }; |
| 12536 | |
| 12537 | MockRead http_reads[] = { |
| 12538 | MockRead( |
| 12539 | "HTTP/1.1 200 OK\r\n" |
| 12540 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12541 | "Content-Length: 40\r\n\r\n" |
| 12542 | "first HTTP/1.1 response from alternative"), |
| 12543 | MockRead( |
| 12544 | "HTTP/1.1 200 OK\r\n" |
| 12545 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12546 | "Content-Length: 41\r\n\r\n" |
| 12547 | "second HTTP/1.1 response from alternative"), |
| 12548 | }; |
| 12549 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12550 | http_writes, arraysize(http_writes)); |
| 12551 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12552 | |
| 12553 | // This test documents that an alternate Job should not pool to an already |
| 12554 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12555 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12556 | StaticSocketDataProvider data_refused; |
| 12557 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12558 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12559 | |
| 12560 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12561 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12562 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12563 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12564 | session->http_server_properties(); |
| 12565 | AlternativeService alternative_service( |
| 12566 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12567 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12568 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12569 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12570 | |
| 12571 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12572 | scoped_ptr<HttpTransaction> trans1( |
| 12573 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12574 | HttpRequestInfo request1; |
| 12575 | request1.method = "GET"; |
| 12576 | request1.url = GURL(alternative_url); |
| 12577 | request1.load_flags = 0; |
| 12578 | TestCompletionCallback callback1; |
| 12579 | |
| 12580 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12581 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12582 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12583 | ASSERT_TRUE(response1); |
| 12584 | ASSERT_TRUE(response1->headers.get()); |
| 12585 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12586 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12587 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12588 | std::string response_data1; |
| 12589 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12590 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12591 | |
| 12592 | // Request for origin.example.org, which has an alternative service. This |
| 12593 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12594 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12595 | // open other connections to alternative server. The Job to origin fails, so |
| 12596 | // this request fails. |
| 12597 | scoped_ptr<HttpTransaction> trans2( |
| 12598 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12599 | HttpRequestInfo request2; |
| 12600 | request2.method = "GET"; |
| 12601 | request2.url = GURL(origin_url); |
| 12602 | request2.load_flags = 0; |
| 12603 | TestCompletionCallback callback2; |
| 12604 | |
| 12605 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12606 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12607 | |
| 12608 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12609 | // socket is still open and in the pool. |
| 12610 | scoped_ptr<HttpTransaction> trans3( |
| 12611 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12612 | HttpRequestInfo request3; |
| 12613 | request3.method = "GET"; |
| 12614 | request3.url = GURL(alternative_url); |
| 12615 | request3.load_flags = 0; |
| 12616 | TestCompletionCallback callback3; |
| 12617 | |
| 12618 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12619 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12620 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12621 | ASSERT_TRUE(response3); |
| 12622 | ASSERT_TRUE(response3->headers.get()); |
| 12623 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12624 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12625 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12626 | std::string response_data3; |
| 12627 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12628 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12629 | } |
| 12630 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12631 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12632 | const std::string https_url = "https://www.example.org:8080/"; |
| 12633 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12634 | |
| 12635 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12636 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12637 | scoped_ptr<SpdyFrame> connect( |
| 12638 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12639 | scoped_ptr<SpdyFrame> req1( |
| 12640 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12641 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12642 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12643 | |
| 12644 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12645 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 12646 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12647 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12648 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12649 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 12650 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12651 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12652 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12653 | |
| 12654 | MockWrite writes1[] = { |
| 12655 | CreateMockWrite(*connect, 0), |
| 12656 | CreateMockWrite(*wrapped_req1, 2), |
| 12657 | CreateMockWrite(*req2, 5), |
| 12658 | }; |
| 12659 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12660 | scoped_ptr<SpdyFrame> conn_resp( |
| 12661 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12662 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12663 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12664 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12665 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12666 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12667 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12668 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12669 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12670 | MockRead reads1[] = { |
| 12671 | CreateMockRead(*conn_resp, 1), |
| 12672 | CreateMockRead(*wrapped_resp1, 3), |
| 12673 | CreateMockRead(*wrapped_body1, 4), |
| 12674 | CreateMockRead(*resp2, 6), |
| 12675 | CreateMockRead(*body2, 7), |
| 12676 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12677 | }; |
| 12678 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12679 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12680 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12681 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12682 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12683 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12684 | session_deps_.proxy_service = |
| 12685 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12686 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12688 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12689 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12690 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12691 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12692 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12693 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12694 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12695 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12696 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12697 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12698 | |
| 12699 | // Start the first transaction to set up the SpdySession |
| 12700 | HttpRequestInfo request1; |
| 12701 | request1.method = "GET"; |
| 12702 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12703 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12704 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12705 | TestCompletionCallback callback1; |
| 12706 | EXPECT_EQ(ERR_IO_PENDING, |
| 12707 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12708 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12709 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12710 | |
| 12711 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12712 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12713 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12714 | LoadTimingInfo load_timing_info1; |
| 12715 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12716 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12717 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12718 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12719 | // Now, start the HTTP request |
| 12720 | HttpRequestInfo request2; |
| 12721 | request2.method = "GET"; |
| 12722 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12723 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12724 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12725 | TestCompletionCallback callback2; |
| 12726 | EXPECT_EQ(ERR_IO_PENDING, |
| 12727 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12728 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12729 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12730 | |
| 12731 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12732 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12733 | |
| 12734 | LoadTimingInfo load_timing_info2; |
| 12735 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12736 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12737 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12738 | // HTTP requests over a SPDY session should have a different connection |
| 12739 | // socket_log_id than requests over a tunnel. |
| 12740 | 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] | 12741 | } |
| 12742 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12743 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12744 | // that we do not pool other origins that resolve to the same IP when |
| 12745 | // the certificate does not match the new origin. |
| 12746 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12747 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12748 | const std::string url1 = "http://www.example.org/"; |
| 12749 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12750 | const std::string ip_addr = "1.2.3.4"; |
| 12751 | |
| 12752 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12753 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12754 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12755 | scoped_ptr<SpdyFrame> req1( |
| 12756 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12757 | |
| 12758 | MockWrite writes1[] = { |
| 12759 | CreateMockWrite(*req1, 0), |
| 12760 | }; |
| 12761 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12762 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12763 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12764 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12765 | CreateMockRead(*resp1, 1), |
| 12766 | CreateMockRead(*body1, 2), |
| 12767 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12768 | }; |
| 12769 | |
| 12770 | scoped_ptr<DeterministicSocketData> data1( |
| 12771 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12772 | writes1, arraysize(writes1))); |
| 12773 | IPAddressNumber ip; |
| 12774 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12775 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12776 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12777 | data1->set_connect_data(connect_data1); |
| 12778 | |
| 12779 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12780 | scoped_ptr<SpdyFrame> req2( |
| 12781 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12782 | |
| 12783 | MockWrite writes2[] = { |
| 12784 | CreateMockWrite(*req2, 0), |
| 12785 | }; |
| 12786 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12787 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12788 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12789 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12790 | CreateMockRead(*resp2, 1), |
| 12791 | CreateMockRead(*body2, 2), |
| 12792 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12793 | }; |
| 12794 | |
| 12795 | scoped_ptr<DeterministicSocketData> data2( |
| 12796 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12797 | writes2, arraysize(writes2))); |
| 12798 | MockConnect connect_data2(ASYNC, OK); |
| 12799 | data2->set_connect_data(connect_data2); |
| 12800 | |
| 12801 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12802 | // all others direct. |
| 12803 | ProxyConfig proxy_config; |
| 12804 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12805 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 12806 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 12807 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12808 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12809 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12810 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12811 | // Load a valid cert. Note, that this does not need to |
| 12812 | // be valid for proxy because the MockSSLClientSocket does |
| 12813 | // not actually verify it. But SpdySession will use this |
| 12814 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12815 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12816 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12817 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12818 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12819 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12820 | |
| 12821 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12822 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12823 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12824 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12825 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12826 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12827 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12828 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12829 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12830 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12831 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12832 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12833 | |
| 12834 | // Start the first transaction to set up the SpdySession |
| 12835 | HttpRequestInfo request1; |
| 12836 | request1.method = "GET"; |
| 12837 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12838 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12839 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12840 | TestCompletionCallback callback1; |
| 12841 | ASSERT_EQ(ERR_IO_PENDING, |
| 12842 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12843 | data1->RunFor(3); |
| 12844 | |
| 12845 | ASSERT_TRUE(callback1.have_result()); |
| 12846 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12847 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12848 | |
| 12849 | // Now, start the HTTP request |
| 12850 | HttpRequestInfo request2; |
| 12851 | request2.method = "GET"; |
| 12852 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12853 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12854 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12855 | TestCompletionCallback callback2; |
| 12856 | EXPECT_EQ(ERR_IO_PENDING, |
| 12857 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12858 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12859 | data2->RunFor(3); |
| 12860 | |
| 12861 | ASSERT_TRUE(callback2.have_result()); |
| 12862 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12863 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12864 | } |
| 12865 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12866 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12867 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12868 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12869 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12870 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12871 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12872 | |
| 12873 | MockRead reads1[] = { |
| 12874 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12875 | }; |
| 12876 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12877 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12878 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12879 | scoped_ptr<SpdyFrame> req2( |
| 12880 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12881 | MockWrite writes2[] = { |
| 12882 | CreateMockWrite(*req2, 0), |
| 12883 | }; |
| 12884 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12885 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12886 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12887 | MockRead reads2[] = { |
| 12888 | CreateMockRead(*resp2, 1), |
| 12889 | CreateMockRead(*body2, 2), |
| 12890 | MockRead(ASYNC, OK, 3) // EOF |
| 12891 | }; |
| 12892 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12893 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12894 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12895 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12896 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12897 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12898 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12900 | |
| 12901 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12902 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12904 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12905 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12906 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12907 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12908 | |
| 12909 | // Start the first transaction to set up the SpdySession and verify that |
| 12910 | // connection was closed. |
| 12911 | HttpRequestInfo request1; |
| 12912 | request1.method = "GET"; |
| 12913 | request1.url = GURL(https_url); |
| 12914 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12915 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12916 | TestCompletionCallback callback1; |
| 12917 | EXPECT_EQ(ERR_IO_PENDING, |
| 12918 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12919 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12920 | |
| 12921 | // Now, start the second request and make sure it succeeds. |
| 12922 | HttpRequestInfo request2; |
| 12923 | request2.method = "GET"; |
| 12924 | request2.url = GURL(https_url); |
| 12925 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12926 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12927 | TestCompletionCallback callback2; |
| 12928 | EXPECT_EQ(ERR_IO_PENDING, |
| 12929 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12930 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12931 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12932 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12933 | } |
| 12934 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12935 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12936 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12937 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12938 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12939 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12940 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12941 | |
| 12942 | // Use two different hosts with different IPs so they don't get pooled. |
| 12943 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12944 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12945 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12946 | |
| 12947 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12948 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12949 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12950 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12952 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12953 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12954 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12955 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12956 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12957 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12958 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12959 | scoped_ptr<SpdyFrame> host1_resp( |
| 12960 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12961 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12962 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12963 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12964 | CreateMockRead(*host1_resp, 1), |
| 12965 | CreateMockRead(*host1_resp_body, 2), |
| 12966 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12967 | }; |
| 12968 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12969 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12970 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12971 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12972 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12973 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12974 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12975 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12976 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12977 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12978 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12979 | scoped_ptr<SpdyFrame> host2_resp( |
| 12980 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12981 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12982 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12983 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12984 | CreateMockRead(*host2_resp, 1), |
| 12985 | CreateMockRead(*host2_resp_body, 2), |
| 12986 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12987 | }; |
| 12988 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12989 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12990 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12991 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12992 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12993 | |
| 12994 | MockWrite http_write[] = { |
| 12995 | MockWrite("GET / HTTP/1.1\r\n" |
| 12996 | "Host: www.a.com\r\n" |
| 12997 | "Connection: keep-alive\r\n\r\n"), |
| 12998 | }; |
| 12999 | |
| 13000 | MockRead http_read[] = { |
| 13001 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13002 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13003 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13004 | MockRead("hello!"), |
| 13005 | }; |
| 13006 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13007 | http_write, arraysize(http_write)); |
| 13008 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13009 | |
| 13010 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13011 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13012 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13013 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13014 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13015 | |
| 13016 | TestCompletionCallback callback; |
| 13017 | HttpRequestInfo request1; |
| 13018 | request1.method = "GET"; |
| 13019 | request1.url = GURL("https://www.a.com/"); |
| 13020 | request1.load_flags = 0; |
| 13021 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13023 | |
| 13024 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13025 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13026 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13027 | |
| 13028 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13029 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13030 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13031 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13032 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13033 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13034 | |
| 13035 | std::string response_data; |
| 13036 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13037 | EXPECT_EQ("hello!", response_data); |
| 13038 | trans.reset(); |
| 13039 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13040 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13041 | |
| 13042 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13043 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13044 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13045 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13046 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13047 | HttpRequestInfo request2; |
| 13048 | request2.method = "GET"; |
| 13049 | request2.url = GURL("https://www.b.com/"); |
| 13050 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13051 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13052 | |
| 13053 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13055 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13056 | |
| 13057 | response = trans->GetResponseInfo(); |
| 13058 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13059 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13060 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13061 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13062 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13063 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13064 | EXPECT_EQ("hello!", response_data); |
| 13065 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13066 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13067 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13068 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13069 | |
| 13070 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13071 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13072 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13073 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13074 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13075 | HttpRequestInfo request3; |
| 13076 | request3.method = "GET"; |
| 13077 | request3.url = GURL("http://www.a.com/"); |
| 13078 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13079 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13080 | |
| 13081 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13083 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13084 | |
| 13085 | response = trans->GetResponseInfo(); |
| 13086 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13087 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13089 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13090 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13091 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13092 | EXPECT_EQ("hello!", response_data); |
| 13093 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13094 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13095 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13096 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13097 | } |
| 13098 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13099 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13100 | HttpRequestInfo request; |
| 13101 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13102 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13103 | request.load_flags = 0; |
| 13104 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13105 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13106 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13107 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13108 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13109 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13110 | StaticSocketDataProvider data; |
| 13111 | data.set_connect_data(mock_connect); |
| 13112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13113 | |
| 13114 | TestCompletionCallback callback; |
| 13115 | |
| 13116 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13117 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13118 | |
| 13119 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13120 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13121 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13122 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13123 | HttpRequestHeaders request_headers; |
| 13124 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13125 | |
| 13126 | ConnectionAttempts attempts; |
| 13127 | trans->GetConnectionAttempts(&attempts); |
| 13128 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13129 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13130 | |
| 13131 | IPEndPoint endpoint; |
| 13132 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13133 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13134 | } |
| 13135 | |
| 13136 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13137 | HttpRequestInfo request; |
| 13138 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13139 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13140 | request.load_flags = 0; |
| 13141 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13142 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13143 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13144 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13145 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13146 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13147 | StaticSocketDataProvider data; |
| 13148 | data.set_connect_data(mock_connect); |
| 13149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13150 | |
| 13151 | TestCompletionCallback callback; |
| 13152 | |
| 13153 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13155 | |
| 13156 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13157 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13158 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13159 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13160 | HttpRequestHeaders request_headers; |
| 13161 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13162 | |
| 13163 | ConnectionAttempts attempts; |
| 13164 | trans->GetConnectionAttempts(&attempts); |
| 13165 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13166 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13167 | |
| 13168 | IPEndPoint endpoint; |
| 13169 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13170 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13171 | } |
| 13172 | |
| 13173 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13174 | HttpRequestInfo request; |
| 13175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13176 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13177 | request.load_flags = 0; |
| 13178 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13179 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13180 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13182 | |
| 13183 | MockWrite data_writes[] = { |
| 13184 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13185 | }; |
| 13186 | MockRead data_reads[] = { |
| 13187 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13188 | }; |
| 13189 | |
| 13190 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13191 | data_writes, arraysize(data_writes)); |
| 13192 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13193 | |
| 13194 | TestCompletionCallback callback; |
| 13195 | |
| 13196 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13197 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13198 | |
| 13199 | rv = callback.WaitForResult(); |
| 13200 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13201 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13202 | HttpRequestHeaders request_headers; |
| 13203 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13204 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13205 | } |
| 13206 | |
| 13207 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13208 | HttpRequestInfo request; |
| 13209 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13210 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13211 | request.load_flags = 0; |
| 13212 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13213 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13214 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13216 | |
| 13217 | MockWrite data_writes[] = { |
| 13218 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13219 | }; |
| 13220 | MockRead data_reads[] = { |
| 13221 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13222 | }; |
| 13223 | |
| 13224 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13225 | data_writes, arraysize(data_writes)); |
| 13226 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13227 | |
| 13228 | TestCompletionCallback callback; |
| 13229 | |
| 13230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13232 | |
| 13233 | rv = callback.WaitForResult(); |
| 13234 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13235 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13236 | HttpRequestHeaders request_headers; |
| 13237 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13238 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13239 | } |
| 13240 | |
| 13241 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13242 | HttpRequestInfo request; |
| 13243 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13244 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13245 | request.load_flags = 0; |
| 13246 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13247 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13248 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13250 | |
| 13251 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13252 | MockWrite( |
| 13253 | "GET / HTTP/1.1\r\n" |
| 13254 | "Host: www.example.org\r\n" |
| 13255 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13256 | }; |
| 13257 | MockRead data_reads[] = { |
| 13258 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13259 | }; |
| 13260 | |
| 13261 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13262 | data_writes, arraysize(data_writes)); |
| 13263 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13264 | |
| 13265 | TestCompletionCallback callback; |
| 13266 | |
| 13267 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13268 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13269 | |
| 13270 | rv = callback.WaitForResult(); |
| 13271 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13272 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13273 | HttpRequestHeaders request_headers; |
| 13274 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13275 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13276 | } |
| 13277 | |
| 13278 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13279 | HttpRequestInfo request; |
| 13280 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13281 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13282 | request.load_flags = 0; |
| 13283 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13284 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13285 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13287 | |
| 13288 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13289 | MockWrite( |
| 13290 | "GET / HTTP/1.1\r\n" |
| 13291 | "Host: www.example.org\r\n" |
| 13292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13293 | }; |
| 13294 | MockRead data_reads[] = { |
| 13295 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13296 | }; |
| 13297 | |
| 13298 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13299 | data_writes, arraysize(data_writes)); |
| 13300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13301 | |
| 13302 | TestCompletionCallback callback; |
| 13303 | |
| 13304 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13306 | |
| 13307 | rv = callback.WaitForResult(); |
| 13308 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13309 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13310 | HttpRequestHeaders request_headers; |
| 13311 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13312 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13313 | } |
| 13314 | |
| 13315 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13316 | HttpRequestInfo request; |
| 13317 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13318 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13319 | request.load_flags = 0; |
| 13320 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13321 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13322 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13323 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13324 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13325 | |
| 13326 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13327 | MockWrite( |
| 13328 | "GET / HTTP/1.1\r\n" |
| 13329 | "Host: www.example.org\r\n" |
| 13330 | "Connection: keep-alive\r\n" |
| 13331 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13332 | }; |
| 13333 | MockRead data_reads[] = { |
| 13334 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13335 | "Content-Length: 5\r\n\r\n" |
| 13336 | "hello"), |
| 13337 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13338 | }; |
| 13339 | |
| 13340 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13341 | data_writes, arraysize(data_writes)); |
| 13342 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13343 | |
| 13344 | TestCompletionCallback callback; |
| 13345 | |
| 13346 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13347 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13348 | |
| 13349 | rv = callback.WaitForResult(); |
| 13350 | EXPECT_EQ(OK, rv); |
| 13351 | |
| 13352 | HttpRequestHeaders request_headers; |
| 13353 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13354 | std::string foo; |
| 13355 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13356 | EXPECT_EQ("bar", foo); |
| 13357 | } |
| 13358 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13359 | namespace { |
| 13360 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13361 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13362 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13363 | public base::SupportsWeakPtr<FakeStream> { |
| 13364 | public: |
| 13365 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13366 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13367 | |
| 13368 | RequestPriority priority() const { return priority_; } |
| 13369 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13370 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13371 | RequestPriority priority, |
| 13372 | const BoundNetLog& net_log, |
| 13373 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13374 | return ERR_IO_PENDING; |
| 13375 | } |
| 13376 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13377 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13378 | HttpResponseInfo* response, |
| 13379 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13380 | ADD_FAILURE(); |
| 13381 | return ERR_UNEXPECTED; |
| 13382 | } |
| 13383 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13384 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13385 | ADD_FAILURE(); |
| 13386 | return ERR_UNEXPECTED; |
| 13387 | } |
| 13388 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13389 | int ReadResponseBody(IOBuffer* buf, |
| 13390 | int buf_len, |
| 13391 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13392 | ADD_FAILURE(); |
| 13393 | return ERR_UNEXPECTED; |
| 13394 | } |
| 13395 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13396 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13397 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13398 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13399 | ADD_FAILURE(); |
| 13400 | return false; |
| 13401 | } |
| 13402 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13403 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13404 | ADD_FAILURE(); |
| 13405 | return false; |
| 13406 | } |
| 13407 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13408 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13409 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13410 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13411 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 13412 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13413 | ADD_FAILURE(); |
| 13414 | return 0; |
| 13415 | } |
| 13416 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 13417 | int64_t GetTotalSentBytes() const override { |
| 13418 | ADD_FAILURE(); |
| 13419 | return 0; |
| 13420 | } |
| 13421 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13422 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13423 | ADD_FAILURE(); |
| 13424 | return false; |
| 13425 | } |
| 13426 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13427 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13428 | |
| 13429 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13430 | ADD_FAILURE(); |
| 13431 | } |
| 13432 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13433 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 13434 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13435 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13436 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13437 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13438 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13439 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13440 | |
| 13441 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13442 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13443 | private: |
| 13444 | RequestPriority priority_; |
| 13445 | |
| 13446 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13447 | }; |
| 13448 | |
| 13449 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13450 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13451 | class FakeStreamRequest : public HttpStreamRequest, |
| 13452 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13453 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13454 | FakeStreamRequest(RequestPriority priority, |
| 13455 | HttpStreamRequest::Delegate* delegate) |
| 13456 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13457 | delegate_(delegate), |
| 13458 | websocket_stream_create_helper_(NULL) {} |
| 13459 | |
| 13460 | FakeStreamRequest(RequestPriority priority, |
| 13461 | HttpStreamRequest::Delegate* delegate, |
| 13462 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13463 | : priority_(priority), |
| 13464 | delegate_(delegate), |
| 13465 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13466 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13467 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13468 | |
| 13469 | RequestPriority priority() const { return priority_; } |
| 13470 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13471 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13472 | websocket_stream_create_helper() const { |
| 13473 | return websocket_stream_create_helper_; |
| 13474 | } |
| 13475 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13476 | // Create a new FakeStream and pass it to the request's |
| 13477 | // delegate. Returns a weak pointer to the FakeStream. |
| 13478 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13479 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13480 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13481 | // immediately delete |fake_stream|. |
| 13482 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13483 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13484 | return weak_stream; |
| 13485 | } |
| 13486 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13487 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13488 | ADD_FAILURE(); |
| 13489 | return ERR_UNEXPECTED; |
| 13490 | } |
| 13491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13492 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13493 | ADD_FAILURE(); |
| 13494 | return LoadState(); |
| 13495 | } |
| 13496 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13497 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13498 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13499 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13500 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13501 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13502 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13503 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13504 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13505 | const ConnectionAttempts& connection_attempts() const override { |
| 13506 | static ConnectionAttempts no_attempts; |
| 13507 | return no_attempts; |
| 13508 | } |
| 13509 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13510 | private: |
| 13511 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13512 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13513 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13514 | |
| 13515 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13516 | }; |
| 13517 | |
| 13518 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13519 | class FakeStreamFactory : public HttpStreamFactory { |
| 13520 | public: |
| 13521 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13522 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13523 | |
| 13524 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13525 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13526 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13527 | return last_stream_request_; |
| 13528 | } |
| 13529 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13530 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13531 | RequestPriority priority, |
| 13532 | const SSLConfig& server_ssl_config, |
| 13533 | const SSLConfig& proxy_ssl_config, |
| 13534 | HttpStreamRequest::Delegate* delegate, |
| 13535 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13536 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13537 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13538 | return fake_request; |
| 13539 | } |
| 13540 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13541 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13542 | const HttpRequestInfo& info, |
| 13543 | RequestPriority priority, |
| 13544 | const SSLConfig& server_ssl_config, |
| 13545 | const SSLConfig& proxy_ssl_config, |
| 13546 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13547 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13548 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13549 | FakeStreamRequest* fake_request = |
| 13550 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13551 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13552 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13553 | } |
| 13554 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13555 | void PreconnectStreams(int num_streams, |
| 13556 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13557 | const SSLConfig& server_ssl_config, |
| 13558 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13559 | ADD_FAILURE(); |
| 13560 | } |
| 13561 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13562 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13563 | ADD_FAILURE(); |
| 13564 | return NULL; |
| 13565 | } |
| 13566 | |
| 13567 | private: |
| 13568 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13569 | |
| 13570 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13571 | }; |
| 13572 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13573 | // TODO(ricea): Maybe unify this with the one in |
| 13574 | // url_request_http_job_unittest.cc ? |
| 13575 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13576 | public: |
| 13577 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13578 | bool using_proxy) |
| 13579 | : state_(connection.release(), using_proxy) {} |
| 13580 | |
| 13581 | // Fake implementation of HttpStreamBase methods. |
| 13582 | // This ends up being quite "real" because this object has to really send data |
| 13583 | // on the mock socket. It might be easier to use the real implementation, but |
| 13584 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13585 | // difficult. |
| 13586 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13587 | RequestPriority priority, |
| 13588 | const BoundNetLog& net_log, |
| 13589 | const CompletionCallback& callback) override { |
| 13590 | state_.Initialize(request_info, priority, net_log, callback); |
| 13591 | return OK; |
| 13592 | } |
| 13593 | |
| 13594 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13595 | HttpResponseInfo* response, |
| 13596 | const CompletionCallback& callback) override { |
| 13597 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13598 | response, callback); |
| 13599 | } |
| 13600 | |
| 13601 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13602 | return parser()->ReadResponseHeaders(callback); |
| 13603 | } |
| 13604 | |
| 13605 | int ReadResponseBody(IOBuffer* buf, |
| 13606 | int buf_len, |
| 13607 | const CompletionCallback& callback) override { |
| 13608 | NOTREACHED(); |
| 13609 | return ERR_IO_PENDING; |
| 13610 | } |
| 13611 | |
| 13612 | void Close(bool not_reusable) override { |
| 13613 | if (parser()) |
| 13614 | parser()->Close(true); |
| 13615 | } |
| 13616 | |
| 13617 | bool IsResponseBodyComplete() const override { |
| 13618 | NOTREACHED(); |
| 13619 | return false; |
| 13620 | } |
| 13621 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13622 | bool IsConnectionReused() const override { |
| 13623 | NOTREACHED(); |
| 13624 | return false; |
| 13625 | } |
| 13626 | void SetConnectionReused() override { NOTREACHED(); } |
| 13627 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13628 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13629 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 13630 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13631 | NOTREACHED(); |
| 13632 | return 0; |
| 13633 | } |
| 13634 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 13635 | int64_t GetTotalSentBytes() const override { |
| 13636 | NOTREACHED(); |
| 13637 | return 0; |
| 13638 | } |
| 13639 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13640 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13641 | NOTREACHED(); |
| 13642 | return false; |
| 13643 | } |
| 13644 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13645 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13646 | |
| 13647 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13648 | NOTREACHED(); |
| 13649 | } |
| 13650 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13651 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 13652 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13653 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13654 | |
| 13655 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13656 | |
| 13657 | UploadProgress GetUploadProgress() const override { |
| 13658 | NOTREACHED(); |
| 13659 | return UploadProgress(); |
| 13660 | } |
| 13661 | |
| 13662 | HttpStream* RenewStreamForAuth() override { |
| 13663 | NOTREACHED(); |
| 13664 | return nullptr; |
| 13665 | } |
| 13666 | |
| 13667 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13668 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13669 | NOTREACHED(); |
| 13670 | return scoped_ptr<WebSocketStream>(); |
| 13671 | } |
| 13672 | |
| 13673 | private: |
| 13674 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13675 | HttpBasicState state_; |
| 13676 | |
| 13677 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13678 | }; |
| 13679 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13680 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13681 | // worth doing. |
| 13682 | class FakeWebSocketStreamCreateHelper : |
| 13683 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13684 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13685 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13686 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13687 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13688 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13689 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13690 | } |
| 13691 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13692 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13693 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13694 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13695 | NOTREACHED(); |
| 13696 | return NULL; |
| 13697 | }; |
| 13698 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13699 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13700 | |
| 13701 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13702 | NOTREACHED(); |
| 13703 | return scoped_ptr<WebSocketStream>(); |
| 13704 | } |
| 13705 | }; |
| 13706 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13707 | } // namespace |
| 13708 | |
| 13709 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13710 | // stream request on start. |
| 13711 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13712 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13713 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13714 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13715 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13716 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13717 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13718 | |
| 13719 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13720 | |
| 13721 | HttpRequestInfo request; |
| 13722 | TestCompletionCallback callback; |
| 13723 | EXPECT_EQ(ERR_IO_PENDING, |
| 13724 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13725 | |
| 13726 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13727 | fake_factory->last_stream_request(); |
| 13728 | ASSERT_TRUE(fake_request != NULL); |
| 13729 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13730 | } |
| 13731 | |
| 13732 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13733 | // updates to its stream request. |
| 13734 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13735 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13736 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13737 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13738 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13739 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13740 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13741 | |
| 13742 | HttpRequestInfo request; |
| 13743 | TestCompletionCallback callback; |
| 13744 | EXPECT_EQ(ERR_IO_PENDING, |
| 13745 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13746 | |
| 13747 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13748 | fake_factory->last_stream_request(); |
| 13749 | ASSERT_TRUE(fake_request != NULL); |
| 13750 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13751 | |
| 13752 | trans.SetPriority(LOWEST); |
| 13753 | ASSERT_TRUE(fake_request != NULL); |
| 13754 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13755 | } |
| 13756 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13757 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13758 | // updates to its stream. |
| 13759 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13760 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13761 | HttpNetworkSessionPeer peer(session); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13762 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13763 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13764 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13765 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13766 | |
| 13767 | HttpRequestInfo request; |
| 13768 | TestCompletionCallback callback; |
| 13769 | EXPECT_EQ(ERR_IO_PENDING, |
| 13770 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13771 | |
| 13772 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13773 | fake_factory->last_stream_request(); |
| 13774 | ASSERT_TRUE(fake_request != NULL); |
| 13775 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13776 | ASSERT_TRUE(fake_stream != NULL); |
| 13777 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13778 | |
| 13779 | trans.SetPriority(LOWEST); |
| 13780 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13781 | } |
| 13782 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13783 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13784 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13785 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13786 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13787 | std::string test_cases[] = {"ws://www.example.org/", |
| 13788 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13789 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13790 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13791 | HttpNetworkSessionPeer peer(session); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13792 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13793 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13794 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13795 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13796 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13797 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13798 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13799 | &websocket_stream_create_helper); |
| 13800 | |
| 13801 | HttpRequestInfo request; |
| 13802 | TestCompletionCallback callback; |
| 13803 | request.method = "GET"; |
| 13804 | request.url = GURL(test_cases[i]); |
| 13805 | |
| 13806 | EXPECT_EQ(ERR_IO_PENDING, |
| 13807 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13808 | |
| 13809 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13810 | fake_factory->last_stream_request(); |
| 13811 | ASSERT_TRUE(fake_request != NULL); |
| 13812 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13813 | fake_request->websocket_stream_create_helper()); |
| 13814 | } |
| 13815 | } |
| 13816 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13817 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13818 | // if the transport socket pool is stalled on the global socket limit. |
| 13819 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13820 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13821 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13822 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13823 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13824 | |
| 13825 | // Set up SSL request. |
| 13826 | |
| 13827 | HttpRequestInfo ssl_request; |
| 13828 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13829 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13830 | |
| 13831 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13832 | MockWrite( |
| 13833 | "GET / HTTP/1.1\r\n" |
| 13834 | "Host: www.example.org\r\n" |
| 13835 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13836 | }; |
| 13837 | MockRead ssl_reads[] = { |
| 13838 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13839 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13840 | MockRead("hello world"), |
| 13841 | MockRead(SYNCHRONOUS, OK), |
| 13842 | }; |
| 13843 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13844 | ssl_writes, arraysize(ssl_writes)); |
| 13845 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13846 | |
| 13847 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13849 | |
| 13850 | // Set up HTTP request. |
| 13851 | |
| 13852 | HttpRequestInfo http_request; |
| 13853 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13854 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13855 | |
| 13856 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13857 | MockWrite( |
| 13858 | "GET / HTTP/1.1\r\n" |
| 13859 | "Host: www.example.org\r\n" |
| 13860 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13861 | }; |
| 13862 | MockRead http_reads[] = { |
| 13863 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13864 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13865 | MockRead("falafel"), |
| 13866 | MockRead(SYNCHRONOUS, OK), |
| 13867 | }; |
| 13868 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13869 | http_writes, arraysize(http_writes)); |
| 13870 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13871 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13872 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13873 | |
| 13874 | // Start the SSL request. |
| 13875 | TestCompletionCallback ssl_callback; |
| 13876 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13878 | ASSERT_EQ(ERR_IO_PENDING, |
| 13879 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13880 | BoundNetLog())); |
| 13881 | |
| 13882 | // Start the HTTP request. Pool should stall. |
| 13883 | TestCompletionCallback http_callback; |
| 13884 | scoped_ptr<HttpTransaction> http_trans( |
| 13885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13886 | ASSERT_EQ(ERR_IO_PENDING, |
| 13887 | http_trans->Start(&http_request, http_callback.callback(), |
| 13888 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13889 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13890 | |
| 13891 | // Wait for response from SSL request. |
| 13892 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13893 | std::string response_data; |
| 13894 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13895 | EXPECT_EQ("hello world", response_data); |
| 13896 | |
| 13897 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13898 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13899 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13900 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13901 | |
| 13902 | // The HTTP request can now complete. |
| 13903 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13904 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13905 | EXPECT_EQ("falafel", response_data); |
| 13906 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13907 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13908 | } |
| 13909 | |
| 13910 | // Tests that when a SSL connection is established but there's no corresponding |
| 13911 | // request that needs it, the new socket is closed if the transport socket pool |
| 13912 | // is stalled on the global socket limit. |
| 13913 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13914 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13915 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13916 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13917 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13918 | |
| 13919 | // Set up an ssl request. |
| 13920 | |
| 13921 | HttpRequestInfo ssl_request; |
| 13922 | ssl_request.method = "GET"; |
| 13923 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13924 | |
| 13925 | // No data will be sent on the SSL socket. |
| 13926 | StaticSocketDataProvider ssl_data; |
| 13927 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13928 | |
| 13929 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13931 | |
| 13932 | // Set up HTTP request. |
| 13933 | |
| 13934 | HttpRequestInfo http_request; |
| 13935 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13936 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13937 | |
| 13938 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13939 | MockWrite( |
| 13940 | "GET / HTTP/1.1\r\n" |
| 13941 | "Host: www.example.org\r\n" |
| 13942 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13943 | }; |
| 13944 | MockRead http_reads[] = { |
| 13945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13946 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13947 | MockRead("falafel"), |
| 13948 | MockRead(SYNCHRONOUS, OK), |
| 13949 | }; |
| 13950 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13951 | http_writes, arraysize(http_writes)); |
| 13952 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13953 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13954 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13955 | |
| 13956 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13957 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13958 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13959 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13960 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 13961 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 13962 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13963 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13964 | |
| 13965 | // Start the HTTP request. Pool should stall. |
| 13966 | TestCompletionCallback http_callback; |
| 13967 | scoped_ptr<HttpTransaction> http_trans( |
| 13968 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13969 | ASSERT_EQ(ERR_IO_PENDING, |
| 13970 | http_trans->Start(&http_request, http_callback.callback(), |
| 13971 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13972 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13973 | |
| 13974 | // The SSL connection will automatically be closed once the connection is |
| 13975 | // established, to let the HTTP request start. |
| 13976 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13977 | std::string response_data; |
| 13978 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13979 | EXPECT_EQ("falafel", response_data); |
| 13980 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13981 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13982 | } |
| 13983 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13984 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13985 | ScopedVector<UploadElementReader> element_readers; |
| 13986 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13987 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13988 | |
| 13989 | HttpRequestInfo request; |
| 13990 | request.method = "POST"; |
| 13991 | request.url = GURL("http://www.foo.com/"); |
| 13992 | request.upload_data_stream = &upload_data_stream; |
| 13993 | request.load_flags = 0; |
| 13994 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13995 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13996 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13998 | // Send headers successfully, but get an error while sending the body. |
| 13999 | MockWrite data_writes[] = { |
| 14000 | MockWrite("POST / HTTP/1.1\r\n" |
| 14001 | "Host: www.foo.com\r\n" |
| 14002 | "Connection: keep-alive\r\n" |
| 14003 | "Content-Length: 3\r\n\r\n"), |
| 14004 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14005 | }; |
| 14006 | |
| 14007 | MockRead data_reads[] = { |
| 14008 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14009 | MockRead("hello world"), |
| 14010 | MockRead(SYNCHRONOUS, OK), |
| 14011 | }; |
| 14012 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14013 | arraysize(data_writes)); |
| 14014 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14015 | |
| 14016 | TestCompletionCallback callback; |
| 14017 | |
| 14018 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14019 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14020 | |
| 14021 | rv = callback.WaitForResult(); |
| 14022 | EXPECT_EQ(OK, rv); |
| 14023 | |
| 14024 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14025 | ASSERT_TRUE(response != NULL); |
| 14026 | |
| 14027 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14028 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14029 | |
| 14030 | std::string response_data; |
| 14031 | rv = ReadTransaction(trans.get(), &response_data); |
| 14032 | EXPECT_EQ(OK, rv); |
| 14033 | EXPECT_EQ("hello world", response_data); |
| 14034 | } |
| 14035 | |
| 14036 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14037 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14038 | TEST_P(HttpNetworkTransactionTest, |
| 14039 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14040 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14041 | MockWrite data_writes[] = { |
| 14042 | MockWrite("GET / HTTP/1.1\r\n" |
| 14043 | "Host: www.foo.com\r\n" |
| 14044 | "Connection: keep-alive\r\n\r\n"), |
| 14045 | MockWrite("POST / HTTP/1.1\r\n" |
| 14046 | "Host: www.foo.com\r\n" |
| 14047 | "Connection: keep-alive\r\n" |
| 14048 | "Content-Length: 3\r\n\r\n"), |
| 14049 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14050 | }; |
| 14051 | |
| 14052 | MockRead data_reads[] = { |
| 14053 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14054 | "Content-Length: 14\r\n\r\n"), |
| 14055 | MockRead("first response"), |
| 14056 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14057 | "Content-Length: 15\r\n\r\n"), |
| 14058 | MockRead("second response"), |
| 14059 | MockRead(SYNCHRONOUS, OK), |
| 14060 | }; |
| 14061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14062 | arraysize(data_writes)); |
| 14063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14064 | |
| 14065 | TestCompletionCallback callback; |
| 14066 | HttpRequestInfo request1; |
| 14067 | request1.method = "GET"; |
| 14068 | request1.url = GURL("http://www.foo.com/"); |
| 14069 | request1.load_flags = 0; |
| 14070 | |
| 14071 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14073 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14074 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14075 | |
| 14076 | rv = callback.WaitForResult(); |
| 14077 | EXPECT_EQ(OK, rv); |
| 14078 | |
| 14079 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14080 | ASSERT_TRUE(response1 != NULL); |
| 14081 | |
| 14082 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14083 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14084 | |
| 14085 | std::string response_data1; |
| 14086 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14087 | EXPECT_EQ(OK, rv); |
| 14088 | EXPECT_EQ("first response", response_data1); |
| 14089 | // Delete the transaction to release the socket back into the socket pool. |
| 14090 | trans1.reset(); |
| 14091 | |
| 14092 | ScopedVector<UploadElementReader> element_readers; |
| 14093 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14094 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14095 | |
| 14096 | HttpRequestInfo request2; |
| 14097 | request2.method = "POST"; |
| 14098 | request2.url = GURL("http://www.foo.com/"); |
| 14099 | request2.upload_data_stream = &upload_data_stream; |
| 14100 | request2.load_flags = 0; |
| 14101 | |
| 14102 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14103 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14104 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14106 | |
| 14107 | rv = callback.WaitForResult(); |
| 14108 | EXPECT_EQ(OK, rv); |
| 14109 | |
| 14110 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14111 | ASSERT_TRUE(response2 != NULL); |
| 14112 | |
| 14113 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14114 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14115 | |
| 14116 | std::string response_data2; |
| 14117 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14118 | EXPECT_EQ(OK, rv); |
| 14119 | EXPECT_EQ("second response", response_data2); |
| 14120 | } |
| 14121 | |
| 14122 | TEST_P(HttpNetworkTransactionTest, |
| 14123 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14124 | ScopedVector<UploadElementReader> element_readers; |
| 14125 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14126 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14127 | |
| 14128 | HttpRequestInfo request; |
| 14129 | request.method = "POST"; |
| 14130 | request.url = GURL("http://www.foo.com/"); |
| 14131 | request.upload_data_stream = &upload_data_stream; |
| 14132 | request.load_flags = 0; |
| 14133 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14134 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14135 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14136 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14137 | // Send headers successfully, but get an error while sending the body. |
| 14138 | MockWrite data_writes[] = { |
| 14139 | MockWrite("POST / HTTP/1.1\r\n" |
| 14140 | "Host: www.foo.com\r\n" |
| 14141 | "Connection: keep-alive\r\n" |
| 14142 | "Content-Length: 3\r\n\r\n" |
| 14143 | "fo"), |
| 14144 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14145 | }; |
| 14146 | |
| 14147 | MockRead data_reads[] = { |
| 14148 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14149 | MockRead("hello world"), |
| 14150 | MockRead(SYNCHRONOUS, OK), |
| 14151 | }; |
| 14152 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14153 | arraysize(data_writes)); |
| 14154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14155 | |
| 14156 | TestCompletionCallback callback; |
| 14157 | |
| 14158 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14160 | |
| 14161 | rv = callback.WaitForResult(); |
| 14162 | EXPECT_EQ(OK, rv); |
| 14163 | |
| 14164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14165 | ASSERT_TRUE(response != NULL); |
| 14166 | |
| 14167 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14168 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14169 | |
| 14170 | std::string response_data; |
| 14171 | rv = ReadTransaction(trans.get(), &response_data); |
| 14172 | EXPECT_EQ(OK, rv); |
| 14173 | EXPECT_EQ("hello world", response_data); |
| 14174 | } |
| 14175 | |
| 14176 | // This tests the more common case than the previous test, where headers and |
| 14177 | // body are not merged into a single request. |
| 14178 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14179 | ScopedVector<UploadElementReader> element_readers; |
| 14180 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14181 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14182 | |
| 14183 | HttpRequestInfo request; |
| 14184 | request.method = "POST"; |
| 14185 | request.url = GURL("http://www.foo.com/"); |
| 14186 | request.upload_data_stream = &upload_data_stream; |
| 14187 | request.load_flags = 0; |
| 14188 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14190 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14192 | // Send headers successfully, but get an error while sending the body. |
| 14193 | MockWrite data_writes[] = { |
| 14194 | MockWrite("POST / HTTP/1.1\r\n" |
| 14195 | "Host: www.foo.com\r\n" |
| 14196 | "Connection: keep-alive\r\n" |
| 14197 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14198 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14199 | }; |
| 14200 | |
| 14201 | MockRead data_reads[] = { |
| 14202 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14203 | MockRead("hello world"), |
| 14204 | MockRead(SYNCHRONOUS, OK), |
| 14205 | }; |
| 14206 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14207 | arraysize(data_writes)); |
| 14208 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14209 | |
| 14210 | TestCompletionCallback callback; |
| 14211 | |
| 14212 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14214 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14215 | // they can't be merged with the body in a single send. Not currently |
| 14216 | // necessary since a chunked body is never merged with headers, but this makes |
| 14217 | // the test more future proof. |
| 14218 | base::RunLoop().RunUntilIdle(); |
| 14219 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14220 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 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, PostReadsErrorResponseAfterResetAnd100) { |
| 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 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14248 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 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 | |
| 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 100 Continue\r\n\r\n"), |
| 14262 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14263 | MockRead("hello world"), |
| 14264 | MockRead(SYNCHRONOUS, OK), |
| 14265 | }; |
| 14266 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14267 | arraysize(data_writes)); |
| 14268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14269 | |
| 14270 | TestCompletionCallback callback; |
| 14271 | |
| 14272 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14274 | |
| 14275 | rv = callback.WaitForResult(); |
| 14276 | EXPECT_EQ(OK, rv); |
| 14277 | |
| 14278 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14279 | ASSERT_TRUE(response != NULL); |
| 14280 | |
| 14281 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14282 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14283 | |
| 14284 | std::string response_data; |
| 14285 | rv = ReadTransaction(trans.get(), &response_data); |
| 14286 | EXPECT_EQ(OK, rv); |
| 14287 | EXPECT_EQ("hello world", response_data); |
| 14288 | } |
| 14289 | |
| 14290 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14291 | ScopedVector<UploadElementReader> element_readers; |
| 14292 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14293 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14294 | |
| 14295 | HttpRequestInfo request; |
| 14296 | request.method = "POST"; |
| 14297 | request.url = GURL("http://www.foo.com/"); |
| 14298 | request.upload_data_stream = &upload_data_stream; |
| 14299 | request.load_flags = 0; |
| 14300 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14301 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14302 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14304 | // Send headers successfully, but get an error while sending the body. |
| 14305 | MockWrite data_writes[] = { |
| 14306 | MockWrite("POST / HTTP/1.1\r\n" |
| 14307 | "Host: www.foo.com\r\n" |
| 14308 | "Connection: keep-alive\r\n" |
| 14309 | "Content-Length: 3\r\n\r\n"), |
| 14310 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14311 | }; |
| 14312 | |
| 14313 | MockRead data_reads[] = { |
| 14314 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14315 | MockRead("hello world"), |
| 14316 | MockRead(SYNCHRONOUS, OK), |
| 14317 | }; |
| 14318 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14319 | arraysize(data_writes)); |
| 14320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14321 | |
| 14322 | TestCompletionCallback callback; |
| 14323 | |
| 14324 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14325 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14326 | |
| 14327 | rv = callback.WaitForResult(); |
| 14328 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14329 | } |
| 14330 | |
| 14331 | TEST_P(HttpNetworkTransactionTest, |
| 14332 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14333 | ScopedVector<UploadElementReader> element_readers; |
| 14334 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14335 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14336 | |
| 14337 | HttpRequestInfo request; |
| 14338 | request.method = "POST"; |
| 14339 | request.url = GURL("http://www.foo.com/"); |
| 14340 | request.upload_data_stream = &upload_data_stream; |
| 14341 | request.load_flags = 0; |
| 14342 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14344 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14346 | // Send headers successfully, but get an error while sending the body. |
| 14347 | MockWrite data_writes[] = { |
| 14348 | MockWrite("POST / HTTP/1.1\r\n" |
| 14349 | "Host: www.foo.com\r\n" |
| 14350 | "Connection: keep-alive\r\n" |
| 14351 | "Content-Length: 3\r\n\r\n"), |
| 14352 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14353 | }; |
| 14354 | |
| 14355 | MockRead data_reads[] = { |
| 14356 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14357 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14358 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14359 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14360 | MockRead(SYNCHRONOUS, OK), |
| 14361 | }; |
| 14362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14363 | arraysize(data_writes)); |
| 14364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14365 | |
| 14366 | TestCompletionCallback callback; |
| 14367 | |
| 14368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14370 | |
| 14371 | rv = callback.WaitForResult(); |
| 14372 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14373 | } |
| 14374 | |
| 14375 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14376 | ScopedVector<UploadElementReader> element_readers; |
| 14377 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14378 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14379 | |
| 14380 | HttpRequestInfo request; |
| 14381 | request.method = "POST"; |
| 14382 | request.url = GURL("http://www.foo.com/"); |
| 14383 | request.upload_data_stream = &upload_data_stream; |
| 14384 | request.load_flags = 0; |
| 14385 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14386 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14387 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14388 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14389 | // Send headers successfully, but get an error while sending the body. |
| 14390 | MockWrite data_writes[] = { |
| 14391 | MockWrite("POST / HTTP/1.1\r\n" |
| 14392 | "Host: www.foo.com\r\n" |
| 14393 | "Connection: keep-alive\r\n" |
| 14394 | "Content-Length: 3\r\n\r\n"), |
| 14395 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14396 | }; |
| 14397 | |
| 14398 | MockRead data_reads[] = { |
| 14399 | MockRead("HTTP 0.9 rocks!"), |
| 14400 | MockRead(SYNCHRONOUS, OK), |
| 14401 | }; |
| 14402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14403 | arraysize(data_writes)); |
| 14404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14405 | |
| 14406 | TestCompletionCallback callback; |
| 14407 | |
| 14408 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14410 | |
| 14411 | rv = callback.WaitForResult(); |
| 14412 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14413 | } |
| 14414 | |
| 14415 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14416 | ScopedVector<UploadElementReader> element_readers; |
| 14417 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14418 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14419 | |
| 14420 | HttpRequestInfo request; |
| 14421 | request.method = "POST"; |
| 14422 | request.url = GURL("http://www.foo.com/"); |
| 14423 | request.upload_data_stream = &upload_data_stream; |
| 14424 | request.load_flags = 0; |
| 14425 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14426 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14427 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14428 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14429 | // Send headers successfully, but get an error while sending the body. |
| 14430 | MockWrite data_writes[] = { |
| 14431 | MockWrite("POST / HTTP/1.1\r\n" |
| 14432 | "Host: www.foo.com\r\n" |
| 14433 | "Connection: keep-alive\r\n" |
| 14434 | "Content-Length: 3\r\n\r\n"), |
| 14435 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14436 | }; |
| 14437 | |
| 14438 | MockRead data_reads[] = { |
| 14439 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14440 | MockRead(SYNCHRONOUS, OK), |
| 14441 | }; |
| 14442 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14443 | arraysize(data_writes)); |
| 14444 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14445 | |
| 14446 | TestCompletionCallback callback; |
| 14447 | |
| 14448 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14449 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14450 | |
| 14451 | rv = callback.WaitForResult(); |
| 14452 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14453 | } |
| 14454 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14455 | // Verify that proxy headers are not sent to the destination server when |
| 14456 | // establishing a tunnel for a secure WebSocket connection. |
| 14457 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14458 | HttpRequestInfo request; |
| 14459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14460 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14461 | AddWebSocketHeaders(&request.extra_headers); |
| 14462 | |
| 14463 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14464 | session_deps_.proxy_service = |
| 14465 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14466 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14467 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14468 | |
| 14469 | // Since a proxy is configured, try to establish a tunnel. |
| 14470 | MockWrite data_writes[] = { |
| 14471 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14472 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14473 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14474 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14475 | |
| 14476 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14477 | // be issuing -- the final header line contains the credentials. |
| 14478 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14479 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14480 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14481 | "Proxy-Connection: keep-alive\r\n" |
| 14482 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14483 | |
| 14484 | MockWrite( |
| 14485 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14486 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14487 | "Connection: Upgrade\r\n" |
| 14488 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14489 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14490 | "Sec-WebSocket-Version: 13\r\n" |
| 14491 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14492 | }; |
| 14493 | |
| 14494 | // The proxy responds to the connect with a 407, using a persistent |
| 14495 | // connection. |
| 14496 | MockRead data_reads[] = { |
| 14497 | // No credentials. |
| 14498 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14499 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame^] | 14500 | MockRead("Proxy-Connection: close\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14501 | |
| 14502 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14503 | |
| 14504 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14505 | MockRead("Upgrade: websocket\r\n"), |
| 14506 | MockRead("Connection: Upgrade\r\n"), |
| 14507 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14508 | }; |
| 14509 | |
| 14510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14511 | arraysize(data_writes)); |
| 14512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14513 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14515 | |
| 14516 | scoped_ptr<HttpTransaction> trans( |
| 14517 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14518 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14519 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14520 | &websocket_stream_create_helper); |
| 14521 | |
| 14522 | { |
| 14523 | TestCompletionCallback callback; |
| 14524 | |
| 14525 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14526 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14527 | |
| 14528 | rv = callback.WaitForResult(); |
| 14529 | EXPECT_EQ(OK, rv); |
| 14530 | } |
| 14531 | |
| 14532 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14533 | ASSERT_TRUE(response); |
| 14534 | ASSERT_TRUE(response->headers.get()); |
| 14535 | EXPECT_EQ(407, response->headers->response_code()); |
| 14536 | |
| 14537 | { |
| 14538 | TestCompletionCallback callback; |
| 14539 | |
| 14540 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14541 | callback.callback()); |
| 14542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14543 | |
| 14544 | rv = callback.WaitForResult(); |
| 14545 | EXPECT_EQ(OK, rv); |
| 14546 | } |
| 14547 | |
| 14548 | response = trans->GetResponseInfo(); |
| 14549 | ASSERT_TRUE(response); |
| 14550 | ASSERT_TRUE(response->headers.get()); |
| 14551 | |
| 14552 | EXPECT_EQ(101, response->headers->response_code()); |
| 14553 | |
| 14554 | trans.reset(); |
| 14555 | session->CloseAllConnections(); |
| 14556 | } |
| 14557 | |
| 14558 | // Verify that proxy headers are not sent to the destination server when |
| 14559 | // establishing a tunnel for an insecure WebSocket connection. |
| 14560 | // This requires the authentication info to be injected into the auth cache |
| 14561 | // due to crbug.com/395064 |
| 14562 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14563 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14564 | HttpRequestInfo request; |
| 14565 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14566 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14567 | AddWebSocketHeaders(&request.extra_headers); |
| 14568 | |
| 14569 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14570 | session_deps_.proxy_service = |
| 14571 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14572 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14573 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14574 | |
| 14575 | MockWrite data_writes[] = { |
| 14576 | // Try to establish a tunnel for the WebSocket connection, with |
| 14577 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14578 | // they cannot and will not use the same TCP/IP connection as the |
| 14579 | // preflight HTTP request. |
| 14580 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14581 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14582 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14583 | "Proxy-Connection: keep-alive\r\n" |
| 14584 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14585 | |
| 14586 | MockWrite( |
| 14587 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14588 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14589 | "Connection: Upgrade\r\n" |
| 14590 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14591 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14592 | "Sec-WebSocket-Version: 13\r\n" |
| 14593 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14594 | }; |
| 14595 | |
| 14596 | MockRead data_reads[] = { |
| 14597 | // HTTP CONNECT with credentials. |
| 14598 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14599 | |
| 14600 | // WebSocket connection established inside tunnel. |
| 14601 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14602 | MockRead("Upgrade: websocket\r\n"), |
| 14603 | MockRead("Connection: Upgrade\r\n"), |
| 14604 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14605 | }; |
| 14606 | |
| 14607 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14608 | arraysize(data_writes)); |
| 14609 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14610 | |
| 14611 | session->http_auth_cache()->Add( |
| 14612 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14613 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14614 | |
| 14615 | scoped_ptr<HttpTransaction> trans( |
| 14616 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14617 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14618 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14619 | &websocket_stream_create_helper); |
| 14620 | |
| 14621 | TestCompletionCallback callback; |
| 14622 | |
| 14623 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14624 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14625 | |
| 14626 | rv = callback.WaitForResult(); |
| 14627 | EXPECT_EQ(OK, rv); |
| 14628 | |
| 14629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14630 | ASSERT_TRUE(response); |
| 14631 | ASSERT_TRUE(response->headers.get()); |
| 14632 | |
| 14633 | EXPECT_EQ(101, response->headers->response_code()); |
| 14634 | |
| 14635 | trans.reset(); |
| 14636 | session->CloseAllConnections(); |
| 14637 | } |
| 14638 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14639 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
| 14640 | ScopedVector<UploadElementReader> element_readers; |
| 14641 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14642 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14643 | |
| 14644 | HttpRequestInfo request; |
| 14645 | request.method = "POST"; |
| 14646 | request.url = GURL("http://www.foo.com/"); |
| 14647 | request.upload_data_stream = &upload_data_stream; |
| 14648 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14649 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14650 | scoped_ptr<HttpTransaction> trans( |
| 14651 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14652 | MockWrite data_writes[] = { |
| 14653 | MockWrite("POST / HTTP/1.1\r\n" |
| 14654 | "Host: www.foo.com\r\n" |
| 14655 | "Connection: keep-alive\r\n" |
| 14656 | "Content-Length: 3\r\n\r\n"), |
| 14657 | MockWrite("foo"), |
| 14658 | }; |
| 14659 | |
| 14660 | MockRead data_reads[] = { |
| 14661 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14662 | MockRead(SYNCHRONOUS, OK), |
| 14663 | }; |
| 14664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14665 | arraysize(data_writes)); |
| 14666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14667 | |
| 14668 | TestCompletionCallback callback; |
| 14669 | |
| 14670 | EXPECT_EQ(ERR_IO_PENDING, |
| 14671 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14672 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14673 | |
| 14674 | std::string response_data; |
| 14675 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14676 | |
| 14677 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14678 | trans->GetTotalSentBytes()); |
| 14679 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14680 | trans->GetTotalReceivedBytes()); |
| 14681 | } |
| 14682 | |
| 14683 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
| 14684 | ScopedVector<UploadElementReader> element_readers; |
| 14685 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14686 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14687 | |
| 14688 | HttpRequestInfo request; |
| 14689 | request.method = "POST"; |
| 14690 | request.url = GURL("http://www.foo.com/"); |
| 14691 | request.upload_data_stream = &upload_data_stream; |
| 14692 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14693 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14694 | scoped_ptr<HttpTransaction> trans( |
| 14695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14696 | MockWrite data_writes[] = { |
| 14697 | MockWrite("POST / HTTP/1.1\r\n" |
| 14698 | "Host: www.foo.com\r\n" |
| 14699 | "Connection: keep-alive\r\n" |
| 14700 | "Content-Length: 3\r\n\r\n"), |
| 14701 | MockWrite("foo"), |
| 14702 | }; |
| 14703 | |
| 14704 | MockRead data_reads[] = { |
| 14705 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 14706 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14707 | MockRead(SYNCHRONOUS, OK), |
| 14708 | }; |
| 14709 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14710 | arraysize(data_writes)); |
| 14711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14712 | |
| 14713 | TestCompletionCallback callback; |
| 14714 | |
| 14715 | EXPECT_EQ(ERR_IO_PENDING, |
| 14716 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14717 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14718 | |
| 14719 | std::string response_data; |
| 14720 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14721 | |
| 14722 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14723 | trans->GetTotalSentBytes()); |
| 14724 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14725 | trans->GetTotalReceivedBytes()); |
| 14726 | } |
| 14727 | |
| 14728 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
| 14729 | ScopedVector<UploadElementReader> element_readers; |
| 14730 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14731 | ChunkedUploadDataStream upload_data_stream(0); |
| 14732 | |
| 14733 | HttpRequestInfo request; |
| 14734 | request.method = "POST"; |
| 14735 | request.url = GURL("http://www.foo.com/"); |
| 14736 | request.upload_data_stream = &upload_data_stream; |
| 14737 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14738 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 14739 | scoped_ptr<HttpTransaction> trans( |
| 14740 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14741 | // Send headers successfully, but get an error while sending the body. |
| 14742 | MockWrite data_writes[] = { |
| 14743 | MockWrite("POST / HTTP/1.1\r\n" |
| 14744 | "Host: www.foo.com\r\n" |
| 14745 | "Connection: keep-alive\r\n" |
| 14746 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14747 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 14748 | }; |
| 14749 | |
| 14750 | MockRead data_reads[] = { |
| 14751 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14752 | MockRead(SYNCHRONOUS, OK), |
| 14753 | }; |
| 14754 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14755 | arraysize(data_writes)); |
| 14756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14757 | |
| 14758 | TestCompletionCallback callback; |
| 14759 | |
| 14760 | EXPECT_EQ(ERR_IO_PENDING, |
| 14761 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14762 | |
| 14763 | base::RunLoop().RunUntilIdle(); |
| 14764 | upload_data_stream.AppendData("f", 1, false); |
| 14765 | |
| 14766 | base::RunLoop().RunUntilIdle(); |
| 14767 | upload_data_stream.AppendData("oo", 2, true); |
| 14768 | |
| 14769 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14770 | |
| 14771 | std::string response_data; |
| 14772 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14773 | |
| 14774 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14775 | trans->GetTotalSentBytes()); |
| 14776 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14777 | trans->GetTotalReceivedBytes()); |
| 14778 | } |
| 14779 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14780 | } // namespace net |