[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
| 9 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 11 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 20 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 21 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 23 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 24 | #include "base/test/test_file_util.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 25 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 26 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 27 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 28 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 29 | #include "net/base/load_timing_info.h" |
| 30 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 31 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 32 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 33 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 34 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 35 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 36 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 37 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 38 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 39 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 40 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 41 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 42 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 44 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 45 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 47 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 48 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 49 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 50 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 51 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 52 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 53 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 54 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 55 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 56 | #include "net/log/test_net_log_entry.h" |
| 57 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 58 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 59 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 60 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 61 | #include "net/proxy/proxy_resolver.h" |
| 62 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 63 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 64 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 65 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 66 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 67 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 68 | #include "net/socket/socket_test_util.h" |
| 69 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 70 | #include "net/spdy/spdy_framer.h" |
| 71 | #include "net/spdy/spdy_session.h" |
| 72 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 73 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 74 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 75 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 76 | #include "net/ssl/ssl_config_service_defaults.h" |
| 77 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 78 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 79 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 80 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 81 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 82 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 84 | using base::ASCIIToUTF16; |
| 85 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | //----------------------------------------------------------------------------- |
| 87 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 88 | namespace net { |
| 89 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 90 | namespace { |
| 91 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 92 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 93 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 94 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 95 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 96 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 97 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 98 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 99 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 100 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 101 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 102 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 103 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 104 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 105 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 106 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 107 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 108 | } |
| 109 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 110 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 111 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 112 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 113 | } |
| 114 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 115 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 116 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 117 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 120 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 121 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 122 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 123 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 124 | if (!params) |
| 125 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 126 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | if (!params->GetList("headers", &header_list)) |
| 128 | return false; |
| 129 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 130 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 131 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 132 | return true; |
| 133 | } |
| 134 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 135 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 136 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 137 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 139 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 140 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 142 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 143 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 144 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 145 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 146 | |
| 147 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 148 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 149 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 150 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 151 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 152 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 155 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 156 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 158 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 161 | |
| 162 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 163 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 164 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 165 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 166 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 167 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 168 | load_timing_info.send_start); |
| 169 | |
| 170 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 171 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 172 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 173 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 174 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 175 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 179 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 180 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 181 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 182 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 184 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | |
| 186 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 187 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 188 | load_timing_info.proxy_resolve_end); |
| 189 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 190 | load_timing_info.send_start); |
| 191 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | int connect_timing_flags) { |
| 203 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | |
| 206 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 207 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 208 | load_timing_info.proxy_resolve_end); |
| 209 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 210 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 211 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 212 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 214 | load_timing_info.send_start); |
| 215 | |
| 216 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 218 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 220 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 221 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 222 | } |
| 223 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 224 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 225 | headers->SetHeader("Connection", "Upgrade"); |
| 226 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 227 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 228 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 229 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 230 | } |
| 231 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 232 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 233 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 236 | } // namespace |
| 237 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 238 | class HttpNetworkTransactionTest |
| 239 | : public PlatformTest, |
| 240 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 241 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 242 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 243 | // Important to restore the per-pool limit first, since the pool limit must |
| 244 | // always be greater than group limit, and the tests reduce both limits. |
| 245 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 246 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 247 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 248 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 249 | } |
| 250 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 251 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 252 | HttpNetworkTransactionTest() |
| 253 | : spdy_util_(GetParam()), |
| 254 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 255 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 256 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 257 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 258 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 259 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 260 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 261 | struct SimpleGetHelperResult { |
| 262 | int rv; |
| 263 | std::string status_line; |
| 264 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 265 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 267 | ConnectionAttempts connection_attempts; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 268 | }; |
| 269 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 270 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 271 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 272 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 273 | } |
| 274 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 275 | void TearDown() 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] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 278 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 279 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 280 | PlatformTest::TearDown(); |
[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 | } |
| 284 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 285 | const char* GetAlternateProtocolFromParam() { |
| 286 | return |
| 287 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 288 | } |
| 289 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 290 | // This is the expected return from a current server advertising SPDY. |
| 291 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 292 | return std::string("Alternate-Protocol: 443:") + |
| 293 | GetAlternateProtocolFromParam() + "\r\n\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 296 | // Either |write_failure| specifies a write failure or |read_failure| |
| 297 | // specifies a read failure when using a reused socket. In either case, the |
| 298 | // failure should cause the network transaction to resend the request, and the |
| 299 | // other argument should be NULL. |
| 300 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 301 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 302 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 303 | // Either |write_failure| specifies a write failure or |read_failure| |
| 304 | // specifies a read failure when using a reused socket. In either case, the |
| 305 | // failure should cause the network transaction to resend the request, and the |
| 306 | // other argument should be NULL. |
| 307 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 308 | const MockRead* read_failure, |
| 309 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 310 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 311 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 312 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 313 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 314 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 315 | HttpRequestInfo request; |
| 316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 317 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 318 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 319 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 320 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 321 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 322 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 323 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 324 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 325 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 326 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 327 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 328 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 330 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 331 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 332 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 333 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 335 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 336 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 337 | |
| 338 | // Even in the failure cases that use this function, connections are always |
| 339 | // successfully established before the error. |
| 340 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 341 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 342 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 343 | if (out.rv != OK) |
| 344 | return out; |
| 345 | |
| 346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 347 | // Can't use ASSERT_* inside helper functions like this, so |
| 348 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 349 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 350 | out.rv = ERR_UNEXPECTED; |
| 351 | return out; |
| 352 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | out.status_line = response->headers->GetStatusLine(); |
| 354 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 355 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 356 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 357 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 359 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 360 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 361 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 362 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 363 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 364 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 365 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 366 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 367 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 368 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 369 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 370 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 371 | std::string line; |
| 372 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 373 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 374 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 375 | HttpRequestHeaders request_headers; |
| 376 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 377 | std::string value; |
| 378 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 379 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 380 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 381 | EXPECT_EQ("keep-alive", value); |
| 382 | |
| 383 | std::string response_headers; |
| 384 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 385 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 386 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 387 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 388 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 389 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 390 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 391 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 392 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 393 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 394 | size_t reads_count) { |
| 395 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 396 | StaticSocketDataProvider* data[] = { &reads }; |
| 397 | return SimpleGetHelperForData(data, 1); |
| 398 | } |
| 399 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 400 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 401 | int64 size = 0; |
| 402 | for (size_t i = 0; i < reads_count; ++i) |
| 403 | size += data_reads[i].data_len; |
| 404 | return size; |
| 405 | } |
| 406 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 407 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 408 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 409 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 410 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 411 | |
| 412 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 413 | |
| 414 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 415 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 416 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 417 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 418 | |
| 419 | // Original socket limits. Some tests set these. Safest to always restore |
| 420 | // them once each test has been run. |
| 421 | int old_max_group_sockets_; |
| 422 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 423 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 424 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 425 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 426 | HttpNetworkTransactionTest, |
| 427 | testing::Values(kProtoSPDY31, |
| 428 | kProtoSPDY4_14, |
| 429 | kProtoSPDY4)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 430 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 431 | namespace { |
| 432 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 433 | class BeforeNetworkStartHandler { |
| 434 | public: |
| 435 | explicit BeforeNetworkStartHandler(bool defer) |
| 436 | : defer_on_before_network_start_(defer), |
| 437 | observed_before_network_start_(false) {} |
| 438 | |
| 439 | void OnBeforeNetworkStart(bool* defer) { |
| 440 | *defer = defer_on_before_network_start_; |
| 441 | observed_before_network_start_ = true; |
| 442 | } |
| 443 | |
| 444 | bool observed_before_network_start() const { |
| 445 | return observed_before_network_start_; |
| 446 | } |
| 447 | |
| 448 | private: |
| 449 | const bool defer_on_before_network_start_; |
| 450 | bool observed_before_network_start_; |
| 451 | |
| 452 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 453 | }; |
| 454 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 455 | class BeforeProxyHeadersSentHandler { |
| 456 | public: |
| 457 | BeforeProxyHeadersSentHandler() |
| 458 | : observed_before_proxy_headers_sent_(false) {} |
| 459 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 460 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 461 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 462 | observed_before_proxy_headers_sent_ = true; |
| 463 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 464 | } |
| 465 | |
| 466 | bool observed_before_proxy_headers_sent() const { |
| 467 | return observed_before_proxy_headers_sent_; |
| 468 | } |
| 469 | |
| 470 | std::string observed_proxy_server_uri() const { |
| 471 | return observed_proxy_server_uri_; |
| 472 | } |
| 473 | |
| 474 | private: |
| 475 | bool observed_before_proxy_headers_sent_; |
| 476 | std::string observed_proxy_server_uri_; |
| 477 | |
| 478 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 479 | }; |
| 480 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 481 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 482 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 483 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 484 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 485 | const int sizeof_row = strlen(row); |
| 486 | const int num_rows = static_cast<int>( |
| 487 | ceil(static_cast<float>(size) / sizeof_row)); |
| 488 | const int sizeof_data = num_rows * sizeof_row; |
| 489 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 490 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 491 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 492 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 493 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 496 | // Alternative functions that eliminate randomness and dependency on the local |
| 497 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 498 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 499 | static const uint8 bytes[] = { |
| 500 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 501 | }; |
| 502 | static size_t current_byte = 0; |
| 503 | for (size_t i = 0; i < n; ++i) { |
| 504 | output[i] = bytes[current_byte++]; |
| 505 | current_byte %= arraysize(bytes); |
| 506 | } |
| 507 | } |
| 508 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 509 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 510 | static const uint8 bytes[] = { |
| 511 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 512 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 513 | }; |
| 514 | static size_t current_byte = 0; |
| 515 | for (size_t i = 0; i < n; ++i) { |
| 516 | output[i] = bytes[current_byte++]; |
| 517 | current_byte %= arraysize(bytes); |
| 518 | } |
| 519 | } |
| 520 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 521 | std::string MockGetHostName() { |
| 522 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 525 | template<typename ParentPool> |
| 526 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 527 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 528 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 529 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 530 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 531 | const std::string last_group_name_received() const { |
| 532 | return last_group_name_; |
| 533 | } |
| 534 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 535 | int RequestSocket(const std::string& group_name, |
| 536 | const void* socket_params, |
| 537 | RequestPriority priority, |
| 538 | ClientSocketHandle* handle, |
| 539 | const CompletionCallback& callback, |
| 540 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 541 | last_group_name_ = group_name; |
| 542 | return ERR_IO_PENDING; |
| 543 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 544 | void CancelRequest(const std::string& group_name, |
| 545 | ClientSocketHandle* handle) override {} |
| 546 | void ReleaseSocket(const std::string& group_name, |
| 547 | scoped_ptr<StreamSocket> socket, |
| 548 | int id) override {} |
| 549 | void CloseIdleSockets() override {} |
| 550 | int IdleSocketCount() const override { return 0; } |
| 551 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 552 | return 0; |
| 553 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 554 | LoadState GetLoadState(const std::string& group_name, |
| 555 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 556 | return LOAD_STATE_IDLE; |
| 557 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 558 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 559 | return base::TimeDelta(); |
| 560 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 561 | |
| 562 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 563 | std::string last_group_name_; |
| 564 | }; |
| 565 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 566 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 567 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 568 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 569 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 570 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 571 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 572 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 573 | CaptureGroupNameSSLSocketPool; |
| 574 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 575 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 576 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 577 | HostResolver* host_resolver, |
| 578 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 579 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 580 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 581 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 582 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 583 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 584 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 585 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 586 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 587 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 588 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 589 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 590 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 591 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 592 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 593 | : SSLClientSocketPool(0, |
| 594 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 595 | cert_verifier, |
| 596 | NULL, |
| 597 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 598 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 599 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 600 | std::string(), |
| 601 | NULL, |
| 602 | NULL, |
| 603 | NULL, |
| 604 | NULL, |
| 605 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 606 | NULL) { |
| 607 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 608 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 609 | //----------------------------------------------------------------------------- |
| 610 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 611 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 612 | // configured for common cases. |
| 613 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 614 | if (!auth_challenge) |
| 615 | return false; |
| 616 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 617 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 618 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 619 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 620 | return true; |
| 621 | } |
| 622 | |
| 623 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 624 | if (!auth_challenge) |
| 625 | return false; |
| 626 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 627 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 628 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 629 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 634 | if (!auth_challenge) |
| 635 | return false; |
| 636 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 637 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 638 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 639 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 640 | return true; |
| 641 | } |
| 642 | |
| 643 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 644 | if (!auth_challenge) |
| 645 | return false; |
| 646 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 647 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 648 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 649 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 650 | return true; |
| 651 | } |
| 652 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 653 | } // namespace |
| 654 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 655 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 656 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 657 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 659 | } |
| 660 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 661 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 662 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 663 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 664 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 665 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 666 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 667 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 668 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 669 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 670 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 671 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 672 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 673 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 674 | EXPECT_EQ(0u, out.connection_attempts.size()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 678 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 680 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 681 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 682 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 683 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 684 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 685 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 686 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 687 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 688 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 689 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 693 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 695 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 696 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 697 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 698 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 699 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 700 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 701 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 702 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 703 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 704 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 708 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 709 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 710 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 712 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 713 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 714 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 715 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 716 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 717 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 718 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 719 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | // 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] | 723 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 725 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 726 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 727 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 728 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 729 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 730 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 731 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 732 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 733 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 734 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 738 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 739 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 740 | MockRead("\n"), |
| 741 | MockRead("\n"), |
| 742 | MockRead("Q"), |
| 743 | MockRead("J"), |
| 744 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 745 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 747 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 748 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 749 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 750 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 751 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 752 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 753 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 757 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 758 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 759 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 760 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 762 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 763 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 764 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 765 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 766 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 767 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 768 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 771 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 772 | // persistent connection. The response should still terminate since a 204 |
| 773 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 774 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 775 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 776 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 777 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 778 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 779 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 780 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 781 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 782 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 783 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 784 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 785 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 786 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 787 | int64 response_size = reads_size - strlen(junk); |
| 788 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 789 | } |
| 790 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 791 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 792 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 793 | std::string final_chunk = "0\r\n\r\n"; |
| 794 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 795 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 796 | MockRead data_reads[] = { |
| 797 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 798 | MockRead("5\r\nHello\r\n"), |
| 799 | MockRead("1\r\n"), |
| 800 | MockRead(" \r\n"), |
| 801 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 802 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 804 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 805 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 806 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 807 | EXPECT_EQ(OK, out.rv); |
| 808 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 809 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 810 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 811 | int64 response_size = reads_size - extra_data.size(); |
| 812 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 815 | // Next tests deal with http://crbug.com/56344. |
| 816 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 817 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 818 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 819 | MockRead data_reads[] = { |
| 820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 821 | MockRead("Content-Length: 10\r\n"), |
| 822 | MockRead("Content-Length: 5\r\n\r\n"), |
| 823 | }; |
| 824 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 825 | arraysize(data_reads)); |
| 826 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 827 | } |
| 828 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 829 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 830 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 831 | MockRead data_reads[] = { |
| 832 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 833 | MockRead("Content-Length: 5\r\n"), |
| 834 | MockRead("Content-Length: 5\r\n\r\n"), |
| 835 | MockRead("Hello"), |
| 836 | }; |
| 837 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 838 | arraysize(data_reads)); |
| 839 | EXPECT_EQ(OK, out.rv); |
| 840 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 841 | EXPECT_EQ("Hello", out.response_data); |
| 842 | } |
| 843 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 844 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 845 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 846 | // More than 2 dupes. |
| 847 | { |
| 848 | MockRead data_reads[] = { |
| 849 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n"), |
| 851 | MockRead("Content-Length: 5\r\n"), |
| 852 | MockRead("Content-Length: 5\r\n\r\n"), |
| 853 | MockRead("Hello"), |
| 854 | }; |
| 855 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 856 | arraysize(data_reads)); |
| 857 | EXPECT_EQ(OK, out.rv); |
| 858 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 859 | EXPECT_EQ("Hello", out.response_data); |
| 860 | } |
| 861 | // HTTP/1.0 |
| 862 | { |
| 863 | MockRead data_reads[] = { |
| 864 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 865 | MockRead("Content-Length: 5\r\n"), |
| 866 | MockRead("Content-Length: 5\r\n"), |
| 867 | MockRead("Content-Length: 5\r\n\r\n"), |
| 868 | MockRead("Hello"), |
| 869 | }; |
| 870 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 871 | arraysize(data_reads)); |
| 872 | EXPECT_EQ(OK, out.rv); |
| 873 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 874 | EXPECT_EQ("Hello", out.response_data); |
| 875 | } |
| 876 | // 2 dupes and one mismatched. |
| 877 | { |
| 878 | MockRead data_reads[] = { |
| 879 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 880 | MockRead("Content-Length: 10\r\n"), |
| 881 | MockRead("Content-Length: 10\r\n"), |
| 882 | MockRead("Content-Length: 5\r\n\r\n"), |
| 883 | }; |
| 884 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 885 | arraysize(data_reads)); |
| 886 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 887 | } |
| 888 | } |
| 889 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 890 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 891 | MultipleContentLengthHeadersTransferEncoding) { |
| 892 | MockRead data_reads[] = { |
| 893 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 894 | MockRead("Content-Length: 666\r\n"), |
| 895 | MockRead("Content-Length: 1337\r\n"), |
| 896 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 897 | MockRead("5\r\nHello\r\n"), |
| 898 | MockRead("1\r\n"), |
| 899 | MockRead(" \r\n"), |
| 900 | MockRead("5\r\nworld\r\n"), |
| 901 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 902 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 903 | }; |
| 904 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 905 | arraysize(data_reads)); |
| 906 | EXPECT_EQ(OK, out.rv); |
| 907 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 908 | EXPECT_EQ("Hello world", out.response_data); |
| 909 | } |
| 910 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 911 | // Next tests deal with http://crbug.com/98895. |
| 912 | |
| 913 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 914 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 915 | MockRead data_reads[] = { |
| 916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 917 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 918 | MockRead("Content-Length: 5\r\n\r\n"), |
| 919 | MockRead("Hello"), |
| 920 | }; |
| 921 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 922 | arraysize(data_reads)); |
| 923 | EXPECT_EQ(OK, out.rv); |
| 924 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 925 | EXPECT_EQ("Hello", out.response_data); |
| 926 | } |
| 927 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 928 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 929 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 930 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 931 | MockRead data_reads[] = { |
| 932 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 933 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 934 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 935 | MockRead("Content-Length: 5\r\n\r\n"), |
| 936 | MockRead("Hello"), |
| 937 | }; |
| 938 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 939 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 940 | EXPECT_EQ(OK, out.rv); |
| 941 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 942 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 946 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 947 | MockRead data_reads[] = { |
| 948 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 949 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 950 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 951 | MockRead("Content-Length: 5\r\n\r\n"), |
| 952 | MockRead("Hello"), |
| 953 | }; |
| 954 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 955 | arraysize(data_reads)); |
| 956 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 957 | } |
| 958 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 959 | // Checks that two identical Location headers result in no error. |
| 960 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 961 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 962 | MockRead data_reads[] = { |
| 963 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 964 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 965 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 966 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 967 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 968 | }; |
| 969 | |
| 970 | HttpRequestInfo request; |
| 971 | request.method = "GET"; |
| 972 | request.url = GURL("http://redirect.com/"); |
| 973 | request.load_flags = 0; |
| 974 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 975 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 978 | |
| 979 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 982 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 984 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 986 | |
| 987 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 988 | |
| 989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 990 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 991 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 992 | std::string url; |
| 993 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 994 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 995 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 998 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 999 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1000 | MockRead data_reads[] = { |
| 1001 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1002 | MockRead("Location: http://good.com/\r\n"), |
| 1003 | MockRead("Location: http://evil.com/\r\n"), |
| 1004 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1005 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | }; |
| 1007 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1008 | arraysize(data_reads)); |
| 1009 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1010 | } |
| 1011 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1012 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1013 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1014 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1015 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1016 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1017 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1018 | request.load_flags = 0; |
| 1019 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1020 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1023 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1024 | trans->SetBeforeProxyHeadersSentCallback( |
| 1025 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1026 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1027 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1028 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1029 | MockWrite( |
| 1030 | "HEAD / HTTP/1.1\r\n" |
| 1031 | "Host: www.example.org\r\n" |
| 1032 | "Connection: keep-alive\r\n" |
| 1033 | "Content-Length: 0\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1034 | }; |
| 1035 | MockRead data_reads1[] = { |
| 1036 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1037 | MockRead("Server: Blah\r\n"), |
| 1038 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1039 | |
| 1040 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1041 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1042 | }; |
| 1043 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1044 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1045 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1046 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1048 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1050 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1051 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1052 | |
| 1053 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1054 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1055 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1056 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1057 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1058 | |
| 1059 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1060 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1061 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1062 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1063 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1064 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1065 | |
| 1066 | std::string server_header; |
| 1067 | void* iter = NULL; |
| 1068 | bool has_server_header = response->headers->EnumerateHeader( |
| 1069 | &iter, "Server", &server_header); |
| 1070 | EXPECT_TRUE(has_server_header); |
| 1071 | EXPECT_EQ("Blah", server_header); |
| 1072 | |
| 1073 | // Reading should give EOF right away, since there is no message body |
| 1074 | // (despite non-zero content-length). |
| 1075 | std::string response_data; |
| 1076 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1077 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1078 | EXPECT_EQ("", response_data); |
| 1079 | } |
| 1080 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1081 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1082 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1083 | |
| 1084 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1085 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1086 | MockRead("hello"), |
| 1087 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1088 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1089 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1090 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1091 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1093 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1094 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1095 | "hello", "world" |
| 1096 | }; |
| 1097 | |
| 1098 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1099 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1100 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1101 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1102 | request.load_flags = 0; |
| 1103 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1104 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1105 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1107 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1109 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1110 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1111 | |
| 1112 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1113 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1114 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1115 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1116 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1117 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1118 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1119 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1120 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1121 | |
| 1122 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1123 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1124 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1125 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1129 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1130 | ScopedVector<UploadElementReader> element_readers; |
| 1131 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1132 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1133 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1134 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1135 | request.method = "POST"; |
| 1136 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1137 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1138 | request.load_flags = 0; |
| 1139 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1140 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1141 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1142 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1143 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1145 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1146 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1147 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1148 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1150 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1153 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1155 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1156 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1157 | |
| 1158 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1159 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1160 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1161 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1162 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1163 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1164 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1165 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1166 | |
| 1167 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1168 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1169 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1170 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1171 | } |
| 1172 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1173 | // This test is almost the same as Ignores100 above, but the response contains |
| 1174 | // 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] | 1175 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1176 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1178 | request.method = "GET"; |
| 1179 | request.url = GURL("http://www.foo.com/"); |
| 1180 | request.load_flags = 0; |
| 1181 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1182 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1183 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1184 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1185 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1186 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1187 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1188 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1189 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1190 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1191 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1192 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1195 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1197 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1198 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1199 | |
| 1200 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1201 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1202 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1203 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1204 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1205 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1206 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1207 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1208 | |
| 1209 | std::string response_data; |
| 1210 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1211 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1212 | EXPECT_EQ("hello world", response_data); |
| 1213 | } |
| 1214 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1215 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1216 | HttpRequestInfo request; |
| 1217 | request.method = "POST"; |
| 1218 | request.url = GURL("http://www.foo.com/"); |
| 1219 | request.load_flags = 0; |
| 1220 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1221 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1222 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1223 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1224 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1225 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1226 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1227 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1228 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1229 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1230 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1232 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1234 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1236 | |
| 1237 | rv = callback.WaitForResult(); |
| 1238 | EXPECT_EQ(OK, rv); |
| 1239 | |
| 1240 | std::string response_data; |
| 1241 | rv = ReadTransaction(trans.get(), &response_data); |
| 1242 | EXPECT_EQ(OK, rv); |
| 1243 | EXPECT_EQ("", response_data); |
| 1244 | } |
| 1245 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1246 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1247 | HttpRequestInfo request; |
| 1248 | request.method = "POST"; |
| 1249 | request.url = GURL("http://www.foo.com/"); |
| 1250 | request.load_flags = 0; |
| 1251 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1252 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1253 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1254 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1255 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1256 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1257 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1258 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1259 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1260 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1262 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1264 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1266 | |
| 1267 | rv = callback.WaitForResult(); |
| 1268 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1269 | } |
| 1270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1271 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1272 | const MockWrite* write_failure, |
| 1273 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1274 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1275 | request.method = "GET"; |
| 1276 | request.url = GURL("http://www.foo.com/"); |
| 1277 | request.load_flags = 0; |
| 1278 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1279 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1280 | session_deps_.net_log = &net_log; |
| 1281 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1282 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1283 | // Written data for successfully sending both requests. |
| 1284 | MockWrite data1_writes[] = { |
| 1285 | MockWrite("GET / HTTP/1.1\r\n" |
| 1286 | "Host: www.foo.com\r\n" |
| 1287 | "Connection: keep-alive\r\n\r\n"), |
| 1288 | MockWrite("GET / HTTP/1.1\r\n" |
| 1289 | "Host: www.foo.com\r\n" |
| 1290 | "Connection: keep-alive\r\n\r\n") |
| 1291 | }; |
| 1292 | |
| 1293 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1295 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1296 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1297 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1299 | |
| 1300 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1301 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1302 | data1_writes[1] = *write_failure; |
| 1303 | } else { |
| 1304 | ASSERT_TRUE(read_failure); |
| 1305 | data1_reads[2] = *read_failure; |
| 1306 | } |
| 1307 | |
| 1308 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1309 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
| 1312 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1313 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1314 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1315 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1317 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1318 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1320 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | "hello", "world" |
| 1322 | }; |
| 1323 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1324 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1326 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1328 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1331 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1332 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
| 1334 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1335 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1337 | LoadTimingInfo load_timing_info; |
| 1338 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1339 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1340 | if (i == 0) { |
| 1341 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1342 | } else { |
| 1343 | // The second request should be using a new socket. |
| 1344 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1345 | } |
| 1346 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1347 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1348 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1350 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1351 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
| 1353 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1354 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1355 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1356 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1357 | } |
| 1358 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1359 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1360 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1361 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1362 | const MockRead* read_failure, |
| 1363 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1364 | HttpRequestInfo request; |
| 1365 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1366 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1367 | request.load_flags = 0; |
| 1368 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1369 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1370 | session_deps_.net_log = &net_log; |
| 1371 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1372 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1373 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1374 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1375 | if (use_spdy) { |
| 1376 | ssl1.SetNextProto(GetParam()); |
| 1377 | ssl2.SetNextProto(GetParam()); |
| 1378 | } |
| 1379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1381 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1382 | // SPDY versions of the request and response. |
| 1383 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1384 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1385 | scoped_ptr<SpdyFrame> spdy_response( |
| 1386 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1387 | scoped_ptr<SpdyFrame> spdy_data( |
| 1388 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1389 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1390 | // HTTP/1.1 versions of the request and response. |
| 1391 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1392 | "Host: www.foo.com\r\n" |
| 1393 | "Connection: keep-alive\r\n\r\n"; |
| 1394 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1395 | const char kHttpData[] = "hello"; |
| 1396 | |
| 1397 | std::vector<MockRead> data1_reads; |
| 1398 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1399 | if (write_failure) { |
| 1400 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1401 | data1_writes.push_back(*write_failure); |
| 1402 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1403 | } else { |
| 1404 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1405 | if (use_spdy) { |
| 1406 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1407 | } else { |
| 1408 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1409 | } |
| 1410 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1411 | } |
| 1412 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1413 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1414 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1416 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1417 | std::vector<MockRead> data2_reads; |
| 1418 | std::vector<MockWrite> data2_writes; |
| 1419 | |
| 1420 | if (use_spdy) { |
| 1421 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1422 | |
| 1423 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1424 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1425 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1426 | } else { |
| 1427 | data2_writes.push_back( |
| 1428 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1429 | |
| 1430 | data2_reads.push_back( |
| 1431 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1432 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1433 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1434 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1435 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1436 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1438 | |
| 1439 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1440 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1441 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1442 | session->GetNextProtos(&ssl_config.next_protos); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1443 | session->http_stream_factory()->PreconnectStreams( |
| 1444 | 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); |
| 1445 | // Wait for the preconnect to complete. |
| 1446 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1447 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1448 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1449 | |
| 1450 | // Make the request. |
| 1451 | TestCompletionCallback callback; |
| 1452 | |
| 1453 | scoped_ptr<HttpTransaction> trans( |
| 1454 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1455 | |
| 1456 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1457 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1458 | |
| 1459 | rv = callback.WaitForResult(); |
| 1460 | EXPECT_EQ(OK, rv); |
| 1461 | |
| 1462 | LoadTimingInfo load_timing_info; |
| 1463 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1464 | TestLoadTimingNotReused( |
| 1465 | load_timing_info, |
| 1466 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | |
| 1468 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1469 | ASSERT_TRUE(response != NULL); |
| 1470 | |
| 1471 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1472 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1473 | |
| 1474 | std::string response_data; |
| 1475 | rv = ReadTransaction(trans.get(), &response_data); |
| 1476 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1477 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1478 | } |
| 1479 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1480 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1481 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1482 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1483 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1484 | } |
| 1485 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1486 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1487 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1488 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1489 | } |
| 1490 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1491 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1492 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1493 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1494 | } |
| 1495 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1496 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1497 | // if the socket was a reused keep alive socket. |
| 1498 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1499 | MockRead read_failure(SYNCHRONOUS, |
| 1500 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1501 | "Connection: Keep-Alive\r\n" |
| 1502 | "Content-Length: 6\r\n\r\n" |
| 1503 | "Pickle"); |
| 1504 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1505 | } |
| 1506 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1507 | TEST_P(HttpNetworkTransactionTest, |
| 1508 | PreconnectErrorNotConnectedOnWrite) { |
| 1509 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1510 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1514 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1515 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1519 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1520 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1521 | } |
| 1522 | |
| 1523 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1524 | MockRead read_failure(ASYNC, OK); // EOF |
| 1525 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1526 | } |
| 1527 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1528 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1529 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1530 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1531 | MockRead read_failure(SYNCHRONOUS, |
| 1532 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1533 | "Connection: Keep-Alive\r\n" |
| 1534 | "Content-Length: 6\r\n\r\n" |
| 1535 | "Pickle"); |
| 1536 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1537 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1538 | } |
| 1539 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1540 | TEST_P(HttpNetworkTransactionTest, |
| 1541 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1542 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1543 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1544 | } |
| 1545 | |
| 1546 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1547 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1548 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1549 | } |
| 1550 | |
| 1551 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1552 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1553 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1554 | } |
| 1555 | |
| 1556 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1557 | MockRead read_failure(ASYNC, OK); // EOF |
| 1558 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1559 | } |
| 1560 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1561 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1562 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1564 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1565 | request.load_flags = 0; |
| 1566 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1567 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1568 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1569 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1570 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1571 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1572 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1573 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1575 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1576 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1577 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1578 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1580 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1582 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1583 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1584 | |
| 1585 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1586 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | // What do various browsers do when the server closes a non-keepalive |
| 1590 | // connection without sending any response header or body? |
| 1591 | // |
| 1592 | // IE7: error page |
| 1593 | // Safari 3.1.2 (Windows): error page |
| 1594 | // Firefox 3.0.1: blank page |
| 1595 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1596 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1597 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1598 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1599 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1600 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1601 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1602 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1603 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1604 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1605 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1606 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1607 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1608 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1609 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1610 | // Test that network access can be deferred and resumed. |
| 1611 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1612 | HttpRequestInfo request; |
| 1613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1614 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1615 | request.load_flags = 0; |
| 1616 | |
| 1617 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1618 | scoped_ptr<HttpTransaction> trans( |
| 1619 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1620 | |
| 1621 | // Defer on OnBeforeNetworkStart. |
| 1622 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1623 | trans->SetBeforeNetworkStartCallback( |
| 1624 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1625 | base::Unretained(&net_start_handler))); |
| 1626 | |
| 1627 | MockRead data_reads[] = { |
| 1628 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1629 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1630 | MockRead("hello"), |
| 1631 | MockRead(SYNCHRONOUS, 0), |
| 1632 | }; |
| 1633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1635 | |
| 1636 | TestCompletionCallback callback; |
| 1637 | |
| 1638 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1640 | base::MessageLoop::current()->RunUntilIdle(); |
| 1641 | |
| 1642 | // Should have deferred for network start. |
| 1643 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1644 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1645 | |
| 1646 | trans->ResumeNetworkStart(); |
| 1647 | rv = callback.WaitForResult(); |
| 1648 | EXPECT_EQ(OK, rv); |
| 1649 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1650 | |
| 1651 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1652 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1653 | if (rv == ERR_IO_PENDING) |
| 1654 | rv = callback.WaitForResult(); |
| 1655 | EXPECT_EQ(5, rv); |
| 1656 | trans.reset(); |
| 1657 | } |
| 1658 | |
| 1659 | // Test that network use can be deferred and canceled. |
| 1660 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1661 | HttpRequestInfo request; |
| 1662 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1663 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1664 | request.load_flags = 0; |
| 1665 | |
| 1666 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1667 | scoped_ptr<HttpTransaction> trans( |
| 1668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1669 | |
| 1670 | // Defer on OnBeforeNetworkStart. |
| 1671 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1672 | trans->SetBeforeNetworkStartCallback( |
| 1673 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1674 | base::Unretained(&net_start_handler))); |
| 1675 | |
| 1676 | TestCompletionCallback callback; |
| 1677 | |
| 1678 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1680 | base::MessageLoop::current()->RunUntilIdle(); |
| 1681 | |
| 1682 | // Should have deferred for network start. |
| 1683 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1684 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1685 | } |
| 1686 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1687 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1688 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1689 | // destructor in such situations. |
| 1690 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1691 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1692 | HttpRequestInfo request; |
| 1693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1695 | request.load_flags = 0; |
| 1696 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1697 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1698 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1699 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1700 | |
| 1701 | MockRead data_reads[] = { |
| 1702 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1703 | MockRead("Connection: keep-alive\r\n"), |
| 1704 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1705 | MockRead("hello"), |
| 1706 | MockRead(SYNCHRONOUS, 0), |
| 1707 | }; |
| 1708 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1710 | |
| 1711 | TestCompletionCallback callback; |
| 1712 | |
| 1713 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1714 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1715 | |
| 1716 | rv = callback.WaitForResult(); |
| 1717 | EXPECT_EQ(OK, rv); |
| 1718 | |
| 1719 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1720 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1721 | if (rv == ERR_IO_PENDING) |
| 1722 | rv = callback.WaitForResult(); |
| 1723 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1724 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1725 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1726 | |
| 1727 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1728 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1729 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1730 | } |
| 1731 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1732 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1733 | HttpRequestInfo request; |
| 1734 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1735 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1736 | request.load_flags = 0; |
| 1737 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1738 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1739 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1740 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1741 | |
| 1742 | MockRead data_reads[] = { |
| 1743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1744 | MockRead("Connection: keep-alive\r\n"), |
| 1745 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1746 | MockRead(SYNCHRONOUS, 0), |
| 1747 | }; |
| 1748 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1750 | |
| 1751 | TestCompletionCallback callback; |
| 1752 | |
| 1753 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1754 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1755 | |
| 1756 | rv = callback.WaitForResult(); |
| 1757 | EXPECT_EQ(OK, rv); |
| 1758 | |
| 1759 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1760 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1761 | if (rv == ERR_IO_PENDING) |
| 1762 | rv = callback.WaitForResult(); |
| 1763 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1764 | |
| 1765 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1766 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1767 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1768 | } |
| 1769 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1770 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1771 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1772 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1773 | HttpRequestInfo request; |
| 1774 | request.method = "GET"; |
| 1775 | request.url = GURL("http://www.foo.com/"); |
| 1776 | request.load_flags = 0; |
| 1777 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1778 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1779 | session_deps_.net_log = &net_log; |
| 1780 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1781 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1782 | // Note that because all these reads happen in the same |
| 1783 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1784 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1785 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1786 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1787 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1788 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1789 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1790 | "Content-Length: 0\r\n\r\n"), |
| 1791 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1792 | "Content-Length: 5\r\n\r\n" |
| 1793 | "hello"), |
| 1794 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1795 | "Content-Length: 0\r\n\r\n"), |
| 1796 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1797 | "Content-Length: 5\r\n\r\n" |
| 1798 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1799 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1800 | MockRead("hello"), |
| 1801 | }; |
| 1802 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1804 | |
| 1805 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1806 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1807 | }; |
| 1808 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1809 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1810 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1811 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1812 | std::string response_lines[kNumUnreadBodies]; |
| 1813 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1814 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1815 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1816 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1817 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1818 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1819 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1821 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1822 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1823 | |
| 1824 | rv = callback.WaitForResult(); |
| 1825 | EXPECT_EQ(OK, rv); |
| 1826 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1827 | LoadTimingInfo load_timing_info; |
| 1828 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1829 | if (i == 0) { |
| 1830 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1831 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1832 | } else { |
| 1833 | TestLoadTimingReused(load_timing_info); |
| 1834 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1835 | } |
| 1836 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1837 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1838 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1839 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1840 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1841 | response_lines[i] = response->headers->GetStatusLine(); |
| 1842 | |
| 1843 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1844 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1845 | |
| 1846 | const char* const kStatusLines[] = { |
| 1847 | "HTTP/1.1 204 No Content", |
| 1848 | "HTTP/1.1 205 Reset Content", |
| 1849 | "HTTP/1.1 304 Not Modified", |
| 1850 | "HTTP/1.1 302 Found", |
| 1851 | "HTTP/1.1 302 Found", |
| 1852 | "HTTP/1.1 301 Moved Permanently", |
| 1853 | "HTTP/1.1 301 Moved Permanently", |
| 1854 | }; |
| 1855 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1856 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1857 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1858 | |
| 1859 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1860 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1862 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1865 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1866 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1867 | rv = callback.WaitForResult(); |
| 1868 | EXPECT_EQ(OK, rv); |
| 1869 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1870 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1871 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1872 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1873 | std::string response_data; |
| 1874 | rv = ReadTransaction(trans.get(), &response_data); |
| 1875 | EXPECT_EQ(OK, rv); |
| 1876 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1877 | } |
| 1878 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1879 | // Test the request-challenge-retry sequence for basic auth. |
| 1880 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1881 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1882 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1884 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1885 | request.load_flags = 0; |
| 1886 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1887 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1888 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1889 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1890 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1892 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1893 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1894 | MockWrite( |
| 1895 | "GET / HTTP/1.1\r\n" |
| 1896 | "Host: www.example.org\r\n" |
| 1897 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1898 | }; |
| 1899 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1900 | MockRead data_reads1[] = { |
| 1901 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1902 | // Give a couple authenticate options (only the middle one is actually |
| 1903 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1904 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1905 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1906 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1908 | // Large content-length -- won't matter, as connection will be reset. |
| 1909 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1910 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1911 | }; |
| 1912 | |
| 1913 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1914 | // be issuing -- the final header line contains the credentials. |
| 1915 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1916 | MockWrite( |
| 1917 | "GET / HTTP/1.1\r\n" |
| 1918 | "Host: www.example.org\r\n" |
| 1919 | "Connection: keep-alive\r\n" |
| 1920 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1921 | }; |
| 1922 | |
| 1923 | // Lastly, the server responds with the actual content. |
| 1924 | MockRead data_reads2[] = { |
| 1925 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1927 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1928 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1929 | }; |
| 1930 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1931 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1932 | data_writes1, arraysize(data_writes1)); |
| 1933 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1934 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1935 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1936 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1938 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1940 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1942 | |
| 1943 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1944 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1945 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1946 | LoadTimingInfo load_timing_info1; |
| 1947 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1948 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1949 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1950 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1951 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1952 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1953 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1954 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1955 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1957 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1959 | rv = trans->RestartWithAuth( |
| 1960 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1961 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1962 | |
| 1963 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1964 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1965 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1966 | LoadTimingInfo load_timing_info2; |
| 1967 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1968 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1969 | // The load timing after restart should have a new socket ID, and times after |
| 1970 | // those of the first load timing. |
| 1971 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1972 | load_timing_info2.connect_timing.connect_start); |
| 1973 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1974 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1975 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1976 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1977 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1978 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1979 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1980 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1981 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1984 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1985 | HttpRequestInfo request; |
| 1986 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1987 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1988 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1989 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1990 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1991 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1993 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1994 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1995 | MockWrite( |
| 1996 | "GET / HTTP/1.1\r\n" |
| 1997 | "Host: www.example.org\r\n" |
| 1998 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1999 | }; |
| 2000 | |
| 2001 | MockRead data_reads[] = { |
| 2002 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2003 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2004 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2005 | // Large content-length -- won't matter, as connection will be reset. |
| 2006 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2007 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2008 | }; |
| 2009 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2010 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2011 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2012 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2013 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2015 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2016 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2017 | |
| 2018 | rv = callback.WaitForResult(); |
| 2019 | EXPECT_EQ(0, rv); |
| 2020 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2021 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2022 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2023 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2024 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2025 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2026 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2027 | } |
| 2028 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2029 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2030 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2031 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2032 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2034 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2035 | request.load_flags = 0; |
| 2036 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2037 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2038 | session_deps_.net_log = &log; |
| 2039 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2040 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2041 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2042 | MockWrite( |
| 2043 | "GET / HTTP/1.1\r\n" |
| 2044 | "Host: www.example.org\r\n" |
| 2045 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2046 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2047 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2048 | // be issuing -- the final header line contains the credentials. |
| 2049 | MockWrite( |
| 2050 | "GET / HTTP/1.1\r\n" |
| 2051 | "Host: www.example.org\r\n" |
| 2052 | "Connection: keep-alive\r\n" |
| 2053 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2054 | }; |
| 2055 | |
| 2056 | MockRead data_reads1[] = { |
| 2057 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2058 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2059 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2060 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2061 | MockRead("Unauthorized\r\n"), |
| 2062 | |
| 2063 | // Lastly, the server responds with the actual content. |
| 2064 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2065 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2066 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2067 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2068 | }; |
| 2069 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2070 | // If there is a regression where we disconnect a Keep-Alive |
| 2071 | // connection during an auth roundtrip, we'll end up reading this. |
| 2072 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2073 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2074 | }; |
| 2075 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2076 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2077 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2078 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2079 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2080 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2081 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2083 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2084 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2085 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2087 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2089 | |
| 2090 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2091 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2092 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2093 | LoadTimingInfo load_timing_info1; |
| 2094 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2095 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2096 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2098 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2099 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2101 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2103 | rv = trans->RestartWithAuth( |
| 2104 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2106 | |
| 2107 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2108 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2109 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2110 | LoadTimingInfo load_timing_info2; |
| 2111 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2112 | TestLoadTimingReused(load_timing_info2); |
| 2113 | // The load timing after restart should have the same socket ID, and times |
| 2114 | // those of the first load timing. |
| 2115 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2116 | load_timing_info2.send_start); |
| 2117 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2118 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2119 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2120 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2121 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2122 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2123 | |
| 2124 | std::string response_data; |
| 2125 | rv = ReadTransaction(trans.get(), &response_data); |
| 2126 | EXPECT_EQ(OK, rv); |
| 2127 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2128 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2132 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2133 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2134 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2135 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2136 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2137 | request.load_flags = 0; |
| 2138 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2139 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2140 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2141 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2142 | MockWrite( |
| 2143 | "GET / HTTP/1.1\r\n" |
| 2144 | "Host: www.example.org\r\n" |
| 2145 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2146 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2147 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2148 | // be issuing -- the final header line contains the credentials. |
| 2149 | MockWrite( |
| 2150 | "GET / HTTP/1.1\r\n" |
| 2151 | "Host: www.example.org\r\n" |
| 2152 | "Connection: keep-alive\r\n" |
| 2153 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2154 | }; |
| 2155 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2156 | MockRead data_reads1[] = { |
| 2157 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2158 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2159 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2160 | |
| 2161 | // Lastly, the server responds with the actual content. |
| 2162 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2163 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2164 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2165 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2166 | }; |
| 2167 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2168 | // An incorrect reconnect would cause this to be read. |
| 2169 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2170 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2171 | }; |
| 2172 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2173 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2174 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2175 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2176 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2177 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2178 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2180 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2181 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2182 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2183 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2184 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | |
| 2187 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2188 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2189 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2190 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2191 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2192 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2194 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2196 | rv = trans->RestartWithAuth( |
| 2197 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2198 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2199 | |
| 2200 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2201 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2202 | |
| 2203 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2204 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2205 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2206 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2210 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2211 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2212 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2213 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2214 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2215 | request.load_flags = 0; |
| 2216 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2217 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2218 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2219 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2220 | MockWrite( |
| 2221 | "GET / HTTP/1.1\r\n" |
| 2222 | "Host: www.example.org\r\n" |
| 2223 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2224 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2225 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2226 | // be issuing -- the final header line contains the credentials. |
| 2227 | MockWrite( |
| 2228 | "GET / HTTP/1.1\r\n" |
| 2229 | "Host: www.example.org\r\n" |
| 2230 | "Connection: keep-alive\r\n" |
| 2231 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2232 | }; |
| 2233 | |
| 2234 | // Respond with 5 kb of response body. |
| 2235 | std::string large_body_string("Unauthorized"); |
| 2236 | large_body_string.append(5 * 1024, ' '); |
| 2237 | large_body_string.append("\r\n"); |
| 2238 | |
| 2239 | MockRead data_reads1[] = { |
| 2240 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2241 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2242 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2243 | // 5134 = 12 + 5 * 1024 + 2 |
| 2244 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2245 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2246 | |
| 2247 | // Lastly, the server responds with the actual content. |
| 2248 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2249 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2250 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2251 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2252 | }; |
| 2253 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2254 | // An incorrect reconnect would cause this to be read. |
| 2255 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2256 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2257 | }; |
| 2258 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2259 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2260 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2261 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2262 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2263 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2264 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2266 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2267 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2268 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2270 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2272 | |
| 2273 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2274 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2275 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2276 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2277 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2278 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2280 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2282 | rv = trans->RestartWithAuth( |
| 2283 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2284 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2285 | |
| 2286 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2287 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2288 | |
| 2289 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2290 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2291 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2292 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2296 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2297 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2298 | HttpRequestInfo request; |
| 2299 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2300 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2301 | request.load_flags = 0; |
| 2302 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2303 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2304 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2305 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2306 | MockWrite( |
| 2307 | "GET / HTTP/1.1\r\n" |
| 2308 | "Host: www.example.org\r\n" |
| 2309 | "Connection: keep-alive\r\n\r\n"), |
| 2310 | // This simulates the seemingly successful write to a closed connection |
| 2311 | // if the bug is not fixed. |
| 2312 | MockWrite( |
| 2313 | "GET / HTTP/1.1\r\n" |
| 2314 | "Host: www.example.org\r\n" |
| 2315 | "Connection: keep-alive\r\n" |
| 2316 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2317 | }; |
| 2318 | |
| 2319 | MockRead data_reads1[] = { |
| 2320 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2321 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2322 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2323 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2324 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2325 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2326 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2327 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2328 | }; |
| 2329 | |
| 2330 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2331 | // be issuing -- the final header line contains the credentials. |
| 2332 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2333 | MockWrite( |
| 2334 | "GET / HTTP/1.1\r\n" |
| 2335 | "Host: www.example.org\r\n" |
| 2336 | "Connection: keep-alive\r\n" |
| 2337 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2338 | }; |
| 2339 | |
| 2340 | // Lastly, the server responds with the actual content. |
| 2341 | MockRead data_reads2[] = { |
| 2342 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2343 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2344 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2345 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2346 | }; |
| 2347 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2348 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2349 | data_writes1, arraysize(data_writes1)); |
| 2350 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2351 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2352 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2353 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2355 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2356 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2357 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2358 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2359 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2360 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2361 | |
| 2362 | rv = callback1.WaitForResult(); |
| 2363 | EXPECT_EQ(OK, rv); |
| 2364 | |
| 2365 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2366 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2367 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2369 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2371 | rv = trans->RestartWithAuth( |
| 2372 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2373 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2374 | |
| 2375 | rv = callback2.WaitForResult(); |
| 2376 | EXPECT_EQ(OK, rv); |
| 2377 | |
| 2378 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2379 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2380 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2381 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2382 | } |
| 2383 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2384 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2385 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2386 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2387 | HttpRequestInfo request; |
| 2388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2389 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2390 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2391 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2392 | |
| 2393 | // Configure against proxy server "myproxy:70". |
| 2394 | session_deps_.proxy_service.reset( |
| 2395 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2396 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2397 | session_deps_.net_log = log.bound().net_log(); |
| 2398 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2399 | |
| 2400 | // Since we have proxy, should try to establish tunnel. |
| 2401 | MockWrite data_writes1[] = { |
| 2402 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2403 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2404 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2405 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2406 | |
| 2407 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2408 | // be issuing -- the final header line contains the credentials. |
| 2409 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2410 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2411 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2412 | "Proxy-Connection: keep-alive\r\n" |
| 2413 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2414 | |
| 2415 | MockWrite( |
| 2416 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2417 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2418 | "Connection: keep-alive\r\n\r\n"), |
| 2419 | }; |
| 2420 | |
| 2421 | // The proxy responds to the connect with a 407, using a persistent |
| 2422 | // connection. |
| 2423 | MockRead data_reads1[] = { |
| 2424 | // No credentials. |
| 2425 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2426 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 2427 | |
| 2428 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2429 | |
| 2430 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2432 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2433 | MockRead(SYNCHRONOUS, "hello"), |
| 2434 | }; |
| 2435 | |
| 2436 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2437 | data_writes1, arraysize(data_writes1)); |
| 2438 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2439 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2441 | |
| 2442 | TestCompletionCallback callback1; |
| 2443 | |
| 2444 | scoped_ptr<HttpTransaction> trans( |
| 2445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2446 | |
| 2447 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2448 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2449 | |
| 2450 | rv = callback1.WaitForResult(); |
| 2451 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2452 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2453 | log.GetEntries(&entries); |
| 2454 | size_t pos = ExpectLogContainsSomewhere( |
| 2455 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2456 | NetLog::PHASE_NONE); |
| 2457 | ExpectLogContainsSomewhere( |
| 2458 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2459 | NetLog::PHASE_NONE); |
| 2460 | |
| 2461 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2462 | ASSERT_TRUE(response != NULL); |
| 2463 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2464 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2465 | EXPECT_EQ(407, response->headers->response_code()); |
| 2466 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2467 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2468 | |
| 2469 | LoadTimingInfo load_timing_info; |
| 2470 | // CONNECT requests and responses are handled at the connect job level, so |
| 2471 | // the transaction does not yet have a connection. |
| 2472 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2473 | |
| 2474 | TestCompletionCallback callback2; |
| 2475 | |
| 2476 | rv = |
| 2477 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2478 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2479 | |
| 2480 | rv = callback2.WaitForResult(); |
| 2481 | EXPECT_EQ(OK, rv); |
| 2482 | |
| 2483 | response = trans->GetResponseInfo(); |
| 2484 | ASSERT_TRUE(response != NULL); |
| 2485 | |
| 2486 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2487 | EXPECT_EQ(200, response->headers->response_code()); |
| 2488 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2489 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2490 | |
| 2491 | // The password prompt info should not be set. |
| 2492 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2493 | |
| 2494 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2495 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2496 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2497 | |
| 2498 | trans.reset(); |
| 2499 | session->CloseAllConnections(); |
| 2500 | } |
| 2501 | |
| 2502 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2503 | // that requires a restart when setting up an SSL tunnel. |
| 2504 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2505 | HttpRequestInfo request; |
| 2506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2507 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2508 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2509 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2510 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2511 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2512 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2513 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2514 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2515 | session_deps_.net_log = log.bound().net_log(); |
| 2516 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2517 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2518 | // Since we have proxy, should try to establish tunnel. |
| 2519 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2520 | MockWrite( |
| 2521 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2522 | "Host: www.example.org\r\n" |
| 2523 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2524 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2525 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2526 | // be issuing -- the final header line contains the credentials. |
| 2527 | MockWrite( |
| 2528 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2529 | "Host: www.example.org\r\n" |
| 2530 | "Proxy-Connection: keep-alive\r\n" |
| 2531 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2532 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2533 | MockWrite( |
| 2534 | "GET / HTTP/1.1\r\n" |
| 2535 | "Host: www.example.org\r\n" |
| 2536 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2537 | }; |
| 2538 | |
| 2539 | // The proxy responds to the connect with a 407, using a persistent |
| 2540 | // connection. |
| 2541 | MockRead data_reads1[] = { |
| 2542 | // No credentials. |
| 2543 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2544 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2545 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2546 | |
| 2547 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2548 | |
| 2549 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2551 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2552 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2553 | }; |
| 2554 | |
| 2555 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2556 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2557 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2558 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2559 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2561 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2562 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2563 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2564 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2566 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2568 | |
| 2569 | rv = callback1.WaitForResult(); |
| 2570 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2571 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2572 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2573 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2574 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2575 | NetLog::PHASE_NONE); |
| 2576 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2577 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2578 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2579 | NetLog::PHASE_NONE); |
| 2580 | |
| 2581 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2582 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2583 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2584 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2585 | EXPECT_EQ(407, response->headers->response_code()); |
| 2586 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2587 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2588 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2589 | LoadTimingInfo load_timing_info; |
| 2590 | // CONNECT requests and responses are handled at the connect job level, so |
| 2591 | // the transaction does not yet have a connection. |
| 2592 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2594 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2596 | rv = trans->RestartWithAuth( |
| 2597 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2599 | |
| 2600 | rv = callback2.WaitForResult(); |
| 2601 | EXPECT_EQ(OK, rv); |
| 2602 | |
| 2603 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2604 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2605 | |
| 2606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2607 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2608 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2609 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2610 | |
| 2611 | // The password prompt info should not be set. |
| 2612 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2613 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2614 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2615 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2616 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2617 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2618 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2619 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2620 | } |
| 2621 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2622 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2623 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2624 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2625 | HttpRequestInfo request; |
| 2626 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2627 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2628 | // Ensure that proxy authentication is attempted even |
| 2629 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2630 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2631 | |
| 2632 | // Configure against proxy server "myproxy:70". |
| 2633 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2634 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2635 | session_deps_.net_log = log.bound().net_log(); |
| 2636 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2637 | |
| 2638 | scoped_ptr<HttpTransaction> trans( |
| 2639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2640 | |
| 2641 | // Since we have proxy, should try to establish tunnel. |
| 2642 | MockWrite data_writes1[] = { |
| 2643 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2644 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2645 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2646 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2647 | |
| 2648 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2649 | // be issuing -- the final header line contains the credentials. |
| 2650 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2651 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2652 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2653 | "Proxy-Connection: keep-alive\r\n" |
| 2654 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2655 | }; |
| 2656 | |
| 2657 | // The proxy responds to the connect with a 407, using a persistent |
| 2658 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2659 | MockRead data_reads1[] = { |
| 2660 | // No credentials. |
| 2661 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2662 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2663 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2664 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2665 | MockRead("0123456789"), |
| 2666 | |
| 2667 | // Wrong credentials (wrong password). |
| 2668 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2669 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2670 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2671 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2672 | // No response body because the test stops reading here. |
| 2673 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2674 | }; |
| 2675 | |
| 2676 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2677 | data_writes1, arraysize(data_writes1)); |
| 2678 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2679 | |
| 2680 | TestCompletionCallback callback1; |
| 2681 | |
| 2682 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2683 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2684 | |
| 2685 | rv = callback1.WaitForResult(); |
| 2686 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2687 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2688 | log.GetEntries(&entries); |
| 2689 | size_t pos = ExpectLogContainsSomewhere( |
| 2690 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2691 | NetLog::PHASE_NONE); |
| 2692 | ExpectLogContainsSomewhere( |
| 2693 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2694 | NetLog::PHASE_NONE); |
| 2695 | |
| 2696 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2697 | ASSERT_TRUE(response); |
| 2698 | ASSERT_TRUE(response->headers); |
| 2699 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2700 | EXPECT_EQ(407, response->headers->response_code()); |
| 2701 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2702 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2703 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2704 | |
| 2705 | TestCompletionCallback callback2; |
| 2706 | |
| 2707 | // Wrong password (should be "bar"). |
| 2708 | rv = |
| 2709 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2711 | |
| 2712 | rv = callback2.WaitForResult(); |
| 2713 | EXPECT_EQ(OK, rv); |
| 2714 | |
| 2715 | response = trans->GetResponseInfo(); |
| 2716 | ASSERT_TRUE(response); |
| 2717 | ASSERT_TRUE(response->headers); |
| 2718 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2719 | EXPECT_EQ(407, response->headers->response_code()); |
| 2720 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2721 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2722 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2723 | |
| 2724 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2725 | // out of scope. |
| 2726 | session->CloseAllConnections(); |
| 2727 | } |
| 2728 | |
| 2729 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2730 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2731 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2732 | HttpRequestInfo request; |
| 2733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2734 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2735 | // Ensure that proxy authentication is attempted even |
| 2736 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2737 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2738 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2740 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2741 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2742 | session_deps_.net_log = log.bound().net_log(); |
| 2743 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2744 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2745 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2746 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2748 | // Since we have proxy, should try to establish tunnel. |
| 2749 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2750 | MockWrite( |
| 2751 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2752 | "Host: www.example.org\r\n" |
| 2753 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2754 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2755 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2756 | // be issuing -- the final header line contains the credentials. |
| 2757 | MockWrite( |
| 2758 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2759 | "Host: www.example.org\r\n" |
| 2760 | "Proxy-Connection: keep-alive\r\n" |
| 2761 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2762 | }; |
| 2763 | |
| 2764 | // The proxy responds to the connect with a 407, using a persistent |
| 2765 | // connection. |
| 2766 | MockRead data_reads1[] = { |
| 2767 | // No credentials. |
| 2768 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2769 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2770 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2771 | MockRead("0123456789"), |
| 2772 | |
| 2773 | // Wrong credentials (wrong password). |
| 2774 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2775 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2776 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2777 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2778 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | }; |
| 2780 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2781 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2782 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2783 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2785 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2787 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2788 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | |
| 2790 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2791 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2792 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2793 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2794 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2795 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2796 | NetLog::PHASE_NONE); |
| 2797 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2798 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2799 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2800 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2802 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2803 | ASSERT_TRUE(response); |
| 2804 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2806 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2807 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2808 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2809 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2811 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2812 | |
| 2813 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2814 | rv = trans->RestartWithAuth( |
| 2815 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2816 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2817 | |
| 2818 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2819 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2820 | |
| 2821 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2822 | ASSERT_TRUE(response); |
| 2823 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2824 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2825 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2826 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2827 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2828 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2829 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2830 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2831 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2832 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2833 | } |
| 2834 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2835 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2836 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2837 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2838 | HttpRequestInfo request; |
| 2839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2840 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2841 | request.load_flags = 0; |
| 2842 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2843 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2844 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2845 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2846 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2850 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2851 | // Since we have proxy, should try to establish tunnel. |
| 2852 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2853 | MockWrite( |
| 2854 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2855 | "Host: www.example.org\r\n" |
| 2856 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2857 | }; |
| 2858 | |
| 2859 | // The proxy responds to the connect with a 407. |
| 2860 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2861 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2862 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2863 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2864 | MockRead("0123456789"), // Should not be reached. |
| 2865 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2866 | }; |
| 2867 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2868 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2869 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2870 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2872 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2874 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2876 | |
| 2877 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2878 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2879 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2881 | ASSERT_TRUE(response); |
| 2882 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2883 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2884 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2885 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2886 | |
| 2887 | std::string response_data; |
| 2888 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2889 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2890 | |
| 2891 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2892 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2893 | } |
| 2894 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2895 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 2896 | // caller when the proxy responds to CONNECT with 407. |
| 2897 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 2898 | HttpRequestInfo request; |
| 2899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2900 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2901 | request.load_flags = 0; |
| 2902 | |
| 2903 | // Configure against proxy server "myproxy:70". |
| 2904 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2905 | |
| 2906 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2907 | |
| 2908 | scoped_ptr<HttpTransaction> trans( |
| 2909 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2910 | |
| 2911 | // Since we have proxy, should try to establish tunnel. |
| 2912 | MockWrite data_writes[] = { |
| 2913 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2914 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2915 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2916 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2917 | }; |
| 2918 | |
| 2919 | // The proxy responds to the connect with a 407. |
| 2920 | MockRead data_reads[] = { |
| 2921 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2922 | MockRead("X-Foo: bar\r\n"), |
| 2923 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 2924 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2925 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2926 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2927 | }; |
| 2928 | |
| 2929 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2930 | arraysize(data_writes)); |
| 2931 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2932 | |
| 2933 | TestCompletionCallback callback; |
| 2934 | |
| 2935 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2937 | |
| 2938 | rv = callback.WaitForResult(); |
| 2939 | EXPECT_EQ(OK, rv); |
| 2940 | |
| 2941 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2942 | ASSERT_TRUE(response); |
| 2943 | ASSERT_TRUE(response->headers); |
| 2944 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2945 | EXPECT_EQ(407, response->headers->response_code()); |
| 2946 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2947 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 2948 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 2949 | |
| 2950 | std::string response_data; |
| 2951 | rv = ReadTransaction(trans.get(), &response_data); |
| 2952 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 2953 | |
| 2954 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 2955 | session->CloseAllConnections(); |
| 2956 | } |
| 2957 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2958 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2959 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2960 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2961 | HttpRequestInfo request; |
| 2962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2964 | request.load_flags = 0; |
| 2965 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2966 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2967 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2968 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2969 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2970 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2971 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2972 | MockWrite( |
| 2973 | "GET / HTTP/1.1\r\n" |
| 2974 | "Host: www.example.org\r\n" |
| 2975 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2976 | }; |
| 2977 | |
| 2978 | MockRead data_reads1[] = { |
| 2979 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2980 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2981 | // Large content-length -- won't matter, as connection will be reset. |
| 2982 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2983 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2984 | }; |
| 2985 | |
| 2986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2987 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2990 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2992 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2994 | |
| 2995 | rv = callback.WaitForResult(); |
| 2996 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2997 | } |
| 2998 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2999 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3000 | // through a non-authenticating proxy. The request should fail with |
| 3001 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3002 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3003 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3004 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3005 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3006 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3007 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3008 | HttpRequestInfo request; |
| 3009 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3010 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3011 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3012 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3013 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3014 | session_deps_.net_log = log.bound().net_log(); |
| 3015 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3016 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3017 | // Since we have proxy, should try to establish tunnel. |
| 3018 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3019 | MockWrite( |
| 3020 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3021 | "Host: www.example.org\r\n" |
| 3022 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3023 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3024 | MockWrite( |
| 3025 | "GET / HTTP/1.1\r\n" |
| 3026 | "Host: www.example.org\r\n" |
| 3027 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3028 | }; |
| 3029 | |
| 3030 | MockRead data_reads1[] = { |
| 3031 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3032 | |
| 3033 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3034 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3035 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3036 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3037 | }; |
| 3038 | |
| 3039 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3040 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3041 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3042 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3045 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3046 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3047 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3050 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3051 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3052 | |
| 3053 | rv = callback1.WaitForResult(); |
| 3054 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3055 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3056 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3057 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3058 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3059 | NetLog::PHASE_NONE); |
| 3060 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3061 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3062 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3063 | NetLog::PHASE_NONE); |
| 3064 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3065 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3066 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3067 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3068 | HttpRequestInfo request1; |
| 3069 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3070 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3071 | |
| 3072 | HttpRequestInfo request2; |
| 3073 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3074 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3075 | |
| 3076 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3077 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3078 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3079 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3080 | session_deps_.net_log = log.bound().net_log(); |
| 3081 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3082 | |
| 3083 | // Since we have proxy, should try to establish tunnel. |
| 3084 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3085 | MockWrite( |
| 3086 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3087 | "Host: www.example.org\r\n" |
| 3088 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3089 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3090 | MockWrite( |
| 3091 | "GET /1 HTTP/1.1\r\n" |
| 3092 | "Host: www.example.org\r\n" |
| 3093 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3095 | MockWrite( |
| 3096 | "GET /2 HTTP/1.1\r\n" |
| 3097 | "Host: www.example.org\r\n" |
| 3098 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3099 | }; |
| 3100 | |
| 3101 | // The proxy responds to the connect with a 407, using a persistent |
| 3102 | // connection. |
| 3103 | MockRead data_reads1[] = { |
| 3104 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3105 | |
| 3106 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3107 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3108 | MockRead(SYNCHRONOUS, "1"), |
| 3109 | |
| 3110 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3111 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3112 | MockRead(SYNCHRONOUS, "22"), |
| 3113 | }; |
| 3114 | |
| 3115 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3116 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3117 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3118 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3119 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3120 | |
| 3121 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3122 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3124 | |
| 3125 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3126 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3127 | |
| 3128 | rv = callback1.WaitForResult(); |
| 3129 | EXPECT_EQ(OK, rv); |
| 3130 | |
| 3131 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3132 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3133 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3134 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3135 | |
| 3136 | LoadTimingInfo load_timing_info1; |
| 3137 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3138 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3139 | |
| 3140 | trans1.reset(); |
| 3141 | |
| 3142 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3143 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3144 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3145 | |
| 3146 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3147 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3148 | |
| 3149 | rv = callback2.WaitForResult(); |
| 3150 | EXPECT_EQ(OK, rv); |
| 3151 | |
| 3152 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3153 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3154 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3155 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3156 | |
| 3157 | LoadTimingInfo load_timing_info2; |
| 3158 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3159 | TestLoadTimingReused(load_timing_info2); |
| 3160 | |
| 3161 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3162 | |
| 3163 | trans2.reset(); |
| 3164 | session->CloseAllConnections(); |
| 3165 | } |
| 3166 | |
| 3167 | // 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] | 3168 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3169 | HttpRequestInfo request1; |
| 3170 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3171 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3172 | |
| 3173 | HttpRequestInfo request2; |
| 3174 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3175 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3176 | |
| 3177 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3178 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3179 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3180 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3181 | session_deps_.net_log = log.bound().net_log(); |
| 3182 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3183 | |
| 3184 | // Since we have proxy, should try to establish tunnel. |
| 3185 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3186 | MockWrite( |
| 3187 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3188 | "Host: www.example.org\r\n" |
| 3189 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3190 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3191 | MockWrite( |
| 3192 | "GET /1 HTTP/1.1\r\n" |
| 3193 | "Host: www.example.org\r\n" |
| 3194 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3195 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3196 | MockWrite( |
| 3197 | "GET /2 HTTP/1.1\r\n" |
| 3198 | "Host: www.example.org\r\n" |
| 3199 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3200 | }; |
| 3201 | |
| 3202 | // The proxy responds to the connect with a 407, using a persistent |
| 3203 | // connection. |
| 3204 | MockRead data_reads1[] = { |
| 3205 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3206 | |
| 3207 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3208 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3209 | MockRead(SYNCHRONOUS, "1"), |
| 3210 | |
| 3211 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3212 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3213 | MockRead(SYNCHRONOUS, "22"), |
| 3214 | }; |
| 3215 | |
| 3216 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3217 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3218 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3219 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3221 | |
| 3222 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3223 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3225 | |
| 3226 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3227 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3228 | |
| 3229 | rv = callback1.WaitForResult(); |
| 3230 | EXPECT_EQ(OK, rv); |
| 3231 | |
| 3232 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3233 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3234 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3235 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3236 | |
| 3237 | LoadTimingInfo load_timing_info1; |
| 3238 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3239 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3240 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3241 | |
| 3242 | trans1.reset(); |
| 3243 | |
| 3244 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3245 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3247 | |
| 3248 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3250 | |
| 3251 | rv = callback2.WaitForResult(); |
| 3252 | EXPECT_EQ(OK, rv); |
| 3253 | |
| 3254 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3255 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3256 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3257 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3258 | |
| 3259 | LoadTimingInfo load_timing_info2; |
| 3260 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3261 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3262 | |
| 3263 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3264 | |
| 3265 | trans2.reset(); |
| 3266 | session->CloseAllConnections(); |
| 3267 | } |
| 3268 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3269 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3270 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3271 | HttpRequestInfo request; |
| 3272 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3273 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3274 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3275 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3276 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3277 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3278 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3279 | session_deps_.net_log = log.bound().net_log(); |
| 3280 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3281 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3282 | // Since we have proxy, should use full url |
| 3283 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3284 | MockWrite( |
| 3285 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3286 | "Host: www.example.org\r\n" |
| 3287 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3288 | }; |
| 3289 | |
| 3290 | MockRead data_reads1[] = { |
| 3291 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3292 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3293 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3294 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3295 | }; |
| 3296 | |
| 3297 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3298 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3299 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3300 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3303 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3304 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3305 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3306 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3308 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3309 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3310 | |
| 3311 | rv = callback1.WaitForResult(); |
| 3312 | EXPECT_EQ(OK, rv); |
| 3313 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3314 | LoadTimingInfo load_timing_info; |
| 3315 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3316 | TestLoadTimingNotReused(load_timing_info, |
| 3317 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3318 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3319 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3320 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3321 | |
| 3322 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3323 | EXPECT_EQ(200, response->headers->response_code()); |
| 3324 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3325 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3326 | |
| 3327 | // The password prompt info should not be set. |
| 3328 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3329 | } |
| 3330 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3331 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3332 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3333 | HttpRequestInfo request; |
| 3334 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3335 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3336 | request.load_flags = 0; |
| 3337 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3338 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3339 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3340 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3341 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3342 | session_deps_.net_log = log.bound().net_log(); |
| 3343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3344 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3345 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3346 | scoped_ptr<SpdyFrame> req( |
| 3347 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3348 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3349 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3350 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3351 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3352 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3353 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3354 | }; |
| 3355 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3356 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3357 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3358 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3359 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3360 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3361 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3364 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3365 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3366 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3367 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3369 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3371 | |
| 3372 | rv = callback1.WaitForResult(); |
| 3373 | EXPECT_EQ(OK, rv); |
| 3374 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3375 | LoadTimingInfo load_timing_info; |
| 3376 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3377 | TestLoadTimingNotReused(load_timing_info, |
| 3378 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3379 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3380 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3381 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3382 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3383 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3384 | |
| 3385 | std::string response_data; |
| 3386 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3387 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3388 | } |
| 3389 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3390 | // Verifies that a session which races and wins against the owning transaction |
| 3391 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3392 | // Regression test for crbug.com/334413. |
| 3393 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3394 | HttpRequestInfo request; |
| 3395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3396 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3397 | request.load_flags = 0; |
| 3398 | |
| 3399 | // Configure SPDY proxy server "proxy:70". |
| 3400 | session_deps_.proxy_service.reset( |
| 3401 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3402 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3403 | session_deps_.net_log = log.bound().net_log(); |
| 3404 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3405 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3406 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3407 | scoped_ptr<SpdyFrame> req( |
| 3408 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3409 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3410 | |
| 3411 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3412 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3413 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3414 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3415 | }; |
| 3416 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3417 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3418 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3419 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3420 | |
| 3421 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3422 | ssl.SetNextProto(GetParam()); |
| 3423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3424 | |
| 3425 | TestCompletionCallback callback1; |
| 3426 | |
| 3427 | scoped_ptr<HttpTransaction> trans( |
| 3428 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3429 | |
| 3430 | // Stall the hostname resolution begun by the transaction. |
| 3431 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3432 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3433 | |
| 3434 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3436 | |
| 3437 | // Race a session to the proxy, which completes first. |
| 3438 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3439 | SpdySessionKey key( |
| 3440 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3441 | base::WeakPtr<SpdySession> spdy_session = |
| 3442 | CreateSecureSpdySession(session, key, log.bound()); |
| 3443 | |
| 3444 | // Unstall the resolution begun by the transaction. |
| 3445 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3446 | session_deps_.host_resolver->ResolveAllPending(); |
| 3447 | |
| 3448 | EXPECT_FALSE(callback1.have_result()); |
| 3449 | rv = callback1.WaitForResult(); |
| 3450 | EXPECT_EQ(OK, rv); |
| 3451 | |
| 3452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3453 | ASSERT_TRUE(response != NULL); |
| 3454 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3455 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3456 | |
| 3457 | std::string response_data; |
| 3458 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3459 | EXPECT_EQ(kUploadData, response_data); |
| 3460 | } |
| 3461 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3462 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3463 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3464 | HttpRequestInfo request; |
| 3465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3466 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3467 | request.load_flags = 0; |
| 3468 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3469 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3470 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3471 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3472 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3473 | session_deps_.net_log = log.bound().net_log(); |
| 3474 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3475 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3476 | // The first request will be a bare GET, the second request will be a |
| 3477 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3478 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3479 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3480 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3481 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3482 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3483 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3484 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3485 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3486 | false, |
| 3487 | 3, |
| 3488 | LOWEST, |
| 3489 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3490 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3491 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3492 | }; |
| 3493 | |
| 3494 | // The first response is a 407 proxy authentication challenge, and the second |
| 3495 | // response will be a 200 response since the second request includes a valid |
| 3496 | // Authorization header. |
| 3497 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3498 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3499 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3500 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3501 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3502 | "407 Proxy Authentication Required", |
| 3503 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3504 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3505 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3506 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3507 | scoped_ptr<SpdyFrame> resp_data( |
| 3508 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3509 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3510 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3511 | CreateMockRead(*resp_authentication, 1), |
| 3512 | CreateMockRead(*body_authentication, 2), |
| 3513 | CreateMockRead(*resp_data, 4), |
| 3514 | CreateMockRead(*body_data, 5), |
| 3515 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3516 | }; |
| 3517 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3518 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3519 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3520 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3521 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3522 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3523 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3526 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3527 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3528 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3529 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3531 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3532 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3533 | |
| 3534 | rv = callback1.WaitForResult(); |
| 3535 | EXPECT_EQ(OK, rv); |
| 3536 | |
| 3537 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3538 | |
| 3539 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3540 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3541 | EXPECT_EQ(407, response->headers->response_code()); |
| 3542 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3543 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3544 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3545 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3547 | rv = trans->RestartWithAuth( |
| 3548 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3549 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3550 | |
| 3551 | rv = callback2.WaitForResult(); |
| 3552 | EXPECT_EQ(OK, rv); |
| 3553 | |
| 3554 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3555 | |
| 3556 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3557 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3558 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3559 | // The password prompt info should not be set. |
| 3560 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3561 | } |
| 3562 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3563 | // 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] | 3564 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3565 | HttpRequestInfo request; |
| 3566 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3567 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3568 | request.load_flags = 0; |
| 3569 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3570 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3571 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3572 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3573 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3574 | session_deps_.net_log = log.bound().net_log(); |
| 3575 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3576 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3577 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3578 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3579 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3580 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3581 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3582 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3583 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3584 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3585 | const char get[] = |
| 3586 | "GET / HTTP/1.1\r\n" |
| 3587 | "Host: www.example.org\r\n" |
| 3588 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3589 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3590 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3591 | scoped_ptr<SpdyFrame> conn_resp( |
| 3592 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3593 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3594 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3595 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3596 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3597 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3598 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3599 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3600 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3601 | |
| 3602 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3603 | CreateMockWrite(*connect, 0), |
| 3604 | CreateMockWrite(*wrapped_get, 2), |
| 3605 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3606 | }; |
| 3607 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3608 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3609 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3610 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3611 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3612 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3613 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3614 | }; |
| 3615 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3616 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3617 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3618 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3619 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3620 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3621 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3623 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3624 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3626 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3628 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3629 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3630 | |
| 3631 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3632 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3633 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3634 | LoadTimingInfo load_timing_info; |
| 3635 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3636 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3637 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3638 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3639 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3640 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3641 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3642 | |
| 3643 | std::string response_data; |
| 3644 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3645 | EXPECT_EQ("1234567890", response_data); |
| 3646 | } |
| 3647 | |
| 3648 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3649 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3650 | HttpRequestInfo request; |
| 3651 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3652 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3653 | request.load_flags = 0; |
| 3654 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3655 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3656 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3657 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3658 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3659 | session_deps_.net_log = log.bound().net_log(); |
| 3660 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3661 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3662 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3663 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3664 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3665 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3666 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3667 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3668 | // fetch https://www.example.org/ via SPDY |
| 3669 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3670 | scoped_ptr<SpdyFrame> get( |
| 3671 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3672 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3673 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3674 | scoped_ptr<SpdyFrame> conn_resp( |
| 3675 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3676 | scoped_ptr<SpdyFrame> get_resp( |
| 3677 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3678 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3679 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3680 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3681 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3682 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3683 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3684 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3685 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3686 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3687 | |
| 3688 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3689 | CreateMockWrite(*connect, 0), |
| 3690 | CreateMockWrite(*wrapped_get, 2), |
| 3691 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3692 | CreateMockWrite(*window_update_body, 7), |
| 3693 | }; |
| 3694 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3695 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3696 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3697 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3698 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3699 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3700 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3701 | }; |
| 3702 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3703 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3704 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3705 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3706 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3707 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3708 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3710 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3711 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3714 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3716 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3718 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3719 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3720 | base::MessageLoop::current()->RunUntilIdle(); |
| 3721 | // Now allow the read of the response to complete. |
| 3722 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3723 | rv = callback1.WaitForResult(); |
| 3724 | EXPECT_EQ(OK, rv); |
| 3725 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3726 | LoadTimingInfo load_timing_info; |
| 3727 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3728 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3729 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3730 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3731 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3732 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3733 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3734 | |
| 3735 | std::string response_data; |
| 3736 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3737 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3741 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3742 | HttpRequestInfo request; |
| 3743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3744 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3745 | request.load_flags = 0; |
| 3746 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3747 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3748 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3749 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3750 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3751 | session_deps_.net_log = log.bound().net_log(); |
| 3752 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3753 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3754 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3756 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3757 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3758 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3759 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3760 | scoped_ptr<SpdyFrame> get( |
| 3761 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3762 | |
| 3763 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3764 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3765 | }; |
| 3766 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3767 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3768 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3769 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3770 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3771 | }; |
| 3772 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3773 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3774 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3775 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3776 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3777 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3778 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3780 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3781 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3784 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3786 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3787 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3788 | |
| 3789 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3790 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3791 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3792 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3793 | } |
| 3794 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3795 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3796 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3797 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3798 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3799 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3800 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3801 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3802 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3803 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3804 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3805 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3806 | |
| 3807 | HttpRequestInfo request1; |
| 3808 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3809 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3810 | request1.load_flags = 0; |
| 3811 | |
| 3812 | HttpRequestInfo request2; |
| 3813 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3814 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3815 | request2.load_flags = 0; |
| 3816 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3817 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3818 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3819 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3820 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3821 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3822 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3823 | // Fetch https://www.example.org/ via HTTP. |
| 3824 | const char get1[] = |
| 3825 | "GET / HTTP/1.1\r\n" |
| 3826 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3827 | "Connection: keep-alive\r\n\r\n"; |
| 3828 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3829 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3830 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3831 | "Content-Length: 1\r\n\r\n"; |
| 3832 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3833 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3834 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3835 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3836 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3837 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3838 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3839 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3840 | SpdyHeaderBlock connect2_block; |
| 3841 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3842 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
| 3843 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3844 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3845 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3846 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3847 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3848 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3849 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3850 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3851 | // Fetch https://mail.example.org/ via HTTP. |
| 3852 | const char get2[] = |
| 3853 | "GET / HTTP/1.1\r\n" |
| 3854 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3855 | "Connection: keep-alive\r\n\r\n"; |
| 3856 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3857 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3858 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3859 | "Content-Length: 2\r\n\r\n"; |
| 3860 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3861 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3862 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3863 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3864 | |
| 3865 | MockWrite spdy_writes[] = { |
| 3866 | CreateMockWrite(*connect1, 0), |
| 3867 | CreateMockWrite(*wrapped_get1, 2), |
| 3868 | CreateMockWrite(*connect2, 5), |
| 3869 | CreateMockWrite(*wrapped_get2, 7), |
| 3870 | }; |
| 3871 | |
| 3872 | MockRead spdy_reads[] = { |
| 3873 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3874 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3875 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3876 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3877 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3878 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3879 | MockRead(ASYNC, 0, 10), |
| 3880 | }; |
| 3881 | |
| 3882 | DeterministicSocketData spdy_data( |
| 3883 | spdy_reads, arraysize(spdy_reads), |
| 3884 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3885 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3886 | |
| 3887 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3888 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3889 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3890 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3891 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3892 | SSLSocketDataProvider ssl3(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3893 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3894 | |
| 3895 | TestCompletionCallback callback; |
| 3896 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3897 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3898 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3899 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3901 | // The first connect and request, each of their responses, and the body. |
| 3902 | spdy_data.RunFor(5); |
| 3903 | |
| 3904 | rv = callback.WaitForResult(); |
| 3905 | EXPECT_EQ(OK, rv); |
| 3906 | |
| 3907 | LoadTimingInfo load_timing_info; |
| 3908 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3909 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3910 | |
| 3911 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3912 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3913 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3914 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3915 | |
| 3916 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3917 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3918 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3919 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3920 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3922 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3924 | |
| 3925 | // The second connect and request, each of their responses, and the body. |
| 3926 | spdy_data.RunFor(5); |
| 3927 | rv = callback.WaitForResult(); |
| 3928 | EXPECT_EQ(OK, rv); |
| 3929 | |
| 3930 | LoadTimingInfo load_timing_info2; |
| 3931 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3932 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3933 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3934 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3935 | |
| 3936 | // The requests should have different IDs, since they each are using their own |
| 3937 | // separate stream. |
| 3938 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3939 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3940 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3944 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3945 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3946 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3947 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3948 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3949 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3950 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3951 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3952 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3953 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3954 | |
| 3955 | HttpRequestInfo request1; |
| 3956 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3957 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3958 | request1.load_flags = 0; |
| 3959 | |
| 3960 | HttpRequestInfo request2; |
| 3961 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3962 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3963 | request2.load_flags = 0; |
| 3964 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3965 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3966 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3967 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3968 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3969 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3970 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3971 | // Fetch https://www.example.org/ via HTTP. |
| 3972 | const char get1[] = |
| 3973 | "GET / HTTP/1.1\r\n" |
| 3974 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3975 | "Connection: keep-alive\r\n\r\n"; |
| 3976 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3977 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3978 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3979 | "Content-Length: 1\r\n\r\n"; |
| 3980 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3981 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3982 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3983 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3984 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3985 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3986 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3987 | // Fetch https://www.example.org/2 via HTTP. |
| 3988 | const char get2[] = |
| 3989 | "GET /2 HTTP/1.1\r\n" |
| 3990 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3991 | "Connection: keep-alive\r\n\r\n"; |
| 3992 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3993 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3994 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3995 | "Content-Length: 2\r\n\r\n"; |
| 3996 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3997 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3998 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3999 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4000 | |
| 4001 | MockWrite spdy_writes[] = { |
| 4002 | CreateMockWrite(*connect1, 0), |
| 4003 | CreateMockWrite(*wrapped_get1, 2), |
| 4004 | CreateMockWrite(*wrapped_get2, 5), |
| 4005 | }; |
| 4006 | |
| 4007 | MockRead spdy_reads[] = { |
| 4008 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4009 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4010 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4011 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4012 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4013 | MockRead(ASYNC, 0, 8), |
| 4014 | }; |
| 4015 | |
| 4016 | DeterministicSocketData spdy_data( |
| 4017 | spdy_reads, arraysize(spdy_reads), |
| 4018 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4019 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4020 | |
| 4021 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4022 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4023 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4024 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4025 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4026 | |
| 4027 | TestCompletionCallback callback; |
| 4028 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4029 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4030 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4031 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4033 | // The first connect and request, each of their responses, and the body. |
| 4034 | spdy_data.RunFor(5); |
| 4035 | |
| 4036 | rv = callback.WaitForResult(); |
| 4037 | EXPECT_EQ(OK, rv); |
| 4038 | |
| 4039 | LoadTimingInfo load_timing_info; |
| 4040 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4041 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4042 | |
| 4043 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4044 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4045 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4046 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4047 | |
| 4048 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4049 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4050 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4051 | trans.reset(); |
| 4052 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4053 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4054 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4055 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4056 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4057 | |
| 4058 | // The second request, response, and body. There should not be a second |
| 4059 | // connect. |
| 4060 | spdy_data.RunFor(3); |
| 4061 | rv = callback.WaitForResult(); |
| 4062 | EXPECT_EQ(OK, rv); |
| 4063 | |
| 4064 | LoadTimingInfo load_timing_info2; |
| 4065 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4066 | TestLoadTimingReused(load_timing_info2); |
| 4067 | |
| 4068 | // The requests should have the same ID. |
| 4069 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4070 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4071 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4075 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4076 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4077 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 4078 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4079 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4080 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4081 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4082 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4083 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4084 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4085 | |
| 4086 | HttpRequestInfo request1; |
| 4087 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4088 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4089 | request1.load_flags = 0; |
| 4090 | |
| 4091 | HttpRequestInfo request2; |
| 4092 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4093 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4094 | request2.load_flags = 0; |
| 4095 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4096 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4097 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4098 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4099 | scoped_ptr<SpdyFrame> get1( |
| 4100 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4101 | scoped_ptr<SpdyFrame> get_resp1( |
| 4102 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4103 | scoped_ptr<SpdyFrame> body1( |
| 4104 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4105 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4106 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4107 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4108 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4109 | scoped_ptr<SpdyFrame> get2( |
| 4110 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4111 | scoped_ptr<SpdyFrame> get_resp2( |
| 4112 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4113 | scoped_ptr<SpdyFrame> body2( |
| 4114 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4115 | |
| 4116 | MockWrite spdy_writes[] = { |
| 4117 | CreateMockWrite(*get1, 0), |
| 4118 | CreateMockWrite(*get2, 3), |
| 4119 | }; |
| 4120 | |
| 4121 | MockRead spdy_reads[] = { |
| 4122 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4123 | CreateMockRead(*body1, 2, ASYNC), |
| 4124 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4125 | CreateMockRead(*body2, 5, ASYNC), |
| 4126 | MockRead(ASYNC, 0, 6), |
| 4127 | }; |
| 4128 | |
| 4129 | DeterministicSocketData spdy_data( |
| 4130 | spdy_reads, arraysize(spdy_reads), |
| 4131 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4132 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4133 | |
| 4134 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4135 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4136 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4137 | |
| 4138 | TestCompletionCallback callback; |
| 4139 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4140 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4141 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4142 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4144 | spdy_data.RunFor(2); |
| 4145 | |
| 4146 | rv = callback.WaitForResult(); |
| 4147 | EXPECT_EQ(OK, rv); |
| 4148 | |
| 4149 | LoadTimingInfo load_timing_info; |
| 4150 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4151 | TestLoadTimingNotReused(load_timing_info, |
| 4152 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4153 | |
| 4154 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4155 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4156 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4157 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4158 | |
| 4159 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4160 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4161 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4162 | spdy_data.RunFor(1); |
| 4163 | EXPECT_EQ(1, callback.WaitForResult()); |
| 4164 | // Delete the first request, so the second one can reuse the socket. |
| 4165 | trans.reset(); |
| 4166 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4167 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4169 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4171 | |
| 4172 | spdy_data.RunFor(2); |
| 4173 | rv = callback.WaitForResult(); |
| 4174 | EXPECT_EQ(OK, rv); |
| 4175 | |
| 4176 | LoadTimingInfo load_timing_info2; |
| 4177 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4178 | TestLoadTimingReused(load_timing_info2); |
| 4179 | |
| 4180 | // The requests should have the same ID. |
| 4181 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4182 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4183 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4184 | spdy_data.RunFor(1); |
| 4185 | EXPECT_EQ(2, callback.WaitForResult()); |
| 4186 | } |
| 4187 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4188 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4189 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4190 | HttpRequestInfo request; |
| 4191 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4192 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4193 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4194 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4195 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4196 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4197 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4198 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4199 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4200 | session_deps_.net_log = log.bound().net_log(); |
| 4201 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4202 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4203 | // Since we have proxy, should use full url |
| 4204 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4205 | MockWrite( |
| 4206 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4207 | "Host: www.example.org\r\n" |
| 4208 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4209 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4210 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4211 | // be issuing -- the final header line contains the credentials. |
| 4212 | MockWrite( |
| 4213 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4214 | "Host: www.example.org\r\n" |
| 4215 | "Proxy-Connection: keep-alive\r\n" |
| 4216 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4217 | }; |
| 4218 | |
| 4219 | // The proxy responds to the GET with a 407, using a persistent |
| 4220 | // connection. |
| 4221 | MockRead data_reads1[] = { |
| 4222 | // No credentials. |
| 4223 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4224 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4225 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4226 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4227 | |
| 4228 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4229 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4230 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4231 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4232 | }; |
| 4233 | |
| 4234 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4235 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4236 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4237 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4240 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4241 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4242 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4243 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4245 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4246 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4247 | |
| 4248 | rv = callback1.WaitForResult(); |
| 4249 | EXPECT_EQ(OK, rv); |
| 4250 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4251 | LoadTimingInfo load_timing_info; |
| 4252 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4253 | TestLoadTimingNotReused(load_timing_info, |
| 4254 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4255 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4257 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4258 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4259 | EXPECT_EQ(407, response->headers->response_code()); |
| 4260 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4261 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4263 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4265 | rv = trans->RestartWithAuth( |
| 4266 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4268 | |
| 4269 | rv = callback2.WaitForResult(); |
| 4270 | EXPECT_EQ(OK, rv); |
| 4271 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4272 | load_timing_info = LoadTimingInfo(); |
| 4273 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4274 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4275 | TestLoadTimingReused(load_timing_info); |
| 4276 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4277 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4278 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4279 | |
| 4280 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4281 | EXPECT_EQ(200, response->headers->response_code()); |
| 4282 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4283 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4284 | |
| 4285 | // The password prompt info should not be set. |
| 4286 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4287 | } |
| 4288 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4289 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4290 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4291 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4293 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4294 | request.load_flags = 0; |
| 4295 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4296 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4297 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4298 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4299 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4300 | // Since we have proxy, should try to establish tunnel. |
| 4301 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4302 | MockWrite( |
| 4303 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4304 | "Host: www.example.org\r\n" |
| 4305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4306 | }; |
| 4307 | |
| 4308 | MockRead data_reads[] = { |
| 4309 | status, |
| 4310 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4311 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4312 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4313 | }; |
| 4314 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4315 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4316 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4319 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4320 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4321 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4322 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4323 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4324 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4325 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4326 | |
| 4327 | rv = callback.WaitForResult(); |
| 4328 | EXPECT_EQ(expected_status, rv); |
| 4329 | } |
| 4330 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4331 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4332 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4333 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4334 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4335 | } |
| 4336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4337 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4338 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4339 | } |
| 4340 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4341 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4342 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4343 | } |
| 4344 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4345 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4346 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4347 | } |
| 4348 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4349 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4350 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4351 | } |
| 4352 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4353 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4354 | ConnectStatusHelper( |
| 4355 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4356 | } |
| 4357 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4358 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4359 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4360 | } |
| 4361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4362 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4363 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4364 | } |
| 4365 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4366 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4367 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4368 | } |
| 4369 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4370 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4371 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4372 | } |
| 4373 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4374 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4375 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4376 | } |
| 4377 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4378 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4379 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4380 | } |
| 4381 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4382 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4383 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4384 | } |
| 4385 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4386 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4387 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4388 | } |
| 4389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4390 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4391 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4392 | } |
| 4393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4394 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4395 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4396 | } |
| 4397 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4398 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4399 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4400 | } |
| 4401 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4402 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4403 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4404 | } |
| 4405 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4406 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4407 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4408 | } |
| 4409 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4410 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4411 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4412 | } |
| 4413 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4414 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4415 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4416 | } |
| 4417 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4418 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4419 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4420 | } |
| 4421 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4422 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4423 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4424 | } |
| 4425 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4426 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4427 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4428 | } |
| 4429 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4430 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4431 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4432 | } |
| 4433 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4434 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4435 | ConnectStatusHelperWithExpectedStatus( |
| 4436 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4437 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4438 | } |
| 4439 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4440 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4441 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4442 | } |
| 4443 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4444 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4445 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4446 | } |
| 4447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4448 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4449 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4450 | } |
| 4451 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4452 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4453 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4454 | } |
| 4455 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4456 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4457 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4458 | } |
| 4459 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4460 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4461 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4462 | } |
| 4463 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4464 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4465 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4466 | } |
| 4467 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4468 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4469 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4470 | } |
| 4471 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4472 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4473 | ConnectStatusHelper( |
| 4474 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4475 | } |
| 4476 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4477 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4478 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4479 | } |
| 4480 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4481 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4482 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4483 | } |
| 4484 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4485 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4486 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4487 | } |
| 4488 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4489 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4490 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4491 | } |
| 4492 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4493 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4494 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4495 | } |
| 4496 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4497 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4498 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4499 | } |
| 4500 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4501 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4502 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4503 | } |
| 4504 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4505 | // Test the flow when both the proxy server AND origin server require |
| 4506 | // authentication. Again, this uses basic auth for both since that is |
| 4507 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4508 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4509 | HttpRequestInfo request; |
| 4510 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4511 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4512 | request.load_flags = 0; |
| 4513 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4514 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4515 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4516 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4517 | |
| 4518 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4519 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4520 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4521 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4522 | MockWrite( |
| 4523 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4524 | "Host: www.example.org\r\n" |
| 4525 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4526 | }; |
| 4527 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4528 | MockRead data_reads1[] = { |
| 4529 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4530 | // Give a couple authenticate options (only the middle one is actually |
| 4531 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4532 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4533 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4534 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4535 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4536 | // Large content-length -- won't matter, as connection will be reset. |
| 4537 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4538 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4539 | }; |
| 4540 | |
| 4541 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4542 | // request we should be issuing -- the final header line contains the |
| 4543 | // proxy's credentials. |
| 4544 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4545 | MockWrite( |
| 4546 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4547 | "Host: www.example.org\r\n" |
| 4548 | "Proxy-Connection: keep-alive\r\n" |
| 4549 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4550 | }; |
| 4551 | |
| 4552 | // Now the proxy server lets the request pass through to origin server. |
| 4553 | // The origin server responds with a 401. |
| 4554 | MockRead data_reads2[] = { |
| 4555 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4556 | // Note: We are using the same realm-name as the proxy server. This is |
| 4557 | // completely valid, as realms are unique across hosts. |
| 4558 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4559 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4560 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4561 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4562 | }; |
| 4563 | |
| 4564 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4565 | // the credentials for both the proxy and origin server. |
| 4566 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4567 | MockWrite( |
| 4568 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4569 | "Host: www.example.org\r\n" |
| 4570 | "Proxy-Connection: keep-alive\r\n" |
| 4571 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4572 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4573 | }; |
| 4574 | |
| 4575 | // Lastly we get the desired content. |
| 4576 | MockRead data_reads3[] = { |
| 4577 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4578 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4579 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4580 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4581 | }; |
| 4582 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4583 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4584 | data_writes1, arraysize(data_writes1)); |
| 4585 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4586 | data_writes2, arraysize(data_writes2)); |
| 4587 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4588 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4589 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4590 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4591 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4593 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4595 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4596 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4597 | |
| 4598 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4599 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4600 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4601 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4602 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4603 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4605 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4607 | rv = trans->RestartWithAuth( |
| 4608 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4610 | |
| 4611 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4612 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4613 | |
| 4614 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4615 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4616 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4618 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4620 | rv = trans->RestartWithAuth( |
| 4621 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4622 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4623 | |
| 4624 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4625 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4626 | |
| 4627 | response = trans->GetResponseInfo(); |
| 4628 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4629 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4630 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4631 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4632 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4633 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4634 | // authorization headers. |
| 4635 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4636 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4637 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4638 | // bytes in the debugger. |
| 4639 | |
| 4640 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4641 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4642 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4643 | request.method = "GET"; |
| 4644 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4645 | |
| 4646 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4647 | // to other auth schemes. |
| 4648 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4649 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4650 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4651 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4652 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4653 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4654 | MockWrite data_writes1[] = { |
| 4655 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4656 | "Host: 172.22.68.17\r\n" |
| 4657 | "Connection: keep-alive\r\n\r\n"), |
| 4658 | }; |
| 4659 | |
| 4660 | MockRead data_reads1[] = { |
| 4661 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4662 | // Negotiate and NTLM are often requested together. However, we only want |
| 4663 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4664 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4665 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4666 | MockRead("Connection: close\r\n"), |
| 4667 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4668 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4669 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4670 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4671 | }; |
| 4672 | |
| 4673 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4674 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4675 | // request we should be issuing -- the final header line contains a Type |
| 4676 | // 1 message. |
| 4677 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4678 | "Host: 172.22.68.17\r\n" |
| 4679 | "Connection: keep-alive\r\n" |
| 4680 | "Authorization: NTLM " |
| 4681 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4682 | |
| 4683 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4684 | // (the credentials for the origin server). The second request continues |
| 4685 | // on the same connection. |
| 4686 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4687 | "Host: 172.22.68.17\r\n" |
| 4688 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4689 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4690 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4691 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4692 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4693 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4694 | }; |
| 4695 | |
| 4696 | MockRead data_reads2[] = { |
| 4697 | // The origin server responds with a Type 2 message. |
| 4698 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4699 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4700 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4701 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4702 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4703 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4704 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4705 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4706 | "BtAAAAAAA=\r\n"), |
| 4707 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4708 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4709 | MockRead("You are not authorized to view this page\r\n"), |
| 4710 | |
| 4711 | // Lastly we get the desired content. |
| 4712 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4713 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4714 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4715 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4717 | }; |
| 4718 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4719 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4720 | data_writes1, arraysize(data_writes1)); |
| 4721 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4722 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4723 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4724 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4726 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4727 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4731 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4733 | |
| 4734 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4735 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4736 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4737 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4738 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4739 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4740 | ASSERT_FALSE(response == NULL); |
| 4741 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4742 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4743 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4744 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4745 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4746 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4747 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4748 | |
| 4749 | rv = callback2.WaitForResult(); |
| 4750 | EXPECT_EQ(OK, rv); |
| 4751 | |
| 4752 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4753 | |
| 4754 | response = trans->GetResponseInfo(); |
| 4755 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4756 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4758 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4760 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4762 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4763 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4764 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4765 | |
| 4766 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4767 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4768 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4769 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4770 | } |
| 4771 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4772 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4773 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4774 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4775 | request.method = "GET"; |
| 4776 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4777 | request.load_flags = 0; |
| 4778 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4779 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4780 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4781 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4782 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4783 | MockWrite data_writes1[] = { |
| 4784 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4785 | "Host: 172.22.68.17\r\n" |
| 4786 | "Connection: keep-alive\r\n\r\n"), |
| 4787 | }; |
| 4788 | |
| 4789 | MockRead data_reads1[] = { |
| 4790 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4791 | // Negotiate and NTLM are often requested together. However, we only want |
| 4792 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4793 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4794 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4795 | MockRead("Connection: close\r\n"), |
| 4796 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4797 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4798 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4799 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4800 | }; |
| 4801 | |
| 4802 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4803 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4804 | // request we should be issuing -- the final header line contains a Type |
| 4805 | // 1 message. |
| 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" |
| 4809 | "Authorization: NTLM " |
| 4810 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4811 | |
| 4812 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4813 | // (the credentials for the origin server). The second request continues |
| 4814 | // on the same connection. |
| 4815 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4816 | "Host: 172.22.68.17\r\n" |
| 4817 | "Connection: keep-alive\r\n" |
| 4818 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4819 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4820 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4821 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4822 | "4Ww7b7E=\r\n\r\n"), |
| 4823 | }; |
| 4824 | |
| 4825 | MockRead data_reads2[] = { |
| 4826 | // The origin server responds with a Type 2 message. |
| 4827 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4828 | MockRead("WWW-Authenticate: NTLM " |
| 4829 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4830 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4831 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4832 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4833 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4834 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4835 | "BtAAAAAAA=\r\n"), |
| 4836 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4837 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4838 | MockRead("You are not authorized to view this page\r\n"), |
| 4839 | |
| 4840 | // Wrong password. |
| 4841 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4842 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4843 | MockRead("Connection: close\r\n"), |
| 4844 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4845 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4846 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4847 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4848 | }; |
| 4849 | |
| 4850 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4851 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4852 | // request we should be issuing -- the final header line contains a Type |
| 4853 | // 1 message. |
| 4854 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4855 | "Host: 172.22.68.17\r\n" |
| 4856 | "Connection: keep-alive\r\n" |
| 4857 | "Authorization: NTLM " |
| 4858 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4859 | |
| 4860 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4861 | // (the credentials for the origin server). The second request continues |
| 4862 | // on the same connection. |
| 4863 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4864 | "Host: 172.22.68.17\r\n" |
| 4865 | "Connection: keep-alive\r\n" |
| 4866 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4867 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4868 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4869 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4870 | "+4MUm7c=\r\n\r\n"), |
| 4871 | }; |
| 4872 | |
| 4873 | MockRead data_reads3[] = { |
| 4874 | // The origin server responds with a Type 2 message. |
| 4875 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4876 | MockRead("WWW-Authenticate: NTLM " |
| 4877 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4878 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4879 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4880 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4881 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4882 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4883 | "BtAAAAAAA=\r\n"), |
| 4884 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4885 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4886 | MockRead("You are not authorized to view this page\r\n"), |
| 4887 | |
| 4888 | // Lastly we get the desired content. |
| 4889 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4890 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4891 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4892 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4893 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4894 | }; |
| 4895 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4896 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4897 | data_writes1, arraysize(data_writes1)); |
| 4898 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4899 | data_writes2, arraysize(data_writes2)); |
| 4900 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4901 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4902 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4903 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4904 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4906 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4907 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4908 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4909 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4911 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4912 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4913 | |
| 4914 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4915 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4916 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4917 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4918 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4919 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4920 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4921 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4923 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4924 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4925 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4926 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4927 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4929 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4930 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4931 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4932 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4933 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4934 | TestCompletionCallback callback3; |
| 4935 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4937 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4938 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4939 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4940 | |
| 4941 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4942 | ASSERT_FALSE(response == NULL); |
| 4943 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4945 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4946 | |
| 4947 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4948 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4949 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4950 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4951 | |
| 4952 | rv = callback4.WaitForResult(); |
| 4953 | EXPECT_EQ(OK, rv); |
| 4954 | |
| 4955 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4957 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4958 | |
| 4959 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4960 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4961 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4962 | |
| 4963 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4964 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4965 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4966 | response = trans->GetResponseInfo(); |
| 4967 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4968 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4969 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4970 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4971 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4972 | // Test reading a server response which has only headers, and no body. |
| 4973 | // After some maximum number of bytes is consumed, the transaction should |
| 4974 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4975 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4976 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4978 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4979 | request.load_flags = 0; |
| 4980 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4981 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4982 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4984 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4985 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4986 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4987 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4988 | |
| 4989 | MockRead data_reads[] = { |
| 4990 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4991 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4992 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4993 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4994 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4995 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4998 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5000 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5002 | |
| 5003 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5004 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5005 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5006 | |
| 5007 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5008 | // establish tunnel. |
| 5009 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5010 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5011 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5012 | HttpRequestInfo request; |
| 5013 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5014 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5015 | request.load_flags = 0; |
| 5016 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5017 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5018 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5019 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5020 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5021 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5022 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5023 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5024 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5025 | // Since we have proxy, should try to establish tunnel. |
| 5026 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5027 | MockWrite( |
| 5028 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5029 | "Host: www.example.org\r\n" |
| 5030 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5031 | }; |
| 5032 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5033 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5034 | // connection. Usually a proxy would return 501 (not implemented), |
| 5035 | // or 200 (tunnel established). |
| 5036 | MockRead data_reads1[] = { |
| 5037 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5038 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5039 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5040 | }; |
| 5041 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5042 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5043 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5044 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5046 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5048 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5050 | |
| 5051 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5052 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5053 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5054 | // Empty the current queue. This is necessary because idle sockets are |
| 5055 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5056 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5057 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5058 | // We now check to make sure the TCPClientSocket was not added back to |
| 5059 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5060 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5061 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5062 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5063 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5064 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5065 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5066 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5067 | // 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] | 5068 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5069 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5071 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5072 | request.load_flags = 0; |
| 5073 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5074 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5075 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5076 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5078 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5079 | MockRead data_reads[] = { |
| 5080 | // A part of the response body is received with the response headers. |
| 5081 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5082 | // The rest of the response body is received in two parts. |
| 5083 | MockRead("lo"), |
| 5084 | MockRead(" world"), |
| 5085 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5086 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5087 | }; |
| 5088 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5089 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5090 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5092 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5094 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5096 | |
| 5097 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5098 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5099 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5101 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5102 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5103 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5104 | std::string status_line = response->headers->GetStatusLine(); |
| 5105 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5106 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5107 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5108 | |
| 5109 | std::string response_data; |
| 5110 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5111 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5112 | EXPECT_EQ("hello world", response_data); |
| 5113 | |
| 5114 | // Empty the current queue. This is necessary because idle sockets are |
| 5115 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5116 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5117 | |
| 5118 | // 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] | 5119 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5120 | } |
| 5121 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5122 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5123 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5124 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5125 | HttpRequestInfo request; |
| 5126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5127 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5128 | request.load_flags = 0; |
| 5129 | |
| 5130 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5131 | MockWrite( |
| 5132 | "GET / HTTP/1.1\r\n" |
| 5133 | "Host: www.example.org\r\n" |
| 5134 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5135 | }; |
| 5136 | |
| 5137 | MockRead data_reads[] = { |
| 5138 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5139 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5140 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5141 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5142 | }; |
| 5143 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5144 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5146 | |
| 5147 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5148 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5151 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5152 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5153 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5154 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5157 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5158 | |
| 5159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5160 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5161 | |
| 5162 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5163 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5164 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5165 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5166 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5167 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5168 | |
| 5169 | std::string response_data; |
| 5170 | rv = ReadTransaction(trans.get(), &response_data); |
| 5171 | EXPECT_EQ(OK, rv); |
| 5172 | EXPECT_EQ("hello world", response_data); |
| 5173 | |
| 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] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5177 | |
| 5178 | // 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] | 5179 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5183 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5184 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5185 | HttpRequestInfo request; |
| 5186 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5187 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5188 | request.load_flags = 0; |
| 5189 | |
| 5190 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5191 | MockWrite( |
| 5192 | "GET / HTTP/1.1\r\n" |
| 5193 | "Host: www.example.org\r\n" |
| 5194 | "Connection: keep-alive\r\n\r\n"), |
| 5195 | MockWrite( |
| 5196 | "GET / HTTP/1.1\r\n" |
| 5197 | "Host: www.example.org\r\n" |
| 5198 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5199 | }; |
| 5200 | |
| 5201 | MockRead data_reads[] = { |
| 5202 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5203 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5204 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5205 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5206 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5207 | }; |
| 5208 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5209 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5210 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5213 | |
| 5214 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5215 | data_writes, arraysize(data_writes)); |
| 5216 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5217 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5219 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5221 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5222 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5223 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5224 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5225 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5226 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5227 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5228 | |
| 5229 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5230 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5231 | |
| 5232 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5233 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5234 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5235 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5236 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5237 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5238 | |
| 5239 | std::string response_data; |
| 5240 | rv = ReadTransaction(trans.get(), &response_data); |
| 5241 | EXPECT_EQ(OK, rv); |
| 5242 | EXPECT_EQ("hello world", response_data); |
| 5243 | |
| 5244 | // Empty the current queue. This is necessary because idle sockets are |
| 5245 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5246 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5247 | |
| 5248 | // 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] | 5249 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5250 | |
| 5251 | // Now start the second transaction, which should reuse the previous socket. |
| 5252 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5253 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5255 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5256 | |
| 5257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5258 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5259 | |
| 5260 | response = trans->GetResponseInfo(); |
| 5261 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5262 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5263 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5264 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5265 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5266 | |
| 5267 | rv = ReadTransaction(trans.get(), &response_data); |
| 5268 | EXPECT_EQ(OK, rv); |
| 5269 | EXPECT_EQ("hello world", response_data); |
| 5270 | |
| 5271 | // Empty the current queue. This is necessary because idle sockets are |
| 5272 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5273 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5274 | |
| 5275 | // 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] | 5276 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5277 | } |
| 5278 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5279 | // Make sure that we recycle a socket after a zero-length response. |
| 5280 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5281 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5282 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5284 | request.url = GURL( |
| 5285 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5286 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5287 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5288 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5289 | request.load_flags = 0; |
| 5290 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5291 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5292 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5293 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5295 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5296 | MockRead data_reads[] = { |
| 5297 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5298 | "Content-Length: 0\r\n" |
| 5299 | "Content-Type: text/html\r\n\r\n"), |
| 5300 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5301 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5302 | }; |
| 5303 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5304 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5307 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5309 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5311 | |
| 5312 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5313 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5314 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5315 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5316 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5317 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5318 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5319 | std::string status_line = response->headers->GetStatusLine(); |
| 5320 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5321 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5322 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5323 | |
| 5324 | std::string response_data; |
| 5325 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5326 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5327 | EXPECT_EQ("", response_data); |
| 5328 | |
| 5329 | // Empty the current queue. This is necessary because idle sockets are |
| 5330 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5331 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5332 | |
| 5333 | // 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] | 5334 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5335 | } |
| 5336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5337 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5338 | ScopedVector<UploadElementReader> element_readers; |
| 5339 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5340 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5341 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5342 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5343 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5344 | // after use. |
| 5345 | request[0].method = "GET"; |
| 5346 | request[0].url = GURL("http://www.google.com/"); |
| 5347 | request[0].load_flags = 0; |
| 5348 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5349 | // transaction 1. The first attempts fails when writing the POST data. |
| 5350 | // This causes the transaction to retry with a new socket. The second |
| 5351 | // attempt succeeds. |
| 5352 | request[1].method = "POST"; |
| 5353 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5354 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5355 | request[1].load_flags = 0; |
| 5356 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5357 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5358 | |
| 5359 | // The first socket is used for transaction 1 and the first attempt of |
| 5360 | // transaction 2. |
| 5361 | |
| 5362 | // The response of transaction 1. |
| 5363 | MockRead data_reads1[] = { |
| 5364 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5365 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5366 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5367 | }; |
| 5368 | // The mock write results of transaction 1 and the first attempt of |
| 5369 | // transaction 2. |
| 5370 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5371 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5372 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5373 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5374 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5375 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5376 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5377 | |
| 5378 | // The second socket is used for the second attempt of transaction 2. |
| 5379 | |
| 5380 | // The response of transaction 2. |
| 5381 | MockRead data_reads2[] = { |
| 5382 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5383 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5385 | }; |
| 5386 | // The mock write results of the second attempt of transaction 2. |
| 5387 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5388 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5389 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5390 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5391 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5392 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5393 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5394 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5395 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5396 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5397 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5398 | "hello world", "welcome" |
| 5399 | }; |
| 5400 | |
| 5401 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5402 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5403 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5405 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5407 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5409 | |
| 5410 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5411 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5412 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5413 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5414 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5415 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5416 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5417 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5418 | |
| 5419 | std::string response_data; |
| 5420 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5421 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5422 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5423 | } |
| 5424 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5425 | |
| 5426 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5427 | // 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] | 5428 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5429 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5430 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5432 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5433 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5434 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5435 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5436 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5437 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5438 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5439 | // The password contains an escaped character -- for this test to pass it |
| 5440 | // will need to be unescaped by HttpNetworkTransaction. |
| 5441 | EXPECT_EQ("b%40r", request.url.password()); |
| 5442 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5443 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5444 | MockWrite( |
| 5445 | "GET / HTTP/1.1\r\n" |
| 5446 | "Host: www.example.org\r\n" |
| 5447 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5448 | }; |
| 5449 | |
| 5450 | MockRead data_reads1[] = { |
| 5451 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5452 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5453 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5454 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5455 | }; |
| 5456 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5457 | // After the challenge above, the transaction will be restarted using the |
| 5458 | // identity from the url (foo, b@r) to answer the challenge. |
| 5459 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5460 | MockWrite( |
| 5461 | "GET / HTTP/1.1\r\n" |
| 5462 | "Host: www.example.org\r\n" |
| 5463 | "Connection: keep-alive\r\n" |
| 5464 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5465 | }; |
| 5466 | |
| 5467 | MockRead data_reads2[] = { |
| 5468 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5469 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5470 | MockRead(SYNCHRONOUS, OK), |
| 5471 | }; |
| 5472 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5473 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5474 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5475 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5476 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5477 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5478 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5480 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5481 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5482 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5483 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5484 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5485 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5486 | |
| 5487 | TestCompletionCallback callback2; |
| 5488 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5489 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5490 | rv = callback2.WaitForResult(); |
| 5491 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5492 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5493 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5495 | ASSERT_TRUE(response != NULL); |
| 5496 | |
| 5497 | // There is no challenge info, since the identity in URL worked. |
| 5498 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5499 | |
| 5500 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5501 | |
| 5502 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5503 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5507 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5508 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5509 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5510 | HttpRequestInfo request; |
| 5511 | request.method = "GET"; |
| 5512 | // Note: the URL has a username:password in it. The password "baz" is |
| 5513 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5514 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5515 | |
| 5516 | request.load_flags = LOAD_NORMAL; |
| 5517 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5518 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5519 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5520 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5521 | |
| 5522 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5523 | MockWrite( |
| 5524 | "GET / HTTP/1.1\r\n" |
| 5525 | "Host: www.example.org\r\n" |
| 5526 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5527 | }; |
| 5528 | |
| 5529 | MockRead data_reads1[] = { |
| 5530 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5531 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5532 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5533 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5534 | }; |
| 5535 | |
| 5536 | // After the challenge above, the transaction will be restarted using the |
| 5537 | // identity from the url (foo, baz) to answer the challenge. |
| 5538 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5539 | MockWrite( |
| 5540 | "GET / HTTP/1.1\r\n" |
| 5541 | "Host: www.example.org\r\n" |
| 5542 | "Connection: keep-alive\r\n" |
| 5543 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5544 | }; |
| 5545 | |
| 5546 | MockRead data_reads2[] = { |
| 5547 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5548 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5549 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5550 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5551 | }; |
| 5552 | |
| 5553 | // After the challenge above, the transaction will be restarted using the |
| 5554 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5555 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5556 | MockWrite( |
| 5557 | "GET / HTTP/1.1\r\n" |
| 5558 | "Host: www.example.org\r\n" |
| 5559 | "Connection: keep-alive\r\n" |
| 5560 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5561 | }; |
| 5562 | |
| 5563 | MockRead data_reads3[] = { |
| 5564 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5565 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5566 | MockRead(SYNCHRONOUS, OK), |
| 5567 | }; |
| 5568 | |
| 5569 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5570 | data_writes1, arraysize(data_writes1)); |
| 5571 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5572 | data_writes2, arraysize(data_writes2)); |
| 5573 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5574 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5575 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5576 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5577 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5578 | |
| 5579 | TestCompletionCallback callback1; |
| 5580 | |
| 5581 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5582 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5583 | |
| 5584 | rv = callback1.WaitForResult(); |
| 5585 | EXPECT_EQ(OK, rv); |
| 5586 | |
| 5587 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5588 | TestCompletionCallback callback2; |
| 5589 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5591 | rv = callback2.WaitForResult(); |
| 5592 | EXPECT_EQ(OK, rv); |
| 5593 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5594 | |
| 5595 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5596 | ASSERT_TRUE(response != NULL); |
| 5597 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5598 | |
| 5599 | TestCompletionCallback callback3; |
| 5600 | rv = trans->RestartWithAuth( |
| 5601 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5603 | rv = callback3.WaitForResult(); |
| 5604 | EXPECT_EQ(OK, rv); |
| 5605 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5606 | |
| 5607 | response = trans->GetResponseInfo(); |
| 5608 | ASSERT_TRUE(response != NULL); |
| 5609 | |
| 5610 | // There is no challenge info, since the identity worked. |
| 5611 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5612 | |
| 5613 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5614 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5615 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5616 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5617 | } |
| 5618 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5619 | |
| 5620 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5621 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5622 | // from the URL should never be used. |
| 5623 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5624 | HttpRequestInfo request; |
| 5625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5626 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5627 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5628 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5629 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5630 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5631 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5632 | |
| 5633 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5634 | MockWrite( |
| 5635 | "GET / HTTP/1.1\r\n" |
| 5636 | "Host: www.example.org\r\n" |
| 5637 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5638 | }; |
| 5639 | |
| 5640 | MockRead data_reads1[] = { |
| 5641 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5642 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5643 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5644 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5645 | }; |
| 5646 | |
| 5647 | // After the challenge above, the transaction will be restarted using the |
| 5648 | // identity supplied by the user, not the one in the URL, to answer the |
| 5649 | // challenge. |
| 5650 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5651 | MockWrite( |
| 5652 | "GET / HTTP/1.1\r\n" |
| 5653 | "Host: www.example.org\r\n" |
| 5654 | "Connection: keep-alive\r\n" |
| 5655 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5656 | }; |
| 5657 | |
| 5658 | MockRead data_reads3[] = { |
| 5659 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5660 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5661 | MockRead(SYNCHRONOUS, OK), |
| 5662 | }; |
| 5663 | |
| 5664 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5665 | data_writes1, arraysize(data_writes1)); |
| 5666 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5667 | data_writes3, arraysize(data_writes3)); |
| 5668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5669 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5670 | |
| 5671 | TestCompletionCallback callback1; |
| 5672 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5673 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5674 | rv = callback1.WaitForResult(); |
| 5675 | EXPECT_EQ(OK, rv); |
| 5676 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5677 | |
| 5678 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5679 | ASSERT_TRUE(response != NULL); |
| 5680 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5681 | |
| 5682 | TestCompletionCallback callback3; |
| 5683 | rv = trans->RestartWithAuth( |
| 5684 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5686 | rv = callback3.WaitForResult(); |
| 5687 | EXPECT_EQ(OK, rv); |
| 5688 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5689 | |
| 5690 | response = trans->GetResponseInfo(); |
| 5691 | ASSERT_TRUE(response != NULL); |
| 5692 | |
| 5693 | // There is no challenge info, since the identity worked. |
| 5694 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5695 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5696 | |
| 5697 | // Empty the current queue. |
| 5698 | base::MessageLoop::current()->RunUntilIdle(); |
| 5699 | } |
| 5700 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5701 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5702 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5703 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5704 | |
| 5705 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5706 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5707 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5709 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5710 | request.load_flags = 0; |
| 5711 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5712 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5713 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5714 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5715 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5716 | MockWrite( |
| 5717 | "GET /x/y/z HTTP/1.1\r\n" |
| 5718 | "Host: www.example.org\r\n" |
| 5719 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5720 | }; |
| 5721 | |
| 5722 | MockRead data_reads1[] = { |
| 5723 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5724 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5725 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5726 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5727 | }; |
| 5728 | |
| 5729 | // Resend with authorization (username=foo, password=bar) |
| 5730 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5731 | MockWrite( |
| 5732 | "GET /x/y/z HTTP/1.1\r\n" |
| 5733 | "Host: www.example.org\r\n" |
| 5734 | "Connection: keep-alive\r\n" |
| 5735 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5736 | }; |
| 5737 | |
| 5738 | // Sever accepts the authorization. |
| 5739 | MockRead data_reads2[] = { |
| 5740 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5741 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5743 | }; |
| 5744 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5745 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5746 | data_writes1, arraysize(data_writes1)); |
| 5747 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5748 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5750 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5752 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5754 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5755 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5756 | |
| 5757 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5758 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5759 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5760 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5761 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5762 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5764 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5766 | rv = trans->RestartWithAuth( |
| 5767 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5768 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5769 | |
| 5770 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5771 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5772 | |
| 5773 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5774 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5775 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5776 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5777 | } |
| 5778 | |
| 5779 | // ------------------------------------------------------------------------ |
| 5780 | |
| 5781 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5782 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5783 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5784 | request.method = "GET"; |
| 5785 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5786 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5787 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5788 | request.load_flags = 0; |
| 5789 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5790 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5792 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5793 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5794 | MockWrite( |
| 5795 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5796 | "Host: www.example.org\r\n" |
| 5797 | "Connection: keep-alive\r\n" |
| 5798 | // Send preemptive authorization for MyRealm1 |
| 5799 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5800 | }; |
| 5801 | |
| 5802 | // The server didn't like the preemptive authorization, and |
| 5803 | // challenges us for a different realm (MyRealm2). |
| 5804 | MockRead data_reads1[] = { |
| 5805 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5806 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5807 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5808 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5809 | }; |
| 5810 | |
| 5811 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5812 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5813 | MockWrite( |
| 5814 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5815 | "Host: www.example.org\r\n" |
| 5816 | "Connection: keep-alive\r\n" |
| 5817 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5818 | }; |
| 5819 | |
| 5820 | // Sever accepts the authorization. |
| 5821 | MockRead data_reads2[] = { |
| 5822 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5823 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5825 | }; |
| 5826 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5827 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5828 | data_writes1, arraysize(data_writes1)); |
| 5829 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5830 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5831 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5832 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5834 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5836 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5838 | |
| 5839 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5840 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5841 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5843 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5844 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5845 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5846 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5847 | response->auth_challenge->challenger.ToString()); |
| 5848 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5849 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5851 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5853 | rv = trans->RestartWithAuth( |
| 5854 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5856 | |
| 5857 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5858 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5859 | |
| 5860 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5861 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5862 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5863 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5864 | } |
| 5865 | |
| 5866 | // ------------------------------------------------------------------------ |
| 5867 | |
| 5868 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5869 | // succeed with preemptive authorization. |
| 5870 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5871 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5873 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5874 | request.load_flags = 0; |
| 5875 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5876 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5878 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5879 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5880 | MockWrite( |
| 5881 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 5882 | "Host: www.example.org\r\n" |
| 5883 | "Connection: keep-alive\r\n" |
| 5884 | // The authorization for MyRealm1 gets sent preemptively |
| 5885 | // (since the url is in the same protection space) |
| 5886 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5887 | }; |
| 5888 | |
| 5889 | // Sever accepts the preemptive authorization |
| 5890 | MockRead data_reads1[] = { |
| 5891 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5892 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5893 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5894 | }; |
| 5895 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5896 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5897 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5900 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5902 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5903 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5904 | |
| 5905 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5906 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5907 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5909 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5910 | |
| 5911 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5912 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5913 | } |
| 5914 | |
| 5915 | // ------------------------------------------------------------------------ |
| 5916 | |
| 5917 | // Transaction 4: request another URL in MyRealm (however the |
| 5918 | // url is not known to belong to the protection space, so no pre-auth). |
| 5919 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5920 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5922 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5923 | request.load_flags = 0; |
| 5924 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5925 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5926 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5927 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5928 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5929 | MockWrite( |
| 5930 | "GET /x/1 HTTP/1.1\r\n" |
| 5931 | "Host: www.example.org\r\n" |
| 5932 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5933 | }; |
| 5934 | |
| 5935 | MockRead data_reads1[] = { |
| 5936 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5937 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5938 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5939 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5940 | }; |
| 5941 | |
| 5942 | // Resend with authorization from MyRealm's cache. |
| 5943 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5944 | MockWrite( |
| 5945 | "GET /x/1 HTTP/1.1\r\n" |
| 5946 | "Host: www.example.org\r\n" |
| 5947 | "Connection: keep-alive\r\n" |
| 5948 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5949 | }; |
| 5950 | |
| 5951 | // Sever accepts the authorization. |
| 5952 | MockRead data_reads2[] = { |
| 5953 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5954 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5955 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5956 | }; |
| 5957 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5958 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5959 | data_writes1, arraysize(data_writes1)); |
| 5960 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5961 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5962 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5963 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5965 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5967 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5968 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5969 | |
| 5970 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5971 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5972 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5973 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5974 | TestCompletionCallback callback2; |
| 5975 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5977 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5978 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5979 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5980 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5981 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5982 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5983 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5984 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5985 | } |
| 5986 | |
| 5987 | // ------------------------------------------------------------------------ |
| 5988 | |
| 5989 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5990 | // cached identity. Should invalidate and re-prompt. |
| 5991 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5992 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5993 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5994 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5995 | request.load_flags = 0; |
| 5996 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5997 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5998 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5999 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6000 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6001 | MockWrite( |
| 6002 | "GET /p/q/t HTTP/1.1\r\n" |
| 6003 | "Host: www.example.org\r\n" |
| 6004 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6005 | }; |
| 6006 | |
| 6007 | MockRead data_reads1[] = { |
| 6008 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6009 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6010 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6011 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6012 | }; |
| 6013 | |
| 6014 | // Resend with authorization from cache for MyRealm. |
| 6015 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6016 | MockWrite( |
| 6017 | "GET /p/q/t HTTP/1.1\r\n" |
| 6018 | "Host: www.example.org\r\n" |
| 6019 | "Connection: keep-alive\r\n" |
| 6020 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6021 | }; |
| 6022 | |
| 6023 | // Sever rejects the authorization. |
| 6024 | MockRead data_reads2[] = { |
| 6025 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6026 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6027 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6028 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6029 | }; |
| 6030 | |
| 6031 | // At this point we should prompt for new credentials for MyRealm. |
| 6032 | // Restart with username=foo3, password=foo4. |
| 6033 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6034 | MockWrite( |
| 6035 | "GET /p/q/t HTTP/1.1\r\n" |
| 6036 | "Host: www.example.org\r\n" |
| 6037 | "Connection: keep-alive\r\n" |
| 6038 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6039 | }; |
| 6040 | |
| 6041 | // Sever accepts the authorization. |
| 6042 | MockRead data_reads3[] = { |
| 6043 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6044 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6045 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6046 | }; |
| 6047 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6048 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6049 | data_writes1, arraysize(data_writes1)); |
| 6050 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6051 | data_writes2, arraysize(data_writes2)); |
| 6052 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6053 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6054 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6055 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6056 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6058 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6060 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6061 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6062 | |
| 6063 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6064 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6065 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6066 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6067 | TestCompletionCallback callback2; |
| 6068 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6070 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6071 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6072 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6073 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6075 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6076 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6078 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6080 | rv = trans->RestartWithAuth( |
| 6081 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6083 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6084 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6085 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6086 | |
| 6087 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6088 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6089 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6090 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6091 | } |
| 6092 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6093 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6094 | // Tests that nonce count increments when multiple auth attempts |
| 6095 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6096 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6097 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6098 | new HttpAuthHandlerDigest::Factory(); |
| 6099 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6100 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6101 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6102 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6103 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6104 | |
| 6105 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6106 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6107 | HttpRequestInfo request; |
| 6108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6109 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6110 | request.load_flags = 0; |
| 6111 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6112 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6114 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6115 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6116 | MockWrite( |
| 6117 | "GET /x/y/z HTTP/1.1\r\n" |
| 6118 | "Host: www.example.org\r\n" |
| 6119 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6120 | }; |
| 6121 | |
| 6122 | MockRead data_reads1[] = { |
| 6123 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6124 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6125 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6126 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6127 | }; |
| 6128 | |
| 6129 | // Resend with authorization (username=foo, password=bar) |
| 6130 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6131 | MockWrite( |
| 6132 | "GET /x/y/z HTTP/1.1\r\n" |
| 6133 | "Host: www.example.org\r\n" |
| 6134 | "Connection: keep-alive\r\n" |
| 6135 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6136 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6137 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6138 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6139 | }; |
| 6140 | |
| 6141 | // Sever accepts the authorization. |
| 6142 | MockRead data_reads2[] = { |
| 6143 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6144 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6145 | }; |
| 6146 | |
| 6147 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6148 | data_writes1, arraysize(data_writes1)); |
| 6149 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6150 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6151 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6152 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6153 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6154 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6156 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6157 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6158 | |
| 6159 | rv = callback1.WaitForResult(); |
| 6160 | EXPECT_EQ(OK, rv); |
| 6161 | |
| 6162 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6163 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6164 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6166 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6167 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6168 | rv = trans->RestartWithAuth( |
| 6169 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6171 | |
| 6172 | rv = callback2.WaitForResult(); |
| 6173 | EXPECT_EQ(OK, rv); |
| 6174 | |
| 6175 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6176 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6177 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6178 | } |
| 6179 | |
| 6180 | // ------------------------------------------------------------------------ |
| 6181 | |
| 6182 | // Transaction 2: Request another resource in digestive's protection space. |
| 6183 | // This will preemptively add an Authorization header which should have an |
| 6184 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6185 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6186 | HttpRequestInfo request; |
| 6187 | request.method = "GET"; |
| 6188 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6189 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6190 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6191 | request.load_flags = 0; |
| 6192 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6193 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6195 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6196 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6197 | MockWrite( |
| 6198 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6199 | "Host: www.example.org\r\n" |
| 6200 | "Connection: keep-alive\r\n" |
| 6201 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6202 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6203 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6204 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6205 | }; |
| 6206 | |
| 6207 | // Sever accepts the authorization. |
| 6208 | MockRead data_reads1[] = { |
| 6209 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6210 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6211 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6212 | }; |
| 6213 | |
| 6214 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6215 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6216 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6218 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6220 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6221 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6222 | |
| 6223 | rv = callback1.WaitForResult(); |
| 6224 | EXPECT_EQ(OK, rv); |
| 6225 | |
| 6226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6227 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6228 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6229 | } |
| 6230 | } |
| 6231 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6232 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6233 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6234 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6235 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6236 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6238 | |
| 6239 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6240 | trans->read_buf_ = new IOBuffer(15); |
| 6241 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6242 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6243 | |
| 6244 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6245 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6246 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6247 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6248 | response->response_time = base::Time::Now(); |
| 6249 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6250 | |
| 6251 | { // Setup state for response_.vary_data |
| 6252 | HttpRequestInfo request; |
| 6253 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6254 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6255 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6256 | request.extra_headers.SetHeader("Foo", "1"); |
| 6257 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6258 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | // Cause the above state to be reset. |
| 6262 | trans->ResetStateForRestart(); |
| 6263 | |
| 6264 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6265 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6266 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6267 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6268 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6269 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6270 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6271 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6272 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6273 | } |
| 6274 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6275 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6276 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6277 | HttpRequestInfo request; |
| 6278 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6279 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6280 | request.load_flags = 0; |
| 6281 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6282 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6283 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6284 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6285 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6286 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6287 | MockWrite( |
| 6288 | "GET / HTTP/1.1\r\n" |
| 6289 | "Host: www.example.org\r\n" |
| 6290 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6291 | }; |
| 6292 | |
| 6293 | MockRead data_reads[] = { |
| 6294 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6295 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6296 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6297 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6298 | }; |
| 6299 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6300 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6301 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6302 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6303 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6304 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6305 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6306 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6307 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6309 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6311 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6313 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6314 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6315 | |
| 6316 | rv = callback.WaitForResult(); |
| 6317 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6319 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6321 | |
| 6322 | rv = callback.WaitForResult(); |
| 6323 | EXPECT_EQ(OK, rv); |
| 6324 | |
| 6325 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6326 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6327 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6328 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6329 | } |
| 6330 | |
| 6331 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6332 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6333 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6334 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6335 | |
| 6336 | HttpRequestInfo request; |
| 6337 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6338 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6339 | request.load_flags = 0; |
| 6340 | |
| 6341 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6342 | MockWrite( |
| 6343 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6344 | "Host: www.example.org\r\n" |
| 6345 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6346 | }; |
| 6347 | |
| 6348 | MockRead proxy_reads[] = { |
| 6349 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6350 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6351 | }; |
| 6352 | |
| 6353 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6354 | MockWrite( |
| 6355 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6356 | "Host: www.example.org\r\n" |
| 6357 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6358 | MockWrite( |
| 6359 | "GET / HTTP/1.1\r\n" |
| 6360 | "Host: www.example.org\r\n" |
| 6361 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6362 | }; |
| 6363 | |
| 6364 | MockRead data_reads[] = { |
| 6365 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6366 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6367 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6368 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6369 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6370 | }; |
| 6371 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6372 | StaticSocketDataProvider ssl_bad_certificate( |
| 6373 | proxy_reads, arraysize(proxy_reads), |
| 6374 | proxy_writes, arraysize(proxy_writes)); |
| 6375 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6376 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6377 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6378 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6379 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6380 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6381 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6385 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6386 | |
| 6387 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6388 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6389 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6390 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6391 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6392 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6394 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6395 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6396 | |
| 6397 | rv = callback.WaitForResult(); |
| 6398 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6400 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6401 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6402 | |
| 6403 | rv = callback.WaitForResult(); |
| 6404 | EXPECT_EQ(OK, rv); |
| 6405 | |
| 6406 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6407 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6408 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6409 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6410 | } |
| 6411 | } |
| 6412 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6413 | |
| 6414 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6415 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6416 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6417 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6418 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6419 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6420 | |
| 6421 | HttpRequestInfo request; |
| 6422 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6423 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6424 | request.load_flags = 0; |
| 6425 | |
| 6426 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6427 | MockWrite( |
| 6428 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6429 | "Host: www.example.org\r\n" |
| 6430 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6431 | MockWrite( |
| 6432 | "GET / HTTP/1.1\r\n" |
| 6433 | "Host: www.example.org\r\n" |
| 6434 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6435 | }; |
| 6436 | |
| 6437 | MockRead data_reads[] = { |
| 6438 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6439 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6440 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6441 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6442 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6443 | }; |
| 6444 | |
| 6445 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6446 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6447 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6448 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6449 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6450 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6451 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6454 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6455 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6456 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6457 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6458 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6460 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6461 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6462 | |
| 6463 | rv = callback.WaitForResult(); |
| 6464 | EXPECT_EQ(OK, rv); |
| 6465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6466 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6467 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6468 | |
| 6469 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6470 | EXPECT_EQ(200, response->headers->response_code()); |
| 6471 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6472 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6473 | |
| 6474 | LoadTimingInfo load_timing_info; |
| 6475 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6476 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6477 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6478 | } |
| 6479 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6480 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6481 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6482 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6483 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6484 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6485 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6486 | |
| 6487 | HttpRequestInfo request; |
| 6488 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6489 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6490 | request.load_flags = 0; |
| 6491 | |
| 6492 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6493 | MockWrite( |
| 6494 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6495 | "Host: www.example.org\r\n" |
| 6496 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6497 | }; |
| 6498 | |
| 6499 | MockRead data_reads[] = { |
| 6500 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6501 | MockRead("Location: http://login.example.com/\r\n"), |
| 6502 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6503 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6504 | }; |
| 6505 | |
| 6506 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6507 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6508 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6509 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6510 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6513 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6514 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6515 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6516 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6517 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6519 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6521 | |
| 6522 | rv = callback.WaitForResult(); |
| 6523 | EXPECT_EQ(OK, rv); |
| 6524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6525 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6526 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6527 | |
| 6528 | EXPECT_EQ(302, response->headers->response_code()); |
| 6529 | std::string url; |
| 6530 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6531 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6532 | |
| 6533 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6534 | // timing for the proxy connection instead of the connection to the host, |
| 6535 | // and no send / receive times. |
| 6536 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6537 | LoadTimingInfo load_timing_info; |
| 6538 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6539 | |
| 6540 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6541 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6542 | |
| 6543 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6544 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6545 | load_timing_info.proxy_resolve_end); |
| 6546 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6547 | load_timing_info.connect_timing.connect_start); |
| 6548 | ExpectConnectTimingHasTimes( |
| 6549 | load_timing_info.connect_timing, |
| 6550 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6551 | |
| 6552 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6553 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6554 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6555 | } |
| 6556 | |
| 6557 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6558 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6559 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6560 | ProxyService::CreateFixed("https://proxy:70")); |
| 6561 | |
| 6562 | HttpRequestInfo request; |
| 6563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6564 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6565 | request.load_flags = 0; |
| 6566 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6567 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6568 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6569 | scoped_ptr<SpdyFrame> goaway( |
| 6570 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6571 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6572 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6573 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6574 | }; |
| 6575 | |
| 6576 | static const char* const kExtraHeaders[] = { |
| 6577 | "location", |
| 6578 | "http://login.example.com/", |
| 6579 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6580 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6581 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6582 | arraysize(kExtraHeaders)/2, 1)); |
| 6583 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6584 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6585 | }; |
| 6586 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6587 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6588 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6589 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6590 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6591 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6593 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6595 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6596 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6597 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6598 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6599 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6601 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6603 | |
| 6604 | rv = callback.WaitForResult(); |
| 6605 | EXPECT_EQ(OK, rv); |
| 6606 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6607 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6608 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6609 | |
| 6610 | EXPECT_EQ(302, response->headers->response_code()); |
| 6611 | std::string url; |
| 6612 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6613 | EXPECT_EQ("http://login.example.com/", url); |
| 6614 | } |
| 6615 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6616 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6617 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6618 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6619 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6620 | ProxyService::CreateFixed("https://proxy:70")); |
| 6621 | |
| 6622 | HttpRequestInfo request; |
| 6623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6624 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6625 | request.load_flags = 0; |
| 6626 | |
| 6627 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6628 | MockWrite( |
| 6629 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6630 | "Host: www.example.org\r\n" |
| 6631 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6632 | }; |
| 6633 | |
| 6634 | MockRead data_reads[] = { |
| 6635 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6636 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6637 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6638 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6639 | }; |
| 6640 | |
| 6641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6642 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6643 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6644 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6648 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6649 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6650 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6651 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6652 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6654 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6656 | |
| 6657 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6658 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6659 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6660 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6661 | } |
| 6662 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6663 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6664 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6665 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6666 | session_deps_.proxy_service.reset( |
| 6667 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6668 | |
| 6669 | HttpRequestInfo request; |
| 6670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6671 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6672 | request.load_flags = 0; |
| 6673 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6674 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6675 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6676 | scoped_ptr<SpdyFrame> rst( |
| 6677 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6678 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6679 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | }; |
| 6681 | |
| 6682 | static const char* const kExtraHeaders[] = { |
| 6683 | "location", |
| 6684 | "http://login.example.com/", |
| 6685 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6686 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6687 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6688 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6689 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6690 | spdy_util_.ConstructSpdyBodyFrame( |
| 6691 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6692 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6693 | CreateMockRead(*resp.get(), 1), |
| 6694 | CreateMockRead(*body.get(), 2), |
| 6695 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6696 | }; |
| 6697 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6698 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6699 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6700 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6701 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6702 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6703 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6706 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6707 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6708 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6709 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6710 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6712 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6713 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6714 | |
| 6715 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6716 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6717 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6718 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6719 | } |
| 6720 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6721 | // Test the request-challenge-retry sequence for basic auth, through |
| 6722 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6723 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6724 | HttpRequestInfo request; |
| 6725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6726 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6727 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6728 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6729 | |
| 6730 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6731 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6732 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6733 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6734 | session_deps_.net_log = log.bound().net_log(); |
| 6735 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6736 | |
| 6737 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6738 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6739 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6740 | scoped_ptr<SpdyFrame> rst( |
| 6741 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6742 | |
| 6743 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6744 | // be issuing -- the final header line contains the credentials. |
| 6745 | const char* const kAuthCredentials[] = { |
| 6746 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6747 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6748 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6749 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6750 | HostPortPair("www.example.org", 443))); |
| 6751 | // fetch https://www.example.org/ via HTTP |
| 6752 | const char get[] = |
| 6753 | "GET / HTTP/1.1\r\n" |
| 6754 | "Host: www.example.org\r\n" |
| 6755 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6756 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6757 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6758 | |
| 6759 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6760 | CreateMockWrite(*req, 0, ASYNC), |
| 6761 | CreateMockWrite(*rst, 2, ASYNC), |
| 6762 | CreateMockWrite(*connect2, 3), |
| 6763 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6764 | }; |
| 6765 | |
| 6766 | // The proxy responds to the connect with a 407, using a persistent |
| 6767 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6768 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6769 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6770 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6771 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6772 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6773 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6774 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6775 | scoped_ptr<SpdyFrame> conn_resp( |
| 6776 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6777 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6778 | "Content-Length: 5\r\n\r\n"; |
| 6779 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6780 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6781 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6782 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6783 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6784 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6785 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6786 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6787 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6788 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6789 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6790 | }; |
| 6791 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6792 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6793 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6794 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6795 | // Negotiate SPDY to the proxy |
| 6796 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6797 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6799 | // Vanilla SSL to the server |
| 6800 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6802 | |
| 6803 | TestCompletionCallback callback1; |
| 6804 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6805 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6806 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6807 | |
| 6808 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6810 | |
| 6811 | rv = callback1.WaitForResult(); |
| 6812 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6813 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6814 | log.GetEntries(&entries); |
| 6815 | size_t pos = ExpectLogContainsSomewhere( |
| 6816 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6817 | NetLog::PHASE_NONE); |
| 6818 | ExpectLogContainsSomewhere( |
| 6819 | entries, pos, |
| 6820 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6821 | NetLog::PHASE_NONE); |
| 6822 | |
| 6823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6824 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6825 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6826 | EXPECT_EQ(407, response->headers->response_code()); |
| 6827 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6828 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6829 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6830 | |
| 6831 | TestCompletionCallback callback2; |
| 6832 | |
| 6833 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6834 | callback2.callback()); |
| 6835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6836 | |
| 6837 | rv = callback2.WaitForResult(); |
| 6838 | EXPECT_EQ(OK, rv); |
| 6839 | |
| 6840 | response = trans->GetResponseInfo(); |
| 6841 | ASSERT_TRUE(response != NULL); |
| 6842 | |
| 6843 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6844 | EXPECT_EQ(200, response->headers->response_code()); |
| 6845 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6846 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6847 | |
| 6848 | // The password prompt info should not be set. |
| 6849 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6850 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6851 | LoadTimingInfo load_timing_info; |
| 6852 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6853 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6854 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6855 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6856 | trans.reset(); |
| 6857 | session->CloseAllConnections(); |
| 6858 | } |
| 6859 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6860 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6861 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6862 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6863 | HttpRequestInfo request; |
| 6864 | HttpRequestInfo push_request; |
| 6865 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6867 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6868 | push_request.method = "GET"; |
| 6869 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6870 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6871 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6872 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6873 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6874 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6875 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6876 | |
| 6877 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6878 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6879 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6881 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6882 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6883 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6884 | |
| 6885 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6886 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6887 | }; |
| 6888 | |
| 6889 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6890 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6891 | |
| 6892 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6893 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6894 | |
| 6895 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6896 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6897 | 0, |
| 6898 | 2, |
| 6899 | 1, |
| 6900 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6901 | const char kPushedData[] = "pushed"; |
| 6902 | scoped_ptr<SpdyFrame> stream2_body( |
| 6903 | spdy_util_.ConstructSpdyBodyFrame( |
| 6904 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6905 | |
| 6906 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6907 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 6908 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 6909 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 6910 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 6911 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6912 | }; |
| 6913 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6914 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6915 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6916 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6917 | // Negotiate SPDY to the proxy |
| 6918 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6919 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6920 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 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] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6924 | TestCompletionCallback callback; |
| 6925 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6927 | |
| 6928 | rv = callback.WaitForResult(); |
| 6929 | EXPECT_EQ(OK, rv); |
| 6930 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6931 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6932 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6933 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6934 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6935 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6936 | |
| 6937 | rv = callback.WaitForResult(); |
| 6938 | EXPECT_EQ(OK, rv); |
| 6939 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6940 | |
| 6941 | ASSERT_TRUE(response != NULL); |
| 6942 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6943 | |
| 6944 | EXPECT_EQ(200, response->headers->response_code()); |
| 6945 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6946 | |
| 6947 | std::string response_data; |
| 6948 | rv = ReadTransaction(trans.get(), &response_data); |
| 6949 | EXPECT_EQ(OK, rv); |
| 6950 | EXPECT_EQ("hello!", response_data); |
| 6951 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6952 | LoadTimingInfo load_timing_info; |
| 6953 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6954 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6955 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6956 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6957 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6958 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6959 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6960 | |
| 6961 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6962 | EXPECT_EQ(OK, rv); |
| 6963 | EXPECT_EQ("pushed", response_data); |
| 6964 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6965 | LoadTimingInfo push_load_timing_info; |
| 6966 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6967 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6968 | // The transactions should share a socket ID, despite being for different |
| 6969 | // origins. |
| 6970 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6971 | push_load_timing_info.socket_log_id); |
| 6972 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6973 | trans.reset(); |
| 6974 | push_trans.reset(); |
| 6975 | session->CloseAllConnections(); |
| 6976 | } |
| 6977 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6978 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6979 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6980 | HttpRequestInfo request; |
| 6981 | |
| 6982 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6983 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6984 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6985 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6986 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6987 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6988 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6989 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6990 | |
| 6991 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6992 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6993 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6994 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6995 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6996 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6997 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6998 | |
| 6999 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7000 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7001 | |
| 7002 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7003 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [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] | 8c84319 | 2012-04-05 07:15:00 | [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] | 8c84319 | 2012-04-05 07:15:00 | [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] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7014 | 0, |
| 7015 | 2, |
| 7016 | 1, |
| 7017 | "https://www.another-origin.com/foo.dat")); |
| 7018 | |
| 7019 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7020 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7021 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7022 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7023 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7024 | }; |
| 7025 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7026 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7027 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7028 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7029 | // Negotiate SPDY to the proxy |
| 7030 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7031 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7033 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7034 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7035 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7036 | TestCompletionCallback callback; |
| 7037 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7038 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7039 | |
| 7040 | rv = callback.WaitForResult(); |
| 7041 | EXPECT_EQ(OK, rv); |
| 7042 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7043 | |
| 7044 | ASSERT_TRUE(response != NULL); |
| 7045 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7046 | |
| 7047 | EXPECT_EQ(200, response->headers->response_code()); |
| 7048 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7049 | |
| 7050 | std::string response_data; |
| 7051 | rv = ReadTransaction(trans.get(), &response_data); |
| 7052 | EXPECT_EQ(OK, rv); |
| 7053 | EXPECT_EQ("hello!", response_data); |
| 7054 | |
| 7055 | trans.reset(); |
| 7056 | session->CloseAllConnections(); |
| 7057 | } |
| 7058 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7059 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7060 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7061 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7062 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7063 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7064 | |
| 7065 | HttpRequestInfo request; |
| 7066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7067 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7068 | request.load_flags = 0; |
| 7069 | |
| 7070 | // Attempt to fetch the URL from a server with a bad cert |
| 7071 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7072 | MockWrite( |
| 7073 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7074 | "Host: www.example.org\r\n" |
| 7075 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7076 | }; |
| 7077 | |
| 7078 | MockRead bad_cert_reads[] = { |
| 7079 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7080 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7081 | }; |
| 7082 | |
| 7083 | // Attempt to fetch the URL with a good cert |
| 7084 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7085 | MockWrite( |
| 7086 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7087 | "Host: www.example.org\r\n" |
| 7088 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7089 | MockWrite( |
| 7090 | "GET / HTTP/1.1\r\n" |
| 7091 | "Host: www.example.org\r\n" |
| 7092 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7093 | }; |
| 7094 | |
| 7095 | MockRead good_cert_reads[] = { |
| 7096 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7097 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7098 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7099 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7101 | }; |
| 7102 | |
| 7103 | StaticSocketDataProvider ssl_bad_certificate( |
| 7104 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7105 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7106 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7107 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7108 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7109 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7110 | |
| 7111 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7113 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7115 | |
| 7116 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7118 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7119 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7121 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7122 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7124 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7127 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7129 | |
| 7130 | rv = callback.WaitForResult(); |
| 7131 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7133 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7134 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7135 | |
| 7136 | rv = callback.WaitForResult(); |
| 7137 | EXPECT_EQ(OK, rv); |
| 7138 | |
| 7139 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7140 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7141 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7142 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7143 | } |
| 7144 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7145 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7146 | HttpRequestInfo request; |
| 7147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7148 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7149 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7150 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7151 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7152 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7153 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7154 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7155 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7156 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7157 | MockWrite( |
| 7158 | "GET / HTTP/1.1\r\n" |
| 7159 | "Host: www.example.org\r\n" |
| 7160 | "Connection: keep-alive\r\n" |
| 7161 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7162 | }; |
| 7163 | |
| 7164 | // Lastly, the server responds with the actual content. |
| 7165 | MockRead data_reads[] = { |
| 7166 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7167 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7168 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7169 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7170 | }; |
| 7171 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7173 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7176 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7178 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7180 | |
| 7181 | rv = callback.WaitForResult(); |
| 7182 | EXPECT_EQ(OK, rv); |
| 7183 | } |
| 7184 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7185 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7186 | HttpRequestInfo request; |
| 7187 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7188 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7189 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7190 | "Chromium Ultra Awesome X Edition"); |
| 7191 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7192 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7193 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7194 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7196 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7197 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7198 | MockWrite( |
| 7199 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7200 | "Host: www.example.org\r\n" |
| 7201 | "Proxy-Connection: keep-alive\r\n" |
| 7202 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7203 | }; |
| 7204 | MockRead data_reads[] = { |
| 7205 | // Return an error, so the transaction stops here (this test isn't |
| 7206 | // interested in the rest). |
| 7207 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7208 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7209 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7210 | }; |
| 7211 | |
| 7212 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7213 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7216 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7220 | |
| 7221 | rv = callback.WaitForResult(); |
| 7222 | EXPECT_EQ(OK, rv); |
| 7223 | } |
| 7224 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7225 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7226 | HttpRequestInfo request; |
| 7227 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7228 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7229 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7230 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7231 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7232 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7233 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7234 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7236 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7237 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7238 | MockWrite( |
| 7239 | "GET / HTTP/1.1\r\n" |
| 7240 | "Host: www.example.org\r\n" |
| 7241 | "Connection: keep-alive\r\n" |
| 7242 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7243 | }; |
| 7244 | |
| 7245 | // Lastly, the server responds with the actual content. |
| 7246 | MockRead data_reads[] = { |
| 7247 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7248 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7249 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7250 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7251 | }; |
| 7252 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7253 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7254 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7257 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7259 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7261 | |
| 7262 | rv = callback.WaitForResult(); |
| 7263 | EXPECT_EQ(OK, rv); |
| 7264 | } |
| 7265 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7266 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7267 | HttpRequestInfo request; |
| 7268 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7269 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7270 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7271 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7272 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7273 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7274 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7275 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7276 | MockWrite( |
| 7277 | "POST / HTTP/1.1\r\n" |
| 7278 | "Host: www.example.org\r\n" |
| 7279 | "Connection: keep-alive\r\n" |
| 7280 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7281 | }; |
| 7282 | |
| 7283 | // Lastly, the server responds with the actual content. |
| 7284 | MockRead data_reads[] = { |
| 7285 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7286 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7287 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7288 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7289 | }; |
| 7290 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7291 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7292 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7295 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7297 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7299 | |
| 7300 | rv = callback.WaitForResult(); |
| 7301 | EXPECT_EQ(OK, rv); |
| 7302 | } |
| 7303 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7304 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7305 | HttpRequestInfo request; |
| 7306 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7307 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7308 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7310 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7312 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7313 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7314 | MockWrite( |
| 7315 | "PUT / HTTP/1.1\r\n" |
| 7316 | "Host: www.example.org\r\n" |
| 7317 | "Connection: keep-alive\r\n" |
| 7318 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7319 | }; |
| 7320 | |
| 7321 | // Lastly, the server responds with the actual content. |
| 7322 | MockRead data_reads[] = { |
| 7323 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7324 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7325 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7326 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7327 | }; |
| 7328 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7329 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7330 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7331 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7332 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7333 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7335 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7337 | |
| 7338 | rv = callback.WaitForResult(); |
| 7339 | EXPECT_EQ(OK, rv); |
| 7340 | } |
| 7341 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7342 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7343 | HttpRequestInfo request; |
| 7344 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7345 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7346 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7347 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7348 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7349 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7350 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7351 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7352 | MockWrite( |
| 7353 | "HEAD / HTTP/1.1\r\n" |
| 7354 | "Host: www.example.org\r\n" |
| 7355 | "Connection: keep-alive\r\n" |
| 7356 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7357 | }; |
| 7358 | |
| 7359 | // Lastly, the server responds with the actual content. |
| 7360 | MockRead data_reads[] = { |
| 7361 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7362 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7363 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7364 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7365 | }; |
| 7366 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7367 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7368 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7371 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7373 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7375 | |
| 7376 | rv = callback.WaitForResult(); |
| 7377 | EXPECT_EQ(OK, rv); |
| 7378 | } |
| 7379 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7380 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7381 | HttpRequestInfo request; |
| 7382 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7383 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7384 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7385 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [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 | "GET / HTTP/1.1\r\n" |
| 7393 | "Host: www.example.org\r\n" |
| 7394 | "Connection: keep-alive\r\n" |
| 7395 | "Pragma: no-cache\r\n" |
| 7396 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7397 | }; |
| 7398 | |
| 7399 | // Lastly, the server responds with the actual content. |
| 7400 | MockRead data_reads[] = { |
| 7401 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7402 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7403 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7404 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7405 | }; |
| 7406 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7407 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7408 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7409 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7411 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7413 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7414 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7415 | |
| 7416 | rv = callback.WaitForResult(); |
| 7417 | EXPECT_EQ(OK, rv); |
| 7418 | } |
| 7419 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7420 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7421 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7422 | HttpRequestInfo request; |
| 7423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7424 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7425 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7426 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7427 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7428 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7429 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7430 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7431 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7432 | MockWrite( |
| 7433 | "GET / HTTP/1.1\r\n" |
| 7434 | "Host: www.example.org\r\n" |
| 7435 | "Connection: keep-alive\r\n" |
| 7436 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7437 | }; |
| 7438 | |
| 7439 | // Lastly, the server responds with the actual content. |
| 7440 | MockRead data_reads[] = { |
| 7441 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7442 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7443 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7445 | }; |
| 7446 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7447 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7448 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7449 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7451 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7453 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7454 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7455 | |
| 7456 | rv = callback.WaitForResult(); |
| 7457 | EXPECT_EQ(OK, rv); |
| 7458 | } |
| 7459 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7460 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7461 | HttpRequestInfo request; |
| 7462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7463 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7464 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7465 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7466 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7467 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7468 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7469 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7470 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7471 | MockWrite( |
| 7472 | "GET / HTTP/1.1\r\n" |
| 7473 | "Host: www.example.org\r\n" |
| 7474 | "Connection: keep-alive\r\n" |
| 7475 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7476 | }; |
| 7477 | |
| 7478 | // Lastly, the server responds with the actual content. |
| 7479 | MockRead data_reads[] = { |
| 7480 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7481 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7482 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7483 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7484 | }; |
| 7485 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7486 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7487 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7490 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7492 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7494 | |
| 7495 | rv = callback.WaitForResult(); |
| 7496 | EXPECT_EQ(OK, rv); |
| 7497 | } |
| 7498 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7499 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7500 | HttpRequestInfo request; |
| 7501 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7502 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7503 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7504 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7505 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7506 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7507 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7508 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7509 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7510 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7511 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7512 | MockWrite( |
| 7513 | "GET / HTTP/1.1\r\n" |
| 7514 | "Host: www.example.org\r\n" |
| 7515 | "Connection: keep-alive\r\n" |
| 7516 | "referer: www.foo.com\r\n" |
| 7517 | "hEllo: Kitty\r\n" |
| 7518 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | // Lastly, the server responds with the actual content. |
| 7522 | MockRead data_reads[] = { |
| 7523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7527 | }; |
| 7528 | |
| 7529 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7530 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7531 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7533 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7536 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7537 | |
| 7538 | rv = callback.WaitForResult(); |
| 7539 | EXPECT_EQ(OK, rv); |
| 7540 | } |
| 7541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7542 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7543 | HttpRequestInfo request; |
| 7544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7545 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7546 | request.load_flags = 0; |
| 7547 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7548 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7549 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7550 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7551 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7552 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7553 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7554 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7555 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7556 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7557 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7558 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7559 | |
| 7560 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7561 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7562 | MockWrite( |
| 7563 | "GET / HTTP/1.1\r\n" |
| 7564 | "Host: www.example.org\r\n" |
| 7565 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7566 | |
| 7567 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7568 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7569 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7570 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7571 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7572 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7573 | }; |
| 7574 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7575 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7576 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7577 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7579 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7581 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7582 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7583 | |
| 7584 | rv = callback.WaitForResult(); |
| 7585 | EXPECT_EQ(OK, rv); |
| 7586 | |
| 7587 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7588 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7589 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7590 | LoadTimingInfo load_timing_info; |
| 7591 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7592 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7593 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7594 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7595 | std::string response_text; |
| 7596 | rv = ReadTransaction(trans.get(), &response_text); |
| 7597 | EXPECT_EQ(OK, rv); |
| 7598 | EXPECT_EQ("Payload", response_text); |
| 7599 | } |
| 7600 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7601 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7602 | HttpRequestInfo request; |
| 7603 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7604 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7605 | request.load_flags = 0; |
| 7606 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7607 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7608 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7609 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7610 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7611 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7612 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7613 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7614 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7615 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7616 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7617 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7618 | |
| 7619 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7620 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7621 | arraysize(write_buffer)), |
| 7622 | MockWrite( |
| 7623 | "GET / HTTP/1.1\r\n" |
| 7624 | "Host: www.example.org\r\n" |
| 7625 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7626 | |
| 7627 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7628 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7629 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7630 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7631 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7632 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7633 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7634 | }; |
| 7635 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7636 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7637 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7638 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7639 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7640 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7643 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7644 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7645 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7647 | |
| 7648 | rv = callback.WaitForResult(); |
| 7649 | EXPECT_EQ(OK, rv); |
| 7650 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7651 | LoadTimingInfo load_timing_info; |
| 7652 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7653 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7654 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7655 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7656 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7657 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7658 | |
| 7659 | std::string response_text; |
| 7660 | rv = ReadTransaction(trans.get(), &response_text); |
| 7661 | EXPECT_EQ(OK, rv); |
| 7662 | EXPECT_EQ("Payload", response_text); |
| 7663 | } |
| 7664 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7665 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7666 | HttpRequestInfo request; |
| 7667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7668 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7669 | request.load_flags = 0; |
| 7670 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7671 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7672 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7673 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7674 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7675 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7676 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7677 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7678 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7679 | |
| 7680 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7681 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7682 | |
| 7683 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7684 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7685 | MockWrite( |
| 7686 | "GET / HTTP/1.1\r\n" |
| 7687 | "Host: www.example.org\r\n" |
| 7688 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7689 | |
| 7690 | MockRead data_reads[] = { |
| 7691 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7692 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7693 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7694 | MockRead("Payload"), |
| 7695 | MockRead(SYNCHRONOUS, OK) |
| 7696 | }; |
| 7697 | |
| 7698 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7699 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7700 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7701 | |
| 7702 | TestCompletionCallback callback; |
| 7703 | |
| 7704 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7705 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7706 | |
| 7707 | rv = callback.WaitForResult(); |
| 7708 | EXPECT_EQ(OK, rv); |
| 7709 | |
| 7710 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7711 | ASSERT_TRUE(response != NULL); |
| 7712 | |
| 7713 | LoadTimingInfo load_timing_info; |
| 7714 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7715 | TestLoadTimingNotReused(load_timing_info, |
| 7716 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7717 | |
| 7718 | std::string response_text; |
| 7719 | rv = ReadTransaction(trans.get(), &response_text); |
| 7720 | EXPECT_EQ(OK, rv); |
| 7721 | EXPECT_EQ("Payload", response_text); |
| 7722 | } |
| 7723 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7724 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7725 | HttpRequestInfo request; |
| 7726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7727 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7728 | request.load_flags = 0; |
| 7729 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7730 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7731 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7732 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7733 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7734 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7735 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7736 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7737 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7738 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7739 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7740 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7741 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7742 | 0x05, // Version |
| 7743 | 0x01, // Command (CONNECT) |
| 7744 | 0x00, // Reserved. |
| 7745 | 0x03, // Address type (DOMAINNAME). |
| 7746 | 0x0F, // Length of domain (15) |
| 7747 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7748 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7749 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7750 | const char kSOCKS5OkResponse[] = |
| 7751 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7752 | |
| 7753 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7754 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7755 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7756 | MockWrite( |
| 7757 | "GET / HTTP/1.1\r\n" |
| 7758 | "Host: www.example.org\r\n" |
| 7759 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7760 | |
| 7761 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7762 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7763 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7764 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7765 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7766 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7767 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7768 | }; |
| 7769 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7770 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7771 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7774 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7778 | |
| 7779 | rv = callback.WaitForResult(); |
| 7780 | EXPECT_EQ(OK, rv); |
| 7781 | |
| 7782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7783 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7784 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7785 | LoadTimingInfo load_timing_info; |
| 7786 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7787 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7788 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7789 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7790 | std::string response_text; |
| 7791 | rv = ReadTransaction(trans.get(), &response_text); |
| 7792 | EXPECT_EQ(OK, rv); |
| 7793 | EXPECT_EQ("Payload", response_text); |
| 7794 | } |
| 7795 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7796 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7797 | HttpRequestInfo request; |
| 7798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7799 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7800 | request.load_flags = 0; |
| 7801 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7802 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7803 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7804 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7805 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7806 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7807 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7808 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7809 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7810 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7811 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7812 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7813 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7814 | 0x05, // Version |
| 7815 | 0x01, // Command (CONNECT) |
| 7816 | 0x00, // Reserved. |
| 7817 | 0x03, // Address type (DOMAINNAME). |
| 7818 | 0x0F, // Length of domain (15) |
| 7819 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7820 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7821 | }; |
| 7822 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7823 | const char kSOCKS5OkResponse[] = |
| 7824 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7825 | |
| 7826 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7827 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7828 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7829 | arraysize(kSOCKS5OkRequest)), |
| 7830 | MockWrite( |
| 7831 | "GET / HTTP/1.1\r\n" |
| 7832 | "Host: www.example.org\r\n" |
| 7833 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7834 | |
| 7835 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7836 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7837 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7838 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7839 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7840 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7841 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7842 | }; |
| 7843 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7844 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7845 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7847 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7848 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7851 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7853 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7854 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7855 | |
| 7856 | rv = callback.WaitForResult(); |
| 7857 | EXPECT_EQ(OK, rv); |
| 7858 | |
| 7859 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7860 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7861 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7862 | LoadTimingInfo load_timing_info; |
| 7863 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7864 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7865 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7866 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7867 | std::string response_text; |
| 7868 | rv = ReadTransaction(trans.get(), &response_text); |
| 7869 | EXPECT_EQ(OK, rv); |
| 7870 | EXPECT_EQ("Payload", response_text); |
| 7871 | } |
| 7872 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7873 | namespace { |
| 7874 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7875 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7876 | |
| 7877 | struct GroupNameTest { |
| 7878 | std::string proxy_server; |
| 7879 | std::string url; |
| 7880 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7881 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7882 | }; |
| 7883 | |
| 7884 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7885 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7886 | SpdySessionDependencies* session_deps_) { |
| 7887 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7888 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7889 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7890 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7891 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7892 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7893 | http_server_properties->SetAlternativeService( |
| 7894 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7895 | |
| 7896 | return session; |
| 7897 | } |
| 7898 | |
| 7899 | int GroupNameTransactionHelper( |
| 7900 | const std::string& url, |
| 7901 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7902 | HttpRequestInfo request; |
| 7903 | request.method = "GET"; |
| 7904 | request.url = GURL(url); |
| 7905 | request.load_flags = 0; |
| 7906 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7907 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7908 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7910 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7911 | |
| 7912 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7913 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7914 | } |
| 7915 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7916 | } // namespace |
| 7917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7918 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7919 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7920 | { |
| 7921 | "", // unused |
| 7922 | "http://www.example.org/direct", |
| 7923 | "www.example.org:80", |
| 7924 | false, |
| 7925 | }, |
| 7926 | { |
| 7927 | "", // unused |
| 7928 | "http://[2001:1418:13:1::25]/direct", |
| 7929 | "[2001:1418:13:1::25]:80", |
| 7930 | false, |
| 7931 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7932 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7933 | // SSL Tests |
| 7934 | { |
| 7935 | "", // unused |
| 7936 | "https://www.example.org/direct_ssl", |
| 7937 | "ssl/www.example.org:443", |
| 7938 | true, |
| 7939 | }, |
| 7940 | { |
| 7941 | "", // unused |
| 7942 | "https://[2001:1418:13:1::25]/direct", |
| 7943 | "ssl/[2001:1418:13:1::25]:443", |
| 7944 | true, |
| 7945 | }, |
| 7946 | { |
| 7947 | "", // unused |
| 7948 | "http://host.with.alternate/direct", |
| 7949 | "ssl/host.with.alternate:443", |
| 7950 | true, |
| 7951 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7952 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7953 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7954 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7955 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7956 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7957 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7958 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7959 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7960 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7961 | |
| 7962 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7963 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7964 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7965 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7966 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7967 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7968 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7969 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7970 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7971 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7972 | |
| 7973 | EXPECT_EQ(ERR_IO_PENDING, |
| 7974 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7975 | if (tests[i].ssl) |
| 7976 | EXPECT_EQ(tests[i].expected_group_name, |
| 7977 | ssl_conn_pool->last_group_name_received()); |
| 7978 | else |
| 7979 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7980 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7981 | } |
| 7982 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7983 | } |
| 7984 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7985 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7986 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7987 | { |
| 7988 | "http_proxy", |
| 7989 | "http://www.example.org/http_proxy_normal", |
| 7990 | "www.example.org:80", |
| 7991 | false, |
| 7992 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7993 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7994 | // SSL Tests |
| 7995 | { |
| 7996 | "http_proxy", |
| 7997 | "https://www.example.org/http_connect_ssl", |
| 7998 | "ssl/www.example.org:443", |
| 7999 | true, |
| 8000 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8001 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8002 | { |
| 8003 | "http_proxy", |
| 8004 | "http://host.with.alternate/direct", |
| 8005 | "ssl/host.with.alternate:443", |
| 8006 | true, |
| 8007 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8008 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8009 | { |
| 8010 | "http_proxy", |
| 8011 | "ftp://ftp.google.com/http_proxy_normal", |
| 8012 | "ftp/ftp.google.com:21", |
| 8013 | false, |
| 8014 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8015 | }; |
| 8016 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8017 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8018 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8019 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8020 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8021 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8022 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8023 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8024 | |
| 8025 | HttpNetworkSessionPeer peer(session); |
| 8026 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8027 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8028 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8029 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8030 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8031 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8032 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8033 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8034 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8035 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8036 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8037 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8038 | |
| 8039 | EXPECT_EQ(ERR_IO_PENDING, |
| 8040 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8041 | if (tests[i].ssl) |
| 8042 | EXPECT_EQ(tests[i].expected_group_name, |
| 8043 | ssl_conn_pool->last_group_name_received()); |
| 8044 | else |
| 8045 | EXPECT_EQ(tests[i].expected_group_name, |
| 8046 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8047 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8048 | } |
| 8049 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8050 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8051 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8052 | { |
| 8053 | "socks4://socks_proxy:1080", |
| 8054 | "http://www.example.org/socks4_direct", |
| 8055 | "socks4/www.example.org:80", |
| 8056 | false, |
| 8057 | }, |
| 8058 | { |
| 8059 | "socks5://socks_proxy:1080", |
| 8060 | "http://www.example.org/socks5_direct", |
| 8061 | "socks5/www.example.org:80", |
| 8062 | false, |
| 8063 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8064 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8065 | // SSL Tests |
| 8066 | { |
| 8067 | "socks4://socks_proxy:1080", |
| 8068 | "https://www.example.org/socks4_ssl", |
| 8069 | "socks4/ssl/www.example.org:443", |
| 8070 | true, |
| 8071 | }, |
| 8072 | { |
| 8073 | "socks5://socks_proxy:1080", |
| 8074 | "https://www.example.org/socks5_ssl", |
| 8075 | "socks5/ssl/www.example.org:443", |
| 8076 | true, |
| 8077 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8078 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8079 | { |
| 8080 | "socks4://socks_proxy:1080", |
| 8081 | "http://host.with.alternate/direct", |
| 8082 | "socks4/ssl/host.with.alternate:443", |
| 8083 | true, |
| 8084 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8085 | }; |
| 8086 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8087 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8088 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8089 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8090 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8091 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8092 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8093 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8094 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8095 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8096 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8097 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8098 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8099 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8100 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8101 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8102 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8103 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8104 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8105 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8106 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8107 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8108 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8109 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8110 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8111 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8112 | EXPECT_EQ(ERR_IO_PENDING, |
| 8113 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8114 | if (tests[i].ssl) |
| 8115 | EXPECT_EQ(tests[i].expected_group_name, |
| 8116 | ssl_conn_pool->last_group_name_received()); |
| 8117 | else |
| 8118 | EXPECT_EQ(tests[i].expected_group_name, |
| 8119 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8120 | } |
| 8121 | } |
| 8122 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8123 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8124 | HttpRequestInfo request; |
| 8125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8126 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8127 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8128 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8129 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8130 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8131 | // This simulates failure resolving all hostnames; that means we will fail |
| 8132 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8133 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8134 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8135 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8136 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8137 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8139 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8141 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8142 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8143 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8144 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8145 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8146 | } |
| 8147 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8148 | // Base test to make sure that when the load flags for a request specify to |
| 8149 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8150 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8151 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8152 | // Issue a request, asking to bypass the cache(s). |
| 8153 | HttpRequestInfo request; |
| 8154 | request.method = "GET"; |
| 8155 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8156 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8157 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8158 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8159 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8160 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8161 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8162 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8164 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8165 | // 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] | 8166 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8167 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8168 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8169 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8170 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8171 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8172 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8173 | EXPECT_EQ(OK, rv); |
| 8174 | |
| 8175 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8176 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8177 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8178 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8179 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8180 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8181 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8182 | // 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] | 8183 | // we can tell if the next lookup hit the cache, or the "network". |
| 8184 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8185 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8186 | |
| 8187 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8188 | // 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] | 8189 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8190 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8191 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8192 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8193 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8194 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8195 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8196 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8197 | |
| 8198 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8199 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8200 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8201 | } |
| 8202 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8203 | // There are multiple load flags that should trigger the host cache bypass. |
| 8204 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8205 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8206 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8207 | } |
| 8208 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8209 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8210 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8211 | } |
| 8212 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8213 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8214 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8215 | } |
| 8216 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8217 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8218 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8219 | HttpRequestInfo request; |
| 8220 | request.method = "GET"; |
| 8221 | request.url = GURL("http://www.foo.com/"); |
| 8222 | request.load_flags = 0; |
| 8223 | |
| 8224 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8225 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8226 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8227 | StaticSocketDataProvider data(NULL, 0, |
| 8228 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8230 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8232 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8233 | |
| 8234 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8237 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8238 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8239 | |
| 8240 | rv = callback.WaitForResult(); |
| 8241 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8242 | } |
| 8243 | |
| 8244 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8245 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8246 | HttpRequestInfo request; |
| 8247 | request.method = "GET"; |
| 8248 | request.url = GURL("http://www.foo.com/"); |
| 8249 | request.load_flags = 0; |
| 8250 | |
| 8251 | MockRead data_reads[] = { |
| 8252 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8253 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8254 | }; |
| 8255 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8258 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8260 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8261 | |
| 8262 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8263 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8265 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8267 | |
| 8268 | rv = callback.WaitForResult(); |
| 8269 | EXPECT_EQ(OK, rv); |
| 8270 | |
| 8271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8272 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8273 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8274 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8275 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8276 | |
| 8277 | std::string response_data; |
| 8278 | rv = ReadTransaction(trans.get(), &response_data); |
| 8279 | EXPECT_EQ(OK, rv); |
| 8280 | EXPECT_EQ("", response_data); |
| 8281 | } |
| 8282 | |
| 8283 | // Make sure that a dropped connection while draining the body for auth |
| 8284 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8285 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8286 | HttpRequestInfo request; |
| 8287 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8288 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8289 | request.load_flags = 0; |
| 8290 | |
| 8291 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8292 | MockWrite( |
| 8293 | "GET / HTTP/1.1\r\n" |
| 8294 | "Host: www.example.org\r\n" |
| 8295 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8296 | }; |
| 8297 | |
| 8298 | MockRead data_reads1[] = { |
| 8299 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8300 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8301 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8302 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8303 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8304 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8305 | }; |
| 8306 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8307 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8308 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8309 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8310 | |
| 8311 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8312 | // be issuing -- the final header line contains the credentials. |
| 8313 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8314 | MockWrite( |
| 8315 | "GET / HTTP/1.1\r\n" |
| 8316 | "Host: www.example.org\r\n" |
| 8317 | "Connection: keep-alive\r\n" |
| 8318 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8319 | }; |
| 8320 | |
| 8321 | // Lastly, the server responds with the actual content. |
| 8322 | MockRead data_reads2[] = { |
| 8323 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8324 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8325 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8326 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8327 | }; |
| 8328 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8329 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8330 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8332 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8334 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8335 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8336 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8337 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8339 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8341 | |
| 8342 | rv = callback1.WaitForResult(); |
| 8343 | EXPECT_EQ(OK, rv); |
| 8344 | |
| 8345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8346 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8347 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8349 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8351 | rv = trans->RestartWithAuth( |
| 8352 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8354 | |
| 8355 | rv = callback2.WaitForResult(); |
| 8356 | EXPECT_EQ(OK, rv); |
| 8357 | |
| 8358 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8359 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8360 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8361 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8362 | } |
| 8363 | |
| 8364 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8365 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8366 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8367 | |
| 8368 | HttpRequestInfo request; |
| 8369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8370 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8371 | request.load_flags = 0; |
| 8372 | |
| 8373 | MockRead proxy_reads[] = { |
| 8374 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8375 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8376 | }; |
| 8377 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8378 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8379 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8380 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8381 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8383 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8384 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8385 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8386 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8387 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8388 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8389 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8392 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8394 | |
| 8395 | rv = callback.WaitForResult(); |
| 8396 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8397 | } |
| 8398 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8399 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8400 | HttpRequestInfo request; |
| 8401 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8402 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8403 | request.load_flags = 0; |
| 8404 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8405 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8406 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8407 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8408 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8409 | MockRead data_reads[] = { |
| 8410 | 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] | 8411 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8412 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8413 | |
| 8414 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8417 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8419 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8420 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8421 | |
| 8422 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8423 | |
| 8424 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8425 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8426 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8427 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8428 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8429 | |
| 8430 | std::string response_data; |
| 8431 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8432 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8433 | } |
| 8434 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8435 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8436 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8437 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8438 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8439 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8440 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8441 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8442 | ScopedVector<UploadElementReader> element_readers; |
| 8443 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8444 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8445 | temp_file_path, |
| 8446 | 0, |
| 8447 | kuint64max, |
| 8448 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8449 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8450 | |
| 8451 | HttpRequestInfo request; |
| 8452 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8453 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8454 | request.upload_data_stream = &upload_data_stream; |
| 8455 | request.load_flags = 0; |
| 8456 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8457 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8458 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8460 | |
| 8461 | MockRead data_reads[] = { |
| 8462 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8463 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8465 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8466 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8469 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8471 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8472 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8473 | |
| 8474 | rv = callback.WaitForResult(); |
| 8475 | EXPECT_EQ(OK, rv); |
| 8476 | |
| 8477 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8478 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8479 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8480 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8481 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8482 | |
| 8483 | std::string response_data; |
| 8484 | rv = ReadTransaction(trans.get(), &response_data); |
| 8485 | EXPECT_EQ(OK, rv); |
| 8486 | EXPECT_EQ("hello world", response_data); |
| 8487 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8488 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8489 | } |
| 8490 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8491 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8492 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8493 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8494 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8495 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8496 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8497 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8498 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8499 | ScopedVector<UploadElementReader> element_readers; |
| 8500 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8501 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8502 | temp_file, |
| 8503 | 0, |
| 8504 | kuint64max, |
| 8505 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8506 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8507 | |
| 8508 | HttpRequestInfo request; |
| 8509 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8510 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8511 | request.upload_data_stream = &upload_data_stream; |
| 8512 | request.load_flags = 0; |
| 8513 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8514 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8515 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8516 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8517 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8518 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8519 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8520 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8521 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8522 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8524 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8526 | |
| 8527 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8528 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8529 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8530 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8531 | } |
| 8532 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8533 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8534 | class FakeUploadElementReader : public UploadElementReader { |
| 8535 | public: |
| 8536 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8537 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8538 | |
| 8539 | const CompletionCallback& callback() const { return callback_; } |
| 8540 | |
| 8541 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8542 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8543 | callback_ = callback; |
| 8544 | return ERR_IO_PENDING; |
| 8545 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8546 | uint64 GetContentLength() const override { return 0; } |
| 8547 | uint64 BytesRemaining() const override { return 0; } |
| 8548 | int Read(IOBuffer* buf, |
| 8549 | int buf_length, |
| 8550 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8551 | return ERR_FAILED; |
| 8552 | } |
| 8553 | |
| 8554 | private: |
| 8555 | CompletionCallback callback_; |
| 8556 | }; |
| 8557 | |
| 8558 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8559 | ScopedVector<UploadElementReader> element_readers; |
| 8560 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8561 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8562 | |
| 8563 | HttpRequestInfo request; |
| 8564 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8565 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8566 | request.upload_data_stream = &upload_data_stream; |
| 8567 | request.load_flags = 0; |
| 8568 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8569 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8570 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8571 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8572 | |
| 8573 | StaticSocketDataProvider data; |
| 8574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8575 | |
| 8576 | TestCompletionCallback callback; |
| 8577 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8578 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8579 | base::MessageLoop::current()->RunUntilIdle(); |
| 8580 | |
| 8581 | // Transaction is pending on request body initialization. |
| 8582 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8583 | |
| 8584 | // Return Init()'s result after the transaction gets destroyed. |
| 8585 | trans.reset(); |
| 8586 | fake_reader->callback().Run(OK); // Should not crash. |
| 8587 | } |
| 8588 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8589 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8590 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8591 | |
| 8592 | HttpRequestInfo request; |
| 8593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8594 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8595 | request.load_flags = 0; |
| 8596 | |
| 8597 | // First transaction will request a resource and receive a Basic challenge |
| 8598 | // with realm="first_realm". |
| 8599 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8600 | MockWrite( |
| 8601 | "GET / HTTP/1.1\r\n" |
| 8602 | "Host: www.example.org\r\n" |
| 8603 | "Connection: keep-alive\r\n" |
| 8604 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8605 | }; |
| 8606 | MockRead data_reads1[] = { |
| 8607 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8608 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8609 | "\r\n"), |
| 8610 | }; |
| 8611 | |
| 8612 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8613 | // for first_realm. The server will reject and provide a challenge with |
| 8614 | // second_realm. |
| 8615 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8616 | MockWrite( |
| 8617 | "GET / HTTP/1.1\r\n" |
| 8618 | "Host: www.example.org\r\n" |
| 8619 | "Connection: keep-alive\r\n" |
| 8620 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8621 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8622 | }; |
| 8623 | MockRead data_reads2[] = { |
| 8624 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8625 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8626 | "\r\n"), |
| 8627 | }; |
| 8628 | |
| 8629 | // This again fails, and goes back to first_realm. Make sure that the |
| 8630 | // entry is removed from cache. |
| 8631 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8632 | MockWrite( |
| 8633 | "GET / HTTP/1.1\r\n" |
| 8634 | "Host: www.example.org\r\n" |
| 8635 | "Connection: keep-alive\r\n" |
| 8636 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8637 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8638 | }; |
| 8639 | MockRead data_reads3[] = { |
| 8640 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8641 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8642 | "\r\n"), |
| 8643 | }; |
| 8644 | |
| 8645 | // Try one last time (with the correct password) and get the resource. |
| 8646 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8647 | MockWrite( |
| 8648 | "GET / HTTP/1.1\r\n" |
| 8649 | "Host: www.example.org\r\n" |
| 8650 | "Connection: keep-alive\r\n" |
| 8651 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8652 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8653 | }; |
| 8654 | MockRead data_reads4[] = { |
| 8655 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8656 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8657 | "Content-Length: 5\r\n" |
| 8658 | "\r\n" |
| 8659 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8660 | }; |
| 8661 | |
| 8662 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8663 | data_writes1, arraysize(data_writes1)); |
| 8664 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8665 | data_writes2, arraysize(data_writes2)); |
| 8666 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8667 | data_writes3, arraysize(data_writes3)); |
| 8668 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8669 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8671 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8672 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8673 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8675 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8676 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8677 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8678 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8679 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8680 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8681 | // Issue the first request with Authorize headers. There should be a |
| 8682 | // password prompt for first_realm waiting to be filled in after the |
| 8683 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8684 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8686 | rv = callback1.WaitForResult(); |
| 8687 | EXPECT_EQ(OK, rv); |
| 8688 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8689 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8690 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8691 | ASSERT_FALSE(challenge == NULL); |
| 8692 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8693 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8694 | EXPECT_EQ("first_realm", challenge->realm); |
| 8695 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8696 | |
| 8697 | // Issue the second request with an incorrect password. There should be a |
| 8698 | // password prompt for second_realm waiting to be filled in after the |
| 8699 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8700 | TestCompletionCallback callback2; |
| 8701 | rv = trans->RestartWithAuth( |
| 8702 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8704 | rv = callback2.WaitForResult(); |
| 8705 | EXPECT_EQ(OK, rv); |
| 8706 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8707 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8708 | challenge = response->auth_challenge.get(); |
| 8709 | ASSERT_FALSE(challenge == NULL); |
| 8710 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8711 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8712 | EXPECT_EQ("second_realm", challenge->realm); |
| 8713 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8714 | |
| 8715 | // Issue the third request with another incorrect password. There should be |
| 8716 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8717 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8718 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8719 | TestCompletionCallback callback3; |
| 8720 | rv = trans->RestartWithAuth( |
| 8721 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8723 | rv = callback3.WaitForResult(); |
| 8724 | EXPECT_EQ(OK, rv); |
| 8725 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8726 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8727 | challenge = response->auth_challenge.get(); |
| 8728 | ASSERT_FALSE(challenge == NULL); |
| 8729 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8730 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8731 | EXPECT_EQ("first_realm", challenge->realm); |
| 8732 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8733 | |
| 8734 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8735 | TestCompletionCallback callback4; |
| 8736 | rv = trans->RestartWithAuth( |
| 8737 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8738 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8739 | rv = callback4.WaitForResult(); |
| 8740 | EXPECT_EQ(OK, rv); |
| 8741 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8742 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8743 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8744 | } |
| 8745 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8746 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8747 | session_deps_.next_protos = SpdyNextProtos(); |
| 8748 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8749 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8750 | std::string alternate_protocol_http_header = |
| 8751 | GetAlternateProtocolHttpHeader(); |
| 8752 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8753 | MockRead data_reads[] = { |
| 8754 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8755 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8756 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8758 | }; |
| 8759 | |
| 8760 | HttpRequestInfo request; |
| 8761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8762 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8763 | request.load_flags = 0; |
| 8764 | |
| 8765 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8766 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8769 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8770 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8771 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8772 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8773 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8775 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8776 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8777 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8778 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8779 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8780 | *session->http_server_properties(); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8781 | AlternativeService alternative_service = |
| 8782 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8783 | EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8784 | |
| 8785 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8786 | |
| 8787 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8788 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8789 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8790 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8791 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8792 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8793 | |
| 8794 | std::string response_data; |
| 8795 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8796 | EXPECT_EQ("hello world", response_data); |
| 8797 | |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8798 | alternative_service = |
| 8799 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8800 | EXPECT_EQ(443, alternative_service.port); |
| 8801 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8802 | alternative_service.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8803 | } |
| 8804 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8805 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 8806 | session_deps_.next_protos = SpdyNextProtos(); |
| 8807 | session_deps_.use_alternate_protocols = true; |
| 8808 | |
| 8809 | MockRead data_reads[] = { |
| 8810 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8811 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 8812 | MockRead("hello world"), |
| 8813 | MockRead(SYNCHRONOUS, OK), |
| 8814 | }; |
| 8815 | |
| 8816 | HttpRequestInfo request; |
| 8817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8818 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8819 | request.load_flags = 0; |
| 8820 | |
| 8821 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8822 | |
| 8823 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8824 | |
| 8825 | TestCompletionCallback callback; |
| 8826 | |
| 8827 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8828 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8829 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8830 | HttpServerProperties& http_server_properties = |
| 8831 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8832 | AlternativeService alternative_service(QUIC, "", 80); |
| 8833 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 8834 | alternative_service, 1.0); |
| 8835 | |
| 8836 | alternative_service = |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8837 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8838 | EXPECT_EQ(alternative_service.protocol, QUIC); |
| 8839 | |
| 8840 | scoped_ptr<HttpTransaction> trans( |
| 8841 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8842 | |
| 8843 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8844 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8845 | |
| 8846 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8847 | |
| 8848 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8849 | ASSERT_TRUE(response != NULL); |
| 8850 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8851 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8852 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8853 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8854 | |
| 8855 | std::string response_data; |
| 8856 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8857 | EXPECT_EQ("hello world", response_data); |
| 8858 | |
| 8859 | alternative_service = |
| 8860 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8861 | EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
| 8862 | } |
| 8863 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8864 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8865 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8866 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8867 | |
| 8868 | HttpRequestInfo request; |
| 8869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8870 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8871 | request.load_flags = 0; |
| 8872 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8873 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8874 | StaticSocketDataProvider first_data; |
| 8875 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8876 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8877 | |
| 8878 | MockRead data_reads[] = { |
| 8879 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8880 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8881 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8882 | }; |
| 8883 | StaticSocketDataProvider second_data( |
| 8884 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8885 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8886 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8887 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8888 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8889 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8890 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 8891 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8892 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8893 | // port 80 (another restricted port). |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8894 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8895 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8896 | 666); /* port is ignored by MockConnect anyway */ |
| 8897 | http_server_properties->SetAlternativeService(host_port_pair, |
| 8898 | alternative_service, 1.0); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8899 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8900 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8901 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8902 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8904 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8906 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8907 | |
| 8908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8909 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8910 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8911 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8912 | |
| 8913 | std::string response_data; |
| 8914 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8915 | EXPECT_EQ("hello world", response_data); |
| 8916 | |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8917 | alternative_service = |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8918 | http_server_properties->GetAlternativeService(host_port_pair); |
| 8919 | EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 8920 | EXPECT_TRUE( |
| 8921 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8922 | } |
| 8923 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8924 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8925 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8926 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8927 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8928 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8929 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8930 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8931 | |
| 8932 | HttpRequestInfo restricted_port_request; |
| 8933 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8934 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8935 | restricted_port_request.load_flags = 0; |
| 8936 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8937 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8938 | StaticSocketDataProvider first_data; |
| 8939 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8940 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8941 | |
| 8942 | MockRead data_reads[] = { |
| 8943 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8944 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8945 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8946 | }; |
| 8947 | StaticSocketDataProvider second_data( |
| 8948 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8949 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8950 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8951 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8952 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8953 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8954 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8955 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8956 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8957 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8958 | kUnrestrictedAlternatePort); |
| 8959 | http_server_properties->SetAlternativeService( |
| 8960 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8961 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8962 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8963 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8965 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8967 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8968 | &restricted_port_request, |
| 8969 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8970 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8971 | // Invalid change to unrestricted port should fail. |
| 8972 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8973 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8974 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8975 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8976 | AlternateProtocolPortRestrictedPermitted) { |
| 8977 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8978 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8979 | // on a restricted port (port < 1024) if we set |
| 8980 | // enable_user_alternate_protocol_ports. |
| 8981 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8982 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8983 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8984 | |
| 8985 | HttpRequestInfo restricted_port_request; |
| 8986 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8987 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8988 | restricted_port_request.load_flags = 0; |
| 8989 | |
| 8990 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8991 | StaticSocketDataProvider first_data; |
| 8992 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8994 | |
| 8995 | MockRead data_reads[] = { |
| 8996 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8997 | MockRead("hello world"), |
| 8998 | MockRead(ASYNC, OK), |
| 8999 | }; |
| 9000 | StaticSocketDataProvider second_data( |
| 9001 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9002 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9003 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9004 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9005 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9006 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9007 | session->http_server_properties(); |
| 9008 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9009 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9010 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9011 | kUnrestrictedAlternatePort); |
| 9012 | http_server_properties->SetAlternativeService( |
| 9013 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9014 | 1.0); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9015 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9016 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9018 | TestCompletionCallback callback; |
| 9019 | |
| 9020 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9021 | &restricted_port_request, |
| 9022 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9023 | // Change to unrestricted port should succeed. |
| 9024 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9025 | } |
| 9026 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9027 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9028 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9029 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9030 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9031 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9032 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9033 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9034 | |
| 9035 | HttpRequestInfo restricted_port_request; |
| 9036 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9037 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9038 | restricted_port_request.load_flags = 0; |
| 9039 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9040 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9041 | StaticSocketDataProvider first_data; |
| 9042 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9043 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9044 | |
| 9045 | MockRead data_reads[] = { |
| 9046 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9047 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9048 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9049 | }; |
| 9050 | StaticSocketDataProvider second_data( |
| 9051 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9052 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9053 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9054 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9055 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9056 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9057 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9058 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9059 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9060 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9061 | kRestrictedAlternatePort); |
| 9062 | http_server_properties->SetAlternativeService( |
| 9063 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9064 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9065 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9066 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9068 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9070 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9071 | &restricted_port_request, |
| 9072 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9073 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9074 | // Valid change to restricted port should pass. |
| 9075 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9076 | } |
| 9077 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9078 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9079 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9080 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9081 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9082 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9083 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9084 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9085 | |
| 9086 | HttpRequestInfo unrestricted_port_request; |
| 9087 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9088 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9089 | unrestricted_port_request.load_flags = 0; |
| 9090 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9091 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9092 | StaticSocketDataProvider first_data; |
| 9093 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9094 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9095 | |
| 9096 | MockRead data_reads[] = { |
| 9097 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9098 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9099 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9100 | }; |
| 9101 | StaticSocketDataProvider second_data( |
| 9102 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9103 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9104 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9105 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9106 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9107 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9108 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9109 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9110 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9111 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9112 | kRestrictedAlternatePort); |
| 9113 | http_server_properties->SetAlternativeService( |
| 9114 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9115 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9116 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9117 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9119 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9121 | int rv = trans->Start( |
| 9122 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9123 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9124 | // Valid change to restricted port should pass. |
| 9125 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9126 | } |
| 9127 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9128 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9129 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9130 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9131 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9132 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9133 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9134 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9135 | |
| 9136 | HttpRequestInfo unrestricted_port_request; |
| 9137 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9138 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9139 | unrestricted_port_request.load_flags = 0; |
| 9140 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9141 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9142 | StaticSocketDataProvider first_data; |
| 9143 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9144 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9145 | |
| 9146 | MockRead data_reads[] = { |
| 9147 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9148 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9149 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9150 | }; |
| 9151 | StaticSocketDataProvider second_data( |
| 9152 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9153 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9154 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9155 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9156 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9157 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9158 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9159 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9160 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9161 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9162 | kUnrestrictedAlternatePort); |
| 9163 | http_server_properties->SetAlternativeService( |
| 9164 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9165 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9166 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9167 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9169 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9171 | int rv = trans->Start( |
| 9172 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9174 | // Valid change to an unrestricted port should pass. |
| 9175 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9176 | } |
| 9177 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9178 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9179 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9180 | // protocol to an unsafe port, and that we resume the second |
| 9181 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9182 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9183 | |
| 9184 | HttpRequestInfo request; |
| 9185 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9186 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9187 | request.load_flags = 0; |
| 9188 | |
| 9189 | // The alternate protocol request will error out before we attempt to connect, |
| 9190 | // so only the standard HTTP request will try to connect. |
| 9191 | MockRead data_reads[] = { |
| 9192 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9193 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9194 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9195 | }; |
| 9196 | StaticSocketDataProvider data( |
| 9197 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9199 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9200 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9201 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9202 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9203 | session->http_server_properties(); |
| 9204 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9205 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9206 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9207 | kUnsafePort); |
| 9208 | http_server_properties->SetAlternativeService( |
| 9209 | HostPortPair::FromURL(request.url), alternative_service, 1.0); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9210 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9211 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9212 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9213 | TestCompletionCallback callback; |
| 9214 | |
| 9215 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9216 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9217 | // The HTTP request should succeed. |
| 9218 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9219 | |
| 9220 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9221 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9222 | |
| 9223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9224 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9225 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9226 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9227 | |
| 9228 | std::string response_data; |
| 9229 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9230 | EXPECT_EQ("hello world", response_data); |
| 9231 | } |
| 9232 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9233 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9234 | session_deps_.use_alternate_protocols = true; |
| 9235 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9236 | |
| 9237 | HttpRequestInfo request; |
| 9238 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9239 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9240 | request.load_flags = 0; |
| 9241 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9242 | std::string alternate_protocol_http_header = |
| 9243 | GetAlternateProtocolHttpHeader(); |
| 9244 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9245 | MockRead data_reads[] = { |
| 9246 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9247 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9248 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9249 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9250 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9251 | }; |
| 9252 | |
| 9253 | StaticSocketDataProvider first_transaction( |
| 9254 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9255 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9256 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9257 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9258 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9259 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9260 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9262 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9263 | scoped_ptr<SpdyFrame> req( |
| 9264 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9265 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9266 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9267 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9268 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9269 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9270 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9271 | }; |
| 9272 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9273 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9274 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9275 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9276 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9277 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9278 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9279 | NULL, 0, NULL, 0); |
| 9280 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9281 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9282 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9283 | &hanging_non_alternate_protocol_socket); |
| 9284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9285 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9286 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9287 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9288 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9293 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9294 | |
| 9295 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9296 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9297 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9298 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9299 | |
| 9300 | std::string response_data; |
| 9301 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9302 | EXPECT_EQ("hello world", response_data); |
| 9303 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9304 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9306 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9307 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9308 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9309 | |
| 9310 | response = trans->GetResponseInfo(); |
| 9311 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9312 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9313 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9314 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9315 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9316 | |
| 9317 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9318 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9319 | } |
| 9320 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9321 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9322 | session_deps_.use_alternate_protocols = true; |
| 9323 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9324 | |
| 9325 | HttpRequestInfo request; |
| 9326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9327 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9328 | request.load_flags = 0; |
| 9329 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9330 | std::string alternate_protocol_http_header = |
| 9331 | GetAlternateProtocolHttpHeader(); |
| 9332 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9333 | MockRead data_reads[] = { |
| 9334 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9335 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9336 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9337 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9338 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9339 | }; |
| 9340 | |
| 9341 | StaticSocketDataProvider first_transaction( |
| 9342 | data_reads, arraysize(data_reads), NULL, 0); |
| 9343 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9344 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9345 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9346 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9347 | StaticSocketDataProvider hanging_socket( |
| 9348 | NULL, 0, NULL, 0); |
| 9349 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9350 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9351 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9352 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9353 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9354 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9355 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9356 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9357 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9358 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9360 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9361 | scoped_ptr<SpdyFrame> req1( |
| 9362 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9363 | scoped_ptr<SpdyFrame> req2( |
| 9364 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9365 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9366 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9367 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9368 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9369 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9370 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9371 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9372 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9373 | CreateMockRead(*resp1, 2), |
| 9374 | CreateMockRead(*data1, 3), |
| 9375 | CreateMockRead(*resp2, 4), |
| 9376 | CreateMockRead(*data2, 5), |
| 9377 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9378 | }; |
| 9379 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9380 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9381 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9382 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9383 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9384 | |
| 9385 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9386 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9387 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9388 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9389 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9390 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9392 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9394 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9395 | |
| 9396 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9397 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9398 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9399 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9400 | |
| 9401 | std::string response_data; |
| 9402 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9403 | EXPECT_EQ("hello world", response_data); |
| 9404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9405 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9406 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9407 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9410 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9411 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9412 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9413 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9414 | |
| 9415 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9416 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9417 | |
| 9418 | response = trans2.GetResponseInfo(); |
| 9419 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9420 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9421 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9422 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9423 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9424 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9425 | EXPECT_EQ("hello!", response_data); |
| 9426 | |
| 9427 | response = trans3.GetResponseInfo(); |
| 9428 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9429 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9430 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9431 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9432 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9433 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9434 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9435 | } |
| 9436 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9437 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9438 | session_deps_.use_alternate_protocols = true; |
| 9439 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9440 | |
| 9441 | HttpRequestInfo request; |
| 9442 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9443 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9444 | request.load_flags = 0; |
| 9445 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9446 | std::string alternate_protocol_http_header = |
| 9447 | GetAlternateProtocolHttpHeader(); |
| 9448 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9449 | MockRead data_reads[] = { |
| 9450 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9451 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9452 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9453 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9454 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9455 | }; |
| 9456 | |
| 9457 | StaticSocketDataProvider first_transaction( |
| 9458 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9459 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9460 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9461 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9462 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9464 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9465 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9466 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9467 | NULL, 0, NULL, 0); |
| 9468 | hanging_alternate_protocol_socket.set_connect_data( |
| 9469 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9470 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9471 | &hanging_alternate_protocol_socket); |
| 9472 | |
| 9473 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9474 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9476 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9477 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9478 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9479 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9482 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9484 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9485 | |
| 9486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9487 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9488 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9489 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9490 | |
| 9491 | std::string response_data; |
| 9492 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9493 | EXPECT_EQ("hello world", response_data); |
| 9494 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9495 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9497 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9499 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9500 | |
| 9501 | response = trans->GetResponseInfo(); |
| 9502 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9503 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9504 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9505 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9506 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9507 | |
| 9508 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9509 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9510 | } |
| 9511 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9512 | class CapturingProxyResolver : public ProxyResolver { |
| 9513 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9514 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9515 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9516 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9517 | int GetProxyForURL(const GURL& url, |
| 9518 | ProxyInfo* results, |
| 9519 | const CompletionCallback& callback, |
| 9520 | RequestHandle* request, |
| 9521 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9522 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9523 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9524 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9525 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9526 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9527 | } |
| 9528 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9529 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9530 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9531 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9532 | NOTREACHED(); |
| 9533 | return LOAD_STATE_IDLE; |
| 9534 | } |
| 9535 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9536 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9537 | |
| 9538 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9539 | std::vector<GURL> resolved_; |
| 9540 | |
| 9541 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9542 | }; |
| 9543 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9544 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9545 | public: |
| 9546 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9547 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9548 | |
| 9549 | int CreateProxyResolver( |
| 9550 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9551 | scoped_ptr<ProxyResolver>* resolver, |
| 9552 | const net::CompletionCallback& callback, |
| 9553 | scoped_ptr<Request>* request) override { |
| 9554 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9555 | return OK; |
| 9556 | } |
| 9557 | |
| 9558 | private: |
| 9559 | ProxyResolver* resolver_; |
| 9560 | }; |
| 9561 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9562 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9563 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9564 | session_deps_.use_alternate_protocols = true; |
| 9565 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9566 | |
| 9567 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9568 | proxy_config.set_auto_detect(true); |
| 9569 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9570 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9571 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9572 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9573 | new ProxyConfigServiceFixed(proxy_config), |
| 9574 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9575 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9576 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9577 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9578 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9579 | |
| 9580 | HttpRequestInfo request; |
| 9581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9582 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9583 | request.load_flags = 0; |
| 9584 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9585 | std::string alternate_protocol_http_header = |
| 9586 | GetAlternateProtocolHttpHeader(); |
| 9587 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9588 | MockRead data_reads[] = { |
| 9589 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9590 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9591 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9592 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9593 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9594 | }; |
| 9595 | |
| 9596 | StaticSocketDataProvider first_transaction( |
| 9597 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9598 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9599 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9600 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9601 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9602 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9603 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9605 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9606 | scoped_ptr<SpdyFrame> req( |
| 9607 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9608 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9609 | MockWrite(ASYNC, 0, |
| 9610 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9611 | "Host: www.example.org\r\n" |
| 9612 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9613 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9614 | }; |
| 9615 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9616 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9617 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9618 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9619 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9620 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9621 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 9622 | CreateMockRead(*resp.get(), 3), |
| 9623 | CreateMockRead(*data.get(), 4), |
| 9624 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9625 | }; |
| 9626 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9627 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9628 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9629 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9630 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9631 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9632 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9633 | NULL, 0, NULL, 0); |
| 9634 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9635 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9636 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9637 | &hanging_non_alternate_protocol_socket); |
| 9638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9639 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9640 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9641 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9642 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9643 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9644 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9645 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9647 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9648 | |
| 9649 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9650 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9651 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9652 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9653 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9654 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9655 | |
| 9656 | std::string response_data; |
| 9657 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9658 | EXPECT_EQ("hello world", response_data); |
| 9659 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9660 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9662 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9664 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9665 | |
| 9666 | response = trans->GetResponseInfo(); |
| 9667 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9668 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9669 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9670 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9671 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9672 | |
| 9673 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9674 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9675 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9676 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9677 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9678 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9679 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9680 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9681 | LoadTimingInfo load_timing_info; |
| 9682 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9683 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9684 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9685 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9686 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9687 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9688 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9689 | session_deps_.use_alternate_protocols = true; |
| 9690 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9691 | |
| 9692 | HttpRequestInfo request; |
| 9693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9695 | request.load_flags = 0; |
| 9696 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9697 | std::string alternate_protocol_http_header = |
| 9698 | GetAlternateProtocolHttpHeader(); |
| 9699 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9700 | MockRead data_reads[] = { |
| 9701 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9702 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9703 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9704 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9705 | }; |
| 9706 | |
| 9707 | StaticSocketDataProvider first_transaction( |
| 9708 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9709 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9710 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9711 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9712 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9713 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9714 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9716 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9717 | scoped_ptr<SpdyFrame> req( |
| 9718 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9719 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9720 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9721 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9722 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9723 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9724 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9725 | }; |
| 9726 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9727 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9728 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9729 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9730 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9731 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9732 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9733 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9734 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9735 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9736 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9738 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9739 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9740 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9741 | |
| 9742 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9743 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9744 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9745 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9746 | |
| 9747 | std::string response_data; |
| 9748 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9749 | EXPECT_EQ("hello world", response_data); |
| 9750 | |
| 9751 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9752 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9753 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9754 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9755 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9756 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9757 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9758 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9760 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9762 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9763 | |
| 9764 | response = trans->GetResponseInfo(); |
| 9765 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9766 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9767 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9768 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9769 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9770 | |
| 9771 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9772 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9773 | } |
| 9774 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9775 | // GenerateAuthToken is a mighty big test. |
| 9776 | // It tests all permutation of GenerateAuthToken behavior: |
| 9777 | // - Synchronous and Asynchronous completion. |
| 9778 | // - OK or error on completion. |
| 9779 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9780 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9781 | // - Non-authenticating and authenticating backend. |
| 9782 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9783 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9784 | // problems generating an auth token for an authenticating proxy, we don't |
| 9785 | // need to test all permutations of the backend server). |
| 9786 | // |
| 9787 | // The test proceeds by going over each of the configuration cases, and |
| 9788 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9789 | // specifies both the configuration for the test as well as the expectations |
| 9790 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9791 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9792 | static const char kServer[] = "http://www.example.com"; |
| 9793 | static const char kSecureServer[] = "https://www.example.com"; |
| 9794 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9795 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9796 | |
| 9797 | enum AuthTiming { |
| 9798 | AUTH_NONE, |
| 9799 | AUTH_SYNC, |
| 9800 | AUTH_ASYNC, |
| 9801 | }; |
| 9802 | |
| 9803 | const MockWrite kGet( |
| 9804 | "GET / HTTP/1.1\r\n" |
| 9805 | "Host: www.example.com\r\n" |
| 9806 | "Connection: keep-alive\r\n\r\n"); |
| 9807 | const MockWrite kGetProxy( |
| 9808 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9809 | "Host: www.example.com\r\n" |
| 9810 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9811 | const MockWrite kGetAuth( |
| 9812 | "GET / HTTP/1.1\r\n" |
| 9813 | "Host: www.example.com\r\n" |
| 9814 | "Connection: keep-alive\r\n" |
| 9815 | "Authorization: auth_token\r\n\r\n"); |
| 9816 | const MockWrite kGetProxyAuth( |
| 9817 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9818 | "Host: www.example.com\r\n" |
| 9819 | "Proxy-Connection: keep-alive\r\n" |
| 9820 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9821 | const MockWrite kGetAuthThroughProxy( |
| 9822 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9823 | "Host: www.example.com\r\n" |
| 9824 | "Proxy-Connection: keep-alive\r\n" |
| 9825 | "Authorization: auth_token\r\n\r\n"); |
| 9826 | const MockWrite kGetAuthWithProxyAuth( |
| 9827 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9828 | "Host: www.example.com\r\n" |
| 9829 | "Proxy-Connection: keep-alive\r\n" |
| 9830 | "Proxy-Authorization: auth_token\r\n" |
| 9831 | "Authorization: auth_token\r\n\r\n"); |
| 9832 | const MockWrite kConnect( |
| 9833 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9834 | "Host: www.example.com\r\n" |
| 9835 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9836 | const MockWrite kConnectProxyAuth( |
| 9837 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9838 | "Host: www.example.com\r\n" |
| 9839 | "Proxy-Connection: keep-alive\r\n" |
| 9840 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9841 | |
| 9842 | const MockRead kSuccess( |
| 9843 | "HTTP/1.1 200 OK\r\n" |
| 9844 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9845 | "Content-Length: 3\r\n\r\n" |
| 9846 | "Yes"); |
| 9847 | const MockRead kFailure( |
| 9848 | "Should not be called."); |
| 9849 | const MockRead kServerChallenge( |
| 9850 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9851 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9852 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9853 | "Content-Length: 14\r\n\r\n" |
| 9854 | "Unauthorized\r\n"); |
| 9855 | const MockRead kProxyChallenge( |
| 9856 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9857 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9858 | "Proxy-Connection: close\r\n" |
| 9859 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9860 | "Content-Length: 14\r\n\r\n" |
| 9861 | "Unauthorized\r\n"); |
| 9862 | const MockRead kProxyConnected( |
| 9863 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9864 | |
| 9865 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9866 | // no constructors, but the C++ compiler on Windows warns about |
| 9867 | // unspecified data in compound literals. So, moved to using constructors, |
| 9868 | // and TestRound's created with the default constructor should not be used. |
| 9869 | struct TestRound { |
| 9870 | TestRound() |
| 9871 | : expected_rv(ERR_UNEXPECTED), |
| 9872 | extra_write(NULL), |
| 9873 | extra_read(NULL) { |
| 9874 | } |
| 9875 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9876 | int expected_rv_arg) |
| 9877 | : write(write_arg), |
| 9878 | read(read_arg), |
| 9879 | expected_rv(expected_rv_arg), |
| 9880 | extra_write(NULL), |
| 9881 | extra_read(NULL) { |
| 9882 | } |
| 9883 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9884 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9885 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9886 | : write(write_arg), |
| 9887 | read(read_arg), |
| 9888 | expected_rv(expected_rv_arg), |
| 9889 | extra_write(extra_write_arg), |
| 9890 | extra_read(extra_read_arg) { |
| 9891 | } |
| 9892 | MockWrite write; |
| 9893 | MockRead read; |
| 9894 | int expected_rv; |
| 9895 | const MockWrite* extra_write; |
| 9896 | const MockRead* extra_read; |
| 9897 | }; |
| 9898 | |
| 9899 | static const int kNoSSL = 500; |
| 9900 | |
| 9901 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9902 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9903 | AuthTiming proxy_auth_timing; |
| 9904 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9905 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9906 | AuthTiming server_auth_timing; |
| 9907 | int server_auth_rv; |
| 9908 | int num_auth_rounds; |
| 9909 | int first_ssl_round; |
| 9910 | TestRound rounds[3]; |
| 9911 | } test_configs[] = { |
| 9912 | // Non-authenticating HTTP server with a direct connection. |
| 9913 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9914 | { TestRound(kGet, kSuccess, OK)}}, |
| 9915 | // Authenticating HTTP server with a direct connection. |
| 9916 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9917 | { TestRound(kGet, kServerChallenge, OK), |
| 9918 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9919 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9920 | { TestRound(kGet, kServerChallenge, OK), |
| 9921 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9922 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9923 | { TestRound(kGet, kServerChallenge, OK), |
| 9924 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9925 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9926 | { TestRound(kGet, kServerChallenge, OK), |
| 9927 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9928 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9929 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9930 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9931 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9932 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9933 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9934 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9935 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9936 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9937 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9938 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9939 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9940 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9941 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9942 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9943 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9944 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9945 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9946 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9947 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9948 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9949 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9950 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9951 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9952 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9953 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9954 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9955 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9956 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9957 | // Authenticating HTTP server through an authenticating proxy. |
| 9958 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9959 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9960 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9961 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9962 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9963 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9964 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9965 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9966 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9967 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9968 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9969 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9970 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9971 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9972 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9973 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9974 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9975 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9976 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9977 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9978 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9979 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9980 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9981 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9982 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9983 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9984 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9985 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9986 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9987 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9988 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9989 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9990 | // Non-authenticating HTTPS server with a direct connection. |
| 9991 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9992 | { TestRound(kGet, kSuccess, OK)}}, |
| 9993 | // Authenticating HTTPS server with a direct connection. |
| 9994 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9995 | { TestRound(kGet, kServerChallenge, OK), |
| 9996 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9997 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9998 | { TestRound(kGet, kServerChallenge, OK), |
| 9999 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10000 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10001 | { TestRound(kGet, kServerChallenge, OK), |
| 10002 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10003 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10004 | { TestRound(kGet, kServerChallenge, OK), |
| 10005 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10006 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10007 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10008 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10009 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10010 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10011 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10012 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10013 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10014 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10015 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10016 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10017 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10018 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10019 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10020 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10021 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10022 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10023 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10024 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10025 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10026 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10027 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10028 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10029 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10030 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10031 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10032 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10033 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10034 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10035 | // Authenticating HTTPS server through an authenticating proxy. |
| 10036 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10037 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10038 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10039 | &kGet, &kServerChallenge), |
| 10040 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10041 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10042 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10043 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10044 | &kGet, &kServerChallenge), |
| 10045 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10046 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10047 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10048 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10049 | &kGet, &kServerChallenge), |
| 10050 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10051 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10052 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10053 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10054 | &kGet, &kServerChallenge), |
| 10055 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10056 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10057 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10058 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10059 | &kGet, &kServerChallenge), |
| 10060 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10061 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10062 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10063 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10064 | &kGet, &kServerChallenge), |
| 10065 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10066 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10067 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10068 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10069 | &kGet, &kServerChallenge), |
| 10070 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10071 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10072 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10073 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10074 | &kGet, &kServerChallenge), |
| 10075 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10076 | }; |
| 10077 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10078 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10079 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10080 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10081 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10082 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10083 | |
| 10084 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10085 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10086 | for (int n = 0; n < 2; n++) { |
| 10087 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10088 | std::string auth_challenge = "Mock realm=proxy"; |
| 10089 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10090 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10091 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10092 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10093 | origin, BoundNetLog()); |
| 10094 | auth_handler->SetGenerateExpectation( |
| 10095 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10096 | test_config.proxy_auth_rv); |
| 10097 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10098 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10099 | } |
| 10100 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10101 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10102 | std::string auth_challenge = "Mock realm=server"; |
| 10103 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10104 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10105 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10106 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10107 | origin, BoundNetLog()); |
| 10108 | auth_handler->SetGenerateExpectation( |
| 10109 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10110 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10111 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10112 | } |
| 10113 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10114 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10115 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10116 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10117 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10118 | } |
| 10119 | |
| 10120 | HttpRequestInfo request; |
| 10121 | request.method = "GET"; |
| 10122 | request.url = GURL(test_config.server_url); |
| 10123 | request.load_flags = 0; |
| 10124 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10125 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10127 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10128 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10129 | |
| 10130 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10131 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10132 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10133 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10134 | |
| 10135 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10136 | mock_reads.back().push_back(read_write_round.read); |
| 10137 | mock_writes.back().push_back(read_write_round.write); |
| 10138 | |
| 10139 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10140 | // socket is closed and a new one will be created for the next request. |
| 10141 | if (read_write_round.read.data == kProxyChallenge.data && |
| 10142 | read_write_round.write.data != kConnect.data) { |
| 10143 | mock_reads.push_back(std::vector<MockRead>()); |
| 10144 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10145 | } |
| 10146 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10147 | if (read_write_round.extra_read) { |
| 10148 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10149 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10150 | if (read_write_round.extra_write) { |
| 10151 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10152 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10153 | |
| 10154 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10155 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10156 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10157 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10158 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10159 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10160 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10161 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10162 | data_providers.push_back(new StaticSocketDataProvider( |
| 10163 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10164 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10165 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10166 | data_providers.back()); |
| 10167 | } |
| 10168 | |
| 10169 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10170 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10171 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10172 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10173 | int rv; |
| 10174 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10175 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10176 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10177 | rv = trans.RestartWithAuth( |
| 10178 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10179 | } |
| 10180 | if (rv == ERR_IO_PENDING) |
| 10181 | rv = callback.WaitForResult(); |
| 10182 | |
| 10183 | // Compare results with expected data. |
| 10184 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10185 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10186 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10187 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10188 | continue; |
| 10189 | } |
| 10190 | if (round + 1 < test_config.num_auth_rounds) { |
| 10191 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10192 | } else { |
| 10193 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10194 | } |
| 10195 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10196 | } |
| 10197 | } |
| 10198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10199 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10200 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10201 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10202 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10203 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10204 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10205 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10206 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10207 | |
| 10208 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10209 | auth_handler->set_connection_based(true); |
| 10210 | std::string auth_challenge = "Mock realm=server"; |
| 10211 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10212 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10213 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10214 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10215 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10216 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10217 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10218 | int rv = OK; |
| 10219 | const HttpResponseInfo* response = NULL; |
| 10220 | HttpRequestInfo request; |
| 10221 | request.method = "GET"; |
| 10222 | request.url = origin; |
| 10223 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10224 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10225 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10226 | |
| 10227 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10228 | // to validate that the TCP socket is not released to the pool between |
| 10229 | // each round of multi-round authentication. |
| 10230 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10231 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10232 | 50, // Max sockets for pool |
| 10233 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10234 | session_deps_.host_resolver.get(), |
| 10235 | session_deps_.socket_factory.get(), |
| 10236 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10237 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10238 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10239 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10240 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10241 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10242 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10243 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10244 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10245 | |
| 10246 | const MockWrite kGet( |
| 10247 | "GET / HTTP/1.1\r\n" |
| 10248 | "Host: www.example.com\r\n" |
| 10249 | "Connection: keep-alive\r\n\r\n"); |
| 10250 | const MockWrite kGetAuth( |
| 10251 | "GET / HTTP/1.1\r\n" |
| 10252 | "Host: www.example.com\r\n" |
| 10253 | "Connection: keep-alive\r\n" |
| 10254 | "Authorization: auth_token\r\n\r\n"); |
| 10255 | |
| 10256 | const MockRead kServerChallenge( |
| 10257 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10258 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10259 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10260 | "Content-Length: 14\r\n\r\n" |
| 10261 | "Unauthorized\r\n"); |
| 10262 | const MockRead kSuccess( |
| 10263 | "HTTP/1.1 200 OK\r\n" |
| 10264 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10265 | "Content-Length: 3\r\n\r\n" |
| 10266 | "Yes"); |
| 10267 | |
| 10268 | MockWrite writes[] = { |
| 10269 | // First round |
| 10270 | kGet, |
| 10271 | // Second round |
| 10272 | kGetAuth, |
| 10273 | // Third round |
| 10274 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10275 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10276 | kGetAuth, |
| 10277 | // Competing request |
| 10278 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10279 | }; |
| 10280 | MockRead reads[] = { |
| 10281 | // First round |
| 10282 | kServerChallenge, |
| 10283 | // Second round |
| 10284 | kServerChallenge, |
| 10285 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10286 | kServerChallenge, |
| 10287 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10288 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10289 | // Competing response |
| 10290 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10291 | }; |
| 10292 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10293 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10294 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10295 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10296 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10297 | |
| 10298 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10299 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10300 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10301 | if (rv == ERR_IO_PENDING) |
| 10302 | rv = callback.WaitForResult(); |
| 10303 | EXPECT_EQ(OK, rv); |
| 10304 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10305 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10306 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10307 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10308 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10309 | // In between rounds, another request comes in for the same domain. |
| 10310 | // It should not be able to grab the TCP socket that trans has already |
| 10311 | // claimed. |
| 10312 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10313 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10314 | TestCompletionCallback callback_compete; |
| 10315 | rv = trans_compete->Start( |
| 10316 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10317 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10318 | // callback_compete.WaitForResult at this point would stall forever, |
| 10319 | // since the HttpNetworkTransaction does not release the request back to |
| 10320 | // the pool until after authentication completes. |
| 10321 | |
| 10322 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10323 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10324 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10325 | if (rv == ERR_IO_PENDING) |
| 10326 | rv = callback.WaitForResult(); |
| 10327 | EXPECT_EQ(OK, rv); |
| 10328 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10329 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10330 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10331 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10332 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10333 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10334 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10335 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10336 | if (rv == ERR_IO_PENDING) |
| 10337 | rv = callback.WaitForResult(); |
| 10338 | EXPECT_EQ(OK, rv); |
| 10339 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10340 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10341 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10342 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10343 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10344 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10345 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10346 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10347 | if (rv == ERR_IO_PENDING) |
| 10348 | rv = callback.WaitForResult(); |
| 10349 | EXPECT_EQ(OK, rv); |
| 10350 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10351 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10352 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10353 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10354 | |
| 10355 | // Read the body since the fourth round was successful. This will also |
| 10356 | // release the socket back to the pool. |
| 10357 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10358 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10359 | if (rv == ERR_IO_PENDING) |
| 10360 | rv = callback.WaitForResult(); |
| 10361 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10362 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10363 | EXPECT_EQ(0, rv); |
| 10364 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10365 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10366 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10367 | |
| 10368 | // The competing request can now finish. Wait for the headers and then |
| 10369 | // read the body. |
| 10370 | rv = callback_compete.WaitForResult(); |
| 10371 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10372 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10373 | if (rv == ERR_IO_PENDING) |
| 10374 | rv = callback.WaitForResult(); |
| 10375 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10376 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10377 | EXPECT_EQ(0, rv); |
| 10378 | |
| 10379 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10380 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10381 | } |
| 10382 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10383 | // This tests the case that a request is issued via http instead of spdy after |
| 10384 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10385 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10386 | session_deps_.use_alternate_protocols = true; |
| 10387 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10388 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10389 | session_deps_.next_protos = next_protos; |
| 10390 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10391 | HttpRequestInfo request; |
| 10392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10393 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10394 | request.load_flags = 0; |
| 10395 | |
| 10396 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10397 | MockWrite( |
| 10398 | "GET / HTTP/1.1\r\n" |
| 10399 | "Host: www.example.org\r\n" |
| 10400 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10401 | }; |
| 10402 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10403 | std::string alternate_protocol_http_header = |
| 10404 | GetAlternateProtocolHttpHeader(); |
| 10405 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10406 | MockRead data_reads[] = { |
| 10407 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10408 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10409 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10410 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10411 | }; |
| 10412 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10413 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10414 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10415 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10417 | |
| 10418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10419 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10422 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10423 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10424 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10425 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10426 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10428 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10429 | |
| 10430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10431 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10432 | |
| 10433 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10434 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10435 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10436 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10437 | |
| 10438 | std::string response_data; |
| 10439 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10440 | EXPECT_EQ("hello world", response_data); |
| 10441 | |
| 10442 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10443 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10444 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10445 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10446 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10447 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10448 | // followed by an immediate server closing of the socket. |
| 10449 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10450 | session_deps_.use_alternate_protocols = true; |
| 10451 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10452 | |
| 10453 | HttpRequestInfo request; |
| 10454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10455 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10456 | request.load_flags = 0; |
| 10457 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10458 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10459 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10461 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10462 | scoped_ptr<SpdyFrame> req( |
| 10463 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10464 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10465 | |
| 10466 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10467 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10468 | }; |
| 10469 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10470 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10471 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10472 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10474 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10475 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10476 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10477 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10478 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10480 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10482 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10483 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10484 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10485 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10486 | // it gets it. This is needed since the auth handler may get destroyed |
| 10487 | // before we get a chance to query it. |
| 10488 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10489 | public: |
| 10490 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10492 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10493 | |
| 10494 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10495 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10496 | const HttpRequestInfo* request, |
| 10497 | const CompletionCallback& callback, |
| 10498 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10499 | *url_ = request->url; |
| 10500 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10501 | credentials, request, callback, auth_token); |
| 10502 | } |
| 10503 | |
| 10504 | private: |
| 10505 | GURL* url_; |
| 10506 | }; |
| 10507 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10508 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10509 | // This test ensures that the URL passed into the proxy is upgraded |
| 10510 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10511 | session_deps_.use_alternate_protocols = true; |
| 10512 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10513 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10514 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10515 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10516 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10517 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10518 | GURL request_url; |
| 10519 | { |
| 10520 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10521 | new HttpAuthHandlerMock::Factory(); |
| 10522 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10523 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10524 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10525 | auth_factory->set_do_init_from_challenge(true); |
| 10526 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10527 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10528 | |
| 10529 | HttpRequestInfo request; |
| 10530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10531 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10532 | request.load_flags = 0; |
| 10533 | |
| 10534 | // First round goes unauthenticated through the proxy. |
| 10535 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10536 | MockWrite( |
| 10537 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10538 | "Host: www.example.org\r\n" |
| 10539 | "Proxy-Connection: keep-alive\r\n" |
| 10540 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10541 | }; |
| 10542 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10543 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10544 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10545 | MockRead("Alternate-Protocol: 443:"), |
| 10546 | MockRead(GetAlternateProtocolFromParam()), |
| 10547 | MockRead("\r\n"), |
| 10548 | MockRead("Proxy-Connection: close\r\n"), |
| 10549 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10550 | }; |
| 10551 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10552 | data_writes_1, arraysize(data_writes_1)); |
| 10553 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10554 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10555 | // Alternate-Protocol announcement in the first round. It fails due |
| 10556 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10557 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10558 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10559 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10560 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10561 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10562 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10563 | // to obtain a new one. |
| 10564 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10565 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10566 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10567 | // establishment and SPDY framing issues. Alas, the |
| 10568 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10569 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10570 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10571 | scoped_ptr<SpdyFrame> req( |
| 10572 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10573 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10574 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10575 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10576 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10577 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10578 | MockWrite(ASYNC, 0, |
| 10579 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10580 | "Host: www.example.org\r\n" |
| 10581 | "Proxy-Connection: keep-alive\r\n" |
| 10582 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10583 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10584 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10585 | MockWrite(ASYNC, 2, |
| 10586 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10587 | "Host: www.example.org\r\n" |
| 10588 | "Proxy-Connection: keep-alive\r\n" |
| 10589 | "Proxy-Authorization: auth_token\r\n" |
| 10590 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10591 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10592 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10593 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10594 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10595 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10596 | "Proxy-Authenticate: Mock\r\n" |
| 10597 | "Proxy-Connection: close\r\n" |
| 10598 | "\r\n"); |
| 10599 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10600 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10601 | // First connection attempt fails |
| 10602 | MockRead(ASYNC, kRejectConnectResponse, |
| 10603 | arraysize(kRejectConnectResponse) - 1, 1), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10604 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10605 | // Second connection attempt passes |
| 10606 | MockRead(ASYNC, kAcceptConnectResponse, |
| 10607 | arraysize(kAcceptConnectResponse) - 1, 3), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10608 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10609 | // SPDY response |
| 10610 | CreateMockRead(*resp.get(), 5), |
| 10611 | CreateMockRead(*data.get(), 6), |
| 10612 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10613 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10614 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 10615 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10616 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10617 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10618 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10619 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10620 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10621 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10622 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10623 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10624 | NULL, 0, NULL, 0); |
| 10625 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10626 | never_finishing_connect); |
| 10627 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10628 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10629 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10631 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10632 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10633 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10634 | |
| 10635 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10636 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10637 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10638 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10639 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10641 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10642 | |
| 10643 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10644 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10645 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10646 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10647 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10648 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10649 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10650 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10651 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10652 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10653 | |
| 10654 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10655 | TestCompletionCallback callback_3; |
| 10656 | rv = trans_2->RestartWithAuth( |
| 10657 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10659 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10660 | |
| 10661 | // After all that work, these two lines (or actually, just the scheme) are |
| 10662 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10663 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10664 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10665 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10666 | LoadTimingInfo load_timing_info; |
| 10667 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10668 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10669 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10670 | } |
| 10671 | |
| 10672 | // Test that if we cancel the transaction as the connection is completing, that |
| 10673 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10674 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10675 | // Setup everything about the connection to complete synchronously, so that |
| 10676 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10677 | // for is the callback from the HttpStreamRequest. |
| 10678 | // Then cancel the transaction. |
| 10679 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10680 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10681 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10682 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10683 | MockRead(SYNCHRONOUS, "hello world"), |
| 10684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10685 | }; |
| 10686 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10687 | HttpRequestInfo request; |
| 10688 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10689 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10690 | request.load_flags = 0; |
| 10691 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10692 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10693 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10694 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10696 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10698 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10701 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10702 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10703 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10704 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10705 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10706 | trans.reset(); // Cancel the transaction here. |
| 10707 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10708 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10709 | } |
| 10710 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10711 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10712 | // stream is drained properly and added back to the socket pool. The main |
| 10713 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10714 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10715 | // deleted. |
| 10716 | // See http://crbug.com/368418 |
| 10717 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10718 | MockRead data_reads[] = { |
| 10719 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10720 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10721 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10722 | MockRead(ASYNC, "1"), |
| 10723 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10724 | // HttpNetworkTransaction has been deleted. |
| 10725 | MockRead(ASYNC, "2"), |
| 10726 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10727 | }; |
| 10728 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10730 | |
| 10731 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10732 | |
| 10733 | { |
| 10734 | HttpRequestInfo request; |
| 10735 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10736 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10737 | request.load_flags = 0; |
| 10738 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10740 | TestCompletionCallback callback; |
| 10741 | |
| 10742 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10744 | callback.WaitForResult(); |
| 10745 | |
| 10746 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10747 | ASSERT_TRUE(response != NULL); |
| 10748 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10749 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10750 | |
| 10751 | // The transaction and HttpRequestInfo are deleted. |
| 10752 | } |
| 10753 | |
| 10754 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10755 | base::MessageLoop::current()->RunUntilIdle(); |
| 10756 | |
| 10757 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10758 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10759 | } |
| 10760 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10761 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10762 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10763 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10764 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10765 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10766 | session_deps_.net_log = log.bound().net_log(); |
| 10767 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10768 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10769 | HttpRequestInfo request; |
| 10770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10771 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10772 | |
| 10773 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10774 | MockWrite( |
| 10775 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10776 | "Host: www.example.org\r\n" |
| 10777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10778 | }; |
| 10779 | |
| 10780 | MockRead data_reads1[] = { |
| 10781 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10782 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10783 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10785 | }; |
| 10786 | |
| 10787 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10788 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10789 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10791 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10792 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10793 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10795 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10796 | trans->SetBeforeProxyHeadersSentCallback( |
| 10797 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10798 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10799 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10800 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10801 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10802 | |
| 10803 | rv = callback1.WaitForResult(); |
| 10804 | EXPECT_EQ(OK, rv); |
| 10805 | |
| 10806 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10807 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10808 | |
| 10809 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10810 | EXPECT_EQ(200, response->headers->response_code()); |
| 10811 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10812 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10813 | EXPECT_TRUE( |
| 10814 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10815 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10816 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10817 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10818 | |
| 10819 | LoadTimingInfo load_timing_info; |
| 10820 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10821 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10822 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10823 | } |
| 10824 | |
| 10825 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10826 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10827 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10828 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10830 | session_deps_.net_log = log.bound().net_log(); |
| 10831 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10832 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10833 | HttpRequestInfo request; |
| 10834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10835 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10836 | |
| 10837 | // Since we have proxy, should try to establish tunnel. |
| 10838 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10839 | MockWrite( |
| 10840 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10841 | "Host: www.example.org\r\n" |
| 10842 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10843 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10844 | MockWrite( |
| 10845 | "GET / HTTP/1.1\r\n" |
| 10846 | "Host: www.example.org\r\n" |
| 10847 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10848 | }; |
| 10849 | |
| 10850 | MockRead data_reads1[] = { |
| 10851 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10852 | |
| 10853 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10854 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10855 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10856 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10857 | }; |
| 10858 | |
| 10859 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10860 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10861 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10862 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10865 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10866 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10867 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10868 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10870 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10871 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10872 | |
| 10873 | rv = callback1.WaitForResult(); |
| 10874 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10875 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10876 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10877 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10878 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10879 | NetLog::PHASE_NONE); |
| 10880 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10881 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10882 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10883 | NetLog::PHASE_NONE); |
| 10884 | |
| 10885 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10886 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10887 | |
| 10888 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10889 | EXPECT_EQ(200, response->headers->response_code()); |
| 10890 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10891 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10892 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10893 | EXPECT_TRUE( |
| 10894 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10895 | |
| 10896 | LoadTimingInfo load_timing_info; |
| 10897 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10898 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10899 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10900 | } |
| 10901 | |
| 10902 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10903 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10904 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10905 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10906 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10907 | session_deps_.net_log = log.bound().net_log(); |
| 10908 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10909 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10910 | HttpRequestInfo request; |
| 10911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10912 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10913 | |
| 10914 | // Since we have proxy, should try to establish tunnel. |
| 10915 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10916 | MockWrite( |
| 10917 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10918 | "Host: www.example.org\r\n" |
| 10919 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10920 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10921 | MockWrite( |
| 10922 | "GET / HTTP/1.1\r\n" |
| 10923 | "Host: www.example.org\r\n" |
| 10924 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10925 | }; |
| 10926 | |
| 10927 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10928 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10929 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10930 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10931 | }; |
| 10932 | |
| 10933 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10934 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10935 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10936 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10939 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10940 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10941 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10942 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10943 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10944 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10945 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10946 | |
| 10947 | rv = callback1.WaitForResult(); |
| 10948 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10949 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10950 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10951 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10952 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10953 | NetLog::PHASE_NONE); |
| 10954 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10955 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10956 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10957 | NetLog::PHASE_NONE); |
| 10958 | } |
| 10959 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10960 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10961 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10962 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10963 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10964 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10965 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10966 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10967 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10968 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10969 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10970 | }; |
| 10971 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10972 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10973 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10974 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10975 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10976 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10977 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10979 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10980 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10981 | |
| 10982 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10983 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10984 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10985 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10986 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10987 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10988 | |
| 10989 | HttpRequestInfo request; |
| 10990 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10991 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10992 | request.load_flags = 0; |
| 10993 | |
| 10994 | // This is the important line that marks this as a preconnect. |
| 10995 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10996 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10997 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10998 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10999 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11000 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11001 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11003 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11004 | } |
| 11005 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11006 | // Given a net error, cause that error to be returned from the first Write() |
| 11007 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11008 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11009 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11010 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11011 | request_info.url = GURL("https://www.example.com/"); |
| 11012 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11013 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11014 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11015 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11016 | MockWrite data_writes[] = { |
| 11017 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11018 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11019 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11022 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11023 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11024 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11025 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11027 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11028 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11029 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11030 | rv = callback.WaitForResult(); |
| 11031 | ASSERT_EQ(error, rv); |
| 11032 | } |
| 11033 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11034 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11035 | // Just check a grab bag of cert errors. |
| 11036 | static const int kErrors[] = { |
| 11037 | ERR_CERT_COMMON_NAME_INVALID, |
| 11038 | ERR_CERT_AUTHORITY_INVALID, |
| 11039 | ERR_CERT_DATE_INVALID, |
| 11040 | }; |
| 11041 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11042 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11043 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11044 | } |
| 11045 | } |
| 11046 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11047 | // Ensure that a client certificate is removed from the SSL client auth |
| 11048 | // cache when: |
| 11049 | // 1) No proxy is involved. |
| 11050 | // 2) TLS False Start is disabled. |
| 11051 | // 3) The initial TLS handshake requests a client certificate. |
| 11052 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11053 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11054 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11055 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11056 | request_info.url = GURL("https://www.example.com/"); |
| 11057 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11058 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11059 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11060 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11061 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11062 | |
| 11063 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11064 | // CertificateRequest is received for the first time, the handshake will |
| 11065 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11066 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11067 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11069 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11070 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11071 | |
| 11072 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11073 | // False Start is not being used, the result of the SSL handshake will be |
| 11074 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11075 | // matches the result of a server sending a handshake_failure alert, |
| 11076 | // rather than a Finished message, because it requires a client |
| 11077 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11078 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11079 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11081 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11082 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11083 | |
| 11084 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11085 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11086 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11087 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11088 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11089 | // requiring a client certificate, this fallback handshake should also |
| 11090 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11091 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11092 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11094 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11095 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11096 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11097 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11098 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11099 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11100 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11101 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11102 | // requiring a client certificate, this fallback handshake should also |
| 11103 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11104 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11105 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11107 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11108 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11109 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11110 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11111 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11112 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11113 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11114 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11115 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11116 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11117 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11118 | |
| 11119 | // Complete the SSL handshake, which should abort due to requiring a |
| 11120 | // client certificate. |
| 11121 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11122 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11123 | |
| 11124 | // Indicate that no certificate should be supplied. From the perspective |
| 11125 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11126 | // certificate, so this is the same as supply a |
| 11127 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11128 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11129 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11130 | |
| 11131 | // Ensure the certificate was added to the client auth cache before |
| 11132 | // allowing the connection to continue restarting. |
| 11133 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11134 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11135 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11136 | ASSERT_EQ(NULL, client_cert.get()); |
| 11137 | |
| 11138 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11139 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11140 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11141 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11142 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11143 | |
| 11144 | // Ensure that the client certificate is removed from the cache on a |
| 11145 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11146 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11147 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11148 | } |
| 11149 | |
| 11150 | // Ensure that a client certificate is removed from the SSL client auth |
| 11151 | // cache when: |
| 11152 | // 1) No proxy is involved. |
| 11153 | // 2) TLS False Start is enabled. |
| 11154 | // 3) The initial TLS handshake requests a client certificate. |
| 11155 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11156 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11157 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11158 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11159 | request_info.url = GURL("https://www.example.com/"); |
| 11160 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11161 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11162 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11163 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11164 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11165 | |
| 11166 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11167 | // return successfully after reading up to the peer's Certificate message. |
| 11168 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11169 | // enqueue application data to be sent in the same packet as the |
| 11170 | // ChangeCipherSpec and Finished messages. |
| 11171 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11172 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11173 | // Finished messages. If there was an error negotiating with the peer, |
| 11174 | // such as due to the peer requiring a client certificate when none was |
| 11175 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11176 | // called. |
| 11177 | |
| 11178 | // Like the non-False Start case, when a client certificate is requested by |
| 11179 | // the peer, the handshake is aborted during the Connect() call. |
| 11180 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11181 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11182 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11184 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11186 | |
| 11187 | // When a client certificate is supplied, Connect() will not be aborted |
| 11188 | // when the peer requests the certificate. Instead, the handshake will |
| 11189 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11190 | // the socket. The handshake messages are not processed until Read() is |
| 11191 | // called, which then detects that the handshake was aborted, due to the |
| 11192 | // peer sending a handshake_failure because it requires a client |
| 11193 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11194 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11195 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11197 | MockRead data2_reads[] = { |
| 11198 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11199 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11200 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11201 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11202 | |
| 11203 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11204 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11205 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11206 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11207 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11209 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11210 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11211 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11212 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11213 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11214 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11215 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11217 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11218 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11219 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11220 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11221 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11222 | ssl_data5.cert_request_info = cert_request.get(); |
| 11223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11224 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11225 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11226 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11227 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11228 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11229 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11230 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11231 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11232 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11233 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11234 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11235 | |
| 11236 | // Complete the SSL handshake, which should abort due to requiring a |
| 11237 | // client certificate. |
| 11238 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11239 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11240 | |
| 11241 | // Indicate that no certificate should be supplied. From the perspective |
| 11242 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11243 | // certificate, so this is the same as supply a |
| 11244 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11245 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11246 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11247 | |
| 11248 | // Ensure the certificate was added to the client auth cache before |
| 11249 | // allowing the connection to continue restarting. |
| 11250 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11251 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11252 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11253 | ASSERT_EQ(NULL, client_cert.get()); |
| 11254 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11255 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11256 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11257 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11258 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11259 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11260 | |
| 11261 | // Ensure that the client certificate is removed from the cache on a |
| 11262 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11263 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11264 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11265 | } |
| 11266 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11267 | // Ensure that a client certificate is removed from the SSL client auth |
| 11268 | // cache when: |
| 11269 | // 1) An HTTPS proxy is involved. |
| 11270 | // 3) The HTTPS proxy requests a client certificate. |
| 11271 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11272 | // proxy. |
| 11273 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11274 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11275 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11276 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11277 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11278 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11279 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11280 | |
| 11281 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11282 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11283 | |
| 11284 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11285 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11286 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11287 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11288 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11289 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11291 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11292 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11293 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11294 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11295 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11297 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11298 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11299 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11300 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11301 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11302 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11303 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11305 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11306 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11307 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11308 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11309 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11310 | requests[0].url = GURL("https://www.example.com/"); |
| 11311 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11312 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11313 | |
| 11314 | requests[1].url = GURL("http://www.example.com/"); |
| 11315 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11316 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11317 | |
| 11318 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11319 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11320 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11321 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11322 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11323 | |
| 11324 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11325 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11326 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11327 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11328 | |
| 11329 | // Complete the SSL handshake, which should abort due to requiring a |
| 11330 | // client certificate. |
| 11331 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11332 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11333 | |
| 11334 | // Indicate that no certificate should be supplied. From the perspective |
| 11335 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11336 | // certificate, so this is the same as supply a |
| 11337 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11338 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11339 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11340 | |
| 11341 | // Ensure the certificate was added to the client auth cache before |
| 11342 | // allowing the connection to continue restarting. |
| 11343 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11344 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11345 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11346 | ASSERT_EQ(NULL, client_cert.get()); |
| 11347 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11348 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11349 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11350 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11351 | |
| 11352 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11353 | // then consume ssl_data3, which should also fail. The result code is |
| 11354 | // checked against what ssl_data3 should return. |
| 11355 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11356 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11357 | |
| 11358 | // Now that the new handshake has failed, ensure that the client |
| 11359 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11360 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11361 | HostPortPair("proxy", 70), &client_cert)); |
| 11362 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11363 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11364 | } |
| 11365 | } |
| 11366 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame^] | 11367 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11368 | session_deps_.use_alternate_protocols = true; |
| 11369 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11370 | |
| 11371 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11372 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11373 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11374 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11375 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11376 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11377 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11378 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11380 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11381 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11382 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11383 | scoped_ptr<SpdyFrame> host2_req( |
| 11384 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11385 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11386 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11387 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11388 | scoped_ptr<SpdyFrame> host1_resp( |
| 11389 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11390 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11391 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11392 | scoped_ptr<SpdyFrame> host2_resp( |
| 11393 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11394 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11395 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11396 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11397 | CreateMockRead(*host1_resp, 1), |
| 11398 | CreateMockRead(*host1_resp_body, 2), |
| 11399 | CreateMockRead(*host2_resp, 4), |
| 11400 | CreateMockRead(*host2_resp_body, 5), |
| 11401 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11402 | }; |
| 11403 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11404 | IPAddressNumber ip; |
| 11405 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11406 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11407 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11408 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11409 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11410 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11411 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11412 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11413 | HttpRequestInfo request1; |
| 11414 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11415 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11416 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11417 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11419 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11420 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11421 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11422 | |
| 11423 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11424 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11425 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11426 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11427 | |
| 11428 | std::string response_data; |
| 11429 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11430 | EXPECT_EQ("hello!", response_data); |
| 11431 | |
| 11432 | // Preload www.gmail.com into HostCache. |
| 11433 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11434 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11435 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11436 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11437 | DEFAULT_PRIORITY, |
| 11438 | &ignored, |
| 11439 | callback.callback(), |
| 11440 | NULL, |
| 11441 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11443 | rv = callback.WaitForResult(); |
| 11444 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11445 | |
| 11446 | HttpRequestInfo request2; |
| 11447 | request2.method = "GET"; |
| 11448 | request2.url = GURL("https://www.gmail.com/"); |
| 11449 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11450 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11452 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11453 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11454 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11455 | |
| 11456 | response = trans2.GetResponseInfo(); |
| 11457 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11458 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11459 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11460 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11461 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11462 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11463 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11464 | } |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11465 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11466 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11467 | session_deps_.use_alternate_protocols = true; |
| 11468 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11469 | |
| 11470 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11471 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11472 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11473 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11474 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11475 | |
| 11476 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11477 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11479 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11480 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11481 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11482 | scoped_ptr<SpdyFrame> host2_req( |
| 11483 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11484 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11485 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11486 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11487 | scoped_ptr<SpdyFrame> host1_resp( |
| 11488 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11489 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11490 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11491 | scoped_ptr<SpdyFrame> host2_resp( |
| 11492 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11493 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11494 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11495 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11496 | CreateMockRead(*host1_resp, 1), |
| 11497 | CreateMockRead(*host1_resp_body, 2), |
| 11498 | CreateMockRead(*host2_resp, 4), |
| 11499 | CreateMockRead(*host2_resp_body, 5), |
| 11500 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11501 | }; |
| 11502 | |
| 11503 | IPAddressNumber ip; |
| 11504 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11505 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11506 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11507 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11508 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11509 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11510 | |
| 11511 | TestCompletionCallback callback; |
| 11512 | HttpRequestInfo request1; |
| 11513 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11514 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11515 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11516 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11517 | |
| 11518 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11519 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11520 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11521 | |
| 11522 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11523 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11524 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11525 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11526 | |
| 11527 | std::string response_data; |
| 11528 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11529 | EXPECT_EQ("hello!", response_data); |
| 11530 | |
| 11531 | HttpRequestInfo request2; |
| 11532 | request2.method = "GET"; |
| 11533 | request2.url = GURL("https://www.gmail.com/"); |
| 11534 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11535 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11536 | |
| 11537 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11539 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11540 | |
| 11541 | response = trans2.GetResponseInfo(); |
| 11542 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11543 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11544 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11545 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11546 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11547 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11548 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11549 | } |
| 11550 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11551 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11552 | public: |
| 11553 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11554 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11555 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11556 | |
| 11557 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11558 | |
| 11559 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11560 | int Resolve(const RequestInfo& info, |
| 11561 | RequestPriority priority, |
| 11562 | AddressList* addresses, |
| 11563 | const CompletionCallback& callback, |
| 11564 | RequestHandle* out_req, |
| 11565 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11566 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11567 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11568 | } |
| 11569 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11570 | int ResolveFromCache(const RequestInfo& info, |
| 11571 | AddressList* addresses, |
| 11572 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11573 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11574 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11575 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11576 | return rv; |
| 11577 | } |
| 11578 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11579 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11580 | host_resolver_.CancelRequest(req); |
| 11581 | } |
| 11582 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11583 | MockCachingHostResolver* GetMockHostResolver() { |
| 11584 | return &host_resolver_; |
| 11585 | } |
| 11586 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11587 | private: |
| 11588 | MockCachingHostResolver host_resolver_; |
| 11589 | const HostPortPair host_port_; |
| 11590 | }; |
| 11591 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame^] | 11592 | TEST_P(HttpNetworkTransactionTest, |
| 11593 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11594 | session_deps_.use_alternate_protocols = true; |
| 11595 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11596 | |
| 11597 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11598 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11599 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11600 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11601 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11602 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11603 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11604 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11605 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11606 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11607 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11609 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11610 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11611 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11612 | scoped_ptr<SpdyFrame> host2_req( |
| 11613 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11614 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11615 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11616 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11617 | scoped_ptr<SpdyFrame> host1_resp( |
| 11618 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11619 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11620 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11621 | scoped_ptr<SpdyFrame> host2_resp( |
| 11622 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11623 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11624 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11625 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11626 | CreateMockRead(*host1_resp, 1), |
| 11627 | CreateMockRead(*host1_resp_body, 2), |
| 11628 | CreateMockRead(*host2_resp, 4), |
| 11629 | CreateMockRead(*host2_resp_body, 5), |
| 11630 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11631 | }; |
| 11632 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11633 | IPAddressNumber ip; |
| 11634 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11635 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11636 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11637 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11638 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11639 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11640 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11641 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11642 | HttpRequestInfo request1; |
| 11643 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11644 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11645 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11646 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11648 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11649 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11650 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11651 | |
| 11652 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11653 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11654 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11655 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11656 | |
| 11657 | std::string response_data; |
| 11658 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11659 | EXPECT_EQ("hello!", response_data); |
| 11660 | |
| 11661 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11662 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11663 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11664 | rv = host_resolver.Resolve(resolve_info, |
| 11665 | DEFAULT_PRIORITY, |
| 11666 | &ignored, |
| 11667 | callback.callback(), |
| 11668 | NULL, |
| 11669 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11671 | rv = callback.WaitForResult(); |
| 11672 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11673 | |
| 11674 | HttpRequestInfo request2; |
| 11675 | request2.method = "GET"; |
| 11676 | request2.url = GURL("https://www.gmail.com/"); |
| 11677 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11678 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11680 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11681 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11682 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11683 | |
| 11684 | response = trans2.GetResponseInfo(); |
| 11685 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11686 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11687 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11688 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11689 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11690 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11691 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11692 | } |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11693 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11694 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11695 | const std::string https_url = "https://www.example.org:8080/"; |
| 11696 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11697 | |
| 11698 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11699 | scoped_ptr<SpdyFrame> req1( |
| 11700 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11701 | |
| 11702 | MockWrite writes1[] = { |
| 11703 | CreateMockWrite(*req1, 0), |
| 11704 | }; |
| 11705 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11706 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11707 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11708 | MockRead reads1[] = { |
| 11709 | CreateMockRead(*resp1, 1), |
| 11710 | CreateMockRead(*body1, 2), |
| 11711 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11712 | }; |
| 11713 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11714 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 11715 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11716 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11717 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11718 | |
| 11719 | // HTTP GET for the HTTP URL |
| 11720 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11721 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11722 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11723 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11724 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11725 | }; |
| 11726 | |
| 11727 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11728 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11729 | MockRead(ASYNC, 2, "hello"), |
| 11730 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11731 | }; |
| 11732 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11733 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 11734 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11735 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11736 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11737 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11739 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11740 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11741 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11742 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11743 | |
| 11744 | // Start the first transaction to set up the SpdySession |
| 11745 | HttpRequestInfo request1; |
| 11746 | request1.method = "GET"; |
| 11747 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11748 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11749 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11750 | TestCompletionCallback callback1; |
| 11751 | EXPECT_EQ(ERR_IO_PENDING, |
| 11752 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11753 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11754 | |
| 11755 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11756 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11757 | |
| 11758 | // Now, start the HTTP request |
| 11759 | HttpRequestInfo request2; |
| 11760 | request2.method = "GET"; |
| 11761 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11762 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11763 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11764 | TestCompletionCallback callback2; |
| 11765 | EXPECT_EQ(ERR_IO_PENDING, |
| 11766 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11767 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11768 | |
| 11769 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11770 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11771 | } |
| 11772 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 11773 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 11774 | public: |
| 11775 | void Run(bool pooling, bool valid) { |
| 11776 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 11777 | 443); |
| 11778 | HostPortPair alternative("www.example.org", 443); |
| 11779 | |
| 11780 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 11781 | scoped_refptr<X509Certificate> cert( |
| 11782 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 11783 | ASSERT_TRUE(cert.get()); |
| 11784 | bool common_name_fallback_used; |
| 11785 | EXPECT_EQ(valid, |
| 11786 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 11787 | EXPECT_TRUE( |
| 11788 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 11789 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11790 | ssl.SetNextProto(GetParam()); |
| 11791 | ssl.cert = cert; |
| 11792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11793 | |
| 11794 | // If pooling, then start a request to alternative first to create a |
| 11795 | // SpdySession. |
| 11796 | std::string url0 = "https://www.example.org:443"; |
| 11797 | // Second request to origin, which has an alternative service, and could |
| 11798 | // open a connection to the alternative host or pool to the existing one. |
| 11799 | std::string url1("https://"); |
| 11800 | url1.append(origin.host()); |
| 11801 | url1.append(":443"); |
| 11802 | |
| 11803 | scoped_ptr<SpdyFrame> req0; |
| 11804 | scoped_ptr<SpdyFrame> req1; |
| 11805 | scoped_ptr<SpdyFrame> resp0; |
| 11806 | scoped_ptr<SpdyFrame> body0; |
| 11807 | scoped_ptr<SpdyFrame> resp1; |
| 11808 | scoped_ptr<SpdyFrame> body1; |
| 11809 | std::vector<MockWrite> writes; |
| 11810 | std::vector<MockRead> reads; |
| 11811 | |
| 11812 | if (pooling) { |
| 11813 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 11814 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 11815 | |
| 11816 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 11817 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 11818 | |
| 11819 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11820 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11821 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11822 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 11823 | |
| 11824 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 11825 | reads.push_back(CreateMockRead(*body0, 2)); |
| 11826 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 11827 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 11828 | reads.push_back(CreateMockRead(*body1, 6)); |
| 11829 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 11830 | } else { |
| 11831 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 11832 | |
| 11833 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 11834 | |
| 11835 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11836 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11837 | |
| 11838 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 11839 | reads.push_back(CreateMockRead(*body1, 2)); |
| 11840 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 11841 | } |
| 11842 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 11843 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 11844 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 11845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11846 | |
| 11847 | // Connection to the origin fails. |
| 11848 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11849 | StaticSocketDataProvider data_refused; |
| 11850 | data_refused.set_connect_data(mock_connect); |
| 11851 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11852 | |
| 11853 | session_deps_.use_alternate_protocols = true; |
| 11854 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11855 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 11856 | session->http_server_properties(); |
| 11857 | AlternativeService alternative_service( |
| 11858 | AlternateProtocolFromNextProto(GetParam()), alternative); |
| 11859 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 11860 | 1.0); |
| 11861 | |
| 11862 | // First request to alternative. |
| 11863 | if (pooling) { |
| 11864 | scoped_ptr<HttpTransaction> trans0( |
| 11865 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 11866 | HttpRequestInfo request0; |
| 11867 | request0.method = "GET"; |
| 11868 | request0.url = GURL(url0); |
| 11869 | request0.load_flags = 0; |
| 11870 | TestCompletionCallback callback0; |
| 11871 | |
| 11872 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 11873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11874 | rv = callback0.WaitForResult(); |
| 11875 | EXPECT_EQ(OK, rv); |
| 11876 | } |
| 11877 | |
| 11878 | // Second request to origin. |
| 11879 | scoped_ptr<HttpTransaction> trans1( |
| 11880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 11881 | HttpRequestInfo request1; |
| 11882 | request1.method = "GET"; |
| 11883 | request1.url = GURL(url1); |
| 11884 | request1.load_flags = 0; |
| 11885 | TestCompletionCallback callback1; |
| 11886 | |
| 11887 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 11888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 11889 | base::MessageLoop::current()->RunUntilIdle(); |
| 11890 | if (data.IsReadPaused()) { |
| 11891 | data.CompleteRead(); |
| 11892 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 11893 | rv = callback1.WaitForResult(); |
| 11894 | if (valid) { |
| 11895 | EXPECT_EQ(OK, rv); |
| 11896 | } else { |
| 11897 | if (pooling) { |
| 11898 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11899 | } else { |
| 11900 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 11901 | } |
| 11902 | } |
| 11903 | } |
| 11904 | }; |
| 11905 | |
| 11906 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 11907 | AltSvcCertificateVerificationTest, |
| 11908 | testing::Values(kProtoSPDY31, |
| 11909 | kProtoSPDY4_14, |
| 11910 | kProtoSPDY4)); |
| 11911 | |
| 11912 | // The alternative service host must exhibit a certificate that is valid for the |
| 11913 | // origin host. Test that this is enforced when pooling to an existing |
| 11914 | // connection. |
| 11915 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 11916 | Run(true, true); |
| 11917 | } |
| 11918 | |
| 11919 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 11920 | Run(true, false); |
| 11921 | } |
| 11922 | |
| 11923 | // The alternative service host must exhibit a certificate that is valid for the |
| 11924 | // origin host. Test that this is enforced when opening a new connection. |
| 11925 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 11926 | Run(false, true); |
| 11927 | } |
| 11928 | |
| 11929 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 11930 | Run(false, false); |
| 11931 | } |
| 11932 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 11933 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 11934 | // with the alternative server. That connection should not be used. |
| 11935 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 11936 | HostPortPair origin("origin.example.org", 443); |
| 11937 | HostPortPair alternative("alternative.example.org", 443); |
| 11938 | |
| 11939 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11940 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11941 | ssl.SetNextProto(kProtoHTTP11); |
| 11942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11943 | |
| 11944 | // No data should be read from the alternative, because HTTP/1.1 is |
| 11945 | // negotiated. |
| 11946 | StaticSocketDataProvider data; |
| 11947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11948 | |
| 11949 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 11950 | // negotiated. In order to test this, a failed connection to the origin is |
| 11951 | // mocked. This way the request relies on the alternate Job. |
| 11952 | StaticSocketDataProvider data_refused; |
| 11953 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11954 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11955 | |
| 11956 | // Set up alternative service for origin. |
| 11957 | session_deps_.use_alternate_protocols = true; |
| 11958 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11959 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 11960 | session->http_server_properties(); |
| 11961 | AlternativeService alternative_service( |
| 11962 | AlternateProtocolFromNextProto(GetParam()), alternative); |
| 11963 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 11964 | 1.0); |
| 11965 | |
| 11966 | scoped_ptr<HttpTransaction> trans( |
| 11967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 11968 | HttpRequestInfo request; |
| 11969 | request.method = "GET"; |
| 11970 | request.url = GURL("https://origin.example.org:443"); |
| 11971 | request.load_flags = 0; |
| 11972 | TestCompletionCallback callback; |
| 11973 | |
| 11974 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 11975 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 11976 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11977 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 11978 | } |
| 11979 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 11980 | // A request to a server with an alternative service fires two Jobs: one to the |
| 11981 | // origin, and an alternate one to the alternative server. If the former |
| 11982 | // succeeds, the request should succeed, even if the latter fails because |
| 11983 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 11984 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 11985 | HostPortPair origin("origin.example.org", 443); |
| 11986 | HostPortPair alternative("alternative.example.org", 443); |
| 11987 | |
| 11988 | // Negotiate HTTP/1.1 with alternative. |
| 11989 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 11990 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 11991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 11992 | |
| 11993 | // No data should be read from the alternative, because HTTP/1.1 is |
| 11994 | // negotiated. |
| 11995 | StaticSocketDataProvider data; |
| 11996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11997 | |
| 11998 | // Negotiate HTTP/1.1 with origin. |
| 11999 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12000 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12002 | |
| 12003 | MockWrite http_writes[] = { |
| 12004 | MockWrite( |
| 12005 | "GET / HTTP/1.1\r\n" |
| 12006 | "Host: origin.example.org\r\n" |
| 12007 | "Connection: keep-alive\r\n\r\n"), |
| 12008 | MockWrite( |
| 12009 | "GET /second HTTP/1.1\r\n" |
| 12010 | "Host: origin.example.org\r\n" |
| 12011 | "Connection: keep-alive\r\n\r\n"), |
| 12012 | }; |
| 12013 | |
| 12014 | MockRead http_reads[] = { |
| 12015 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12016 | MockRead("Content-Type: text/html\r\n"), |
| 12017 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12018 | MockRead("foobar"), |
| 12019 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12020 | MockRead("Content-Type: text/html\r\n"), |
| 12021 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12022 | MockRead("another"), |
| 12023 | }; |
| 12024 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12025 | http_writes, arraysize(http_writes)); |
| 12026 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12027 | |
| 12028 | // Set up alternative service for origin. |
| 12029 | session_deps_.use_alternate_protocols = true; |
| 12030 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12031 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12032 | session->http_server_properties(); |
| 12033 | AlternativeService alternative_service( |
| 12034 | AlternateProtocolFromNextProto(GetParam()), alternative); |
| 12035 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 12036 | 1.0); |
| 12037 | |
| 12038 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12039 | HttpRequestInfo request1; |
| 12040 | request1.method = "GET"; |
| 12041 | request1.url = GURL("https://origin.example.org:443"); |
| 12042 | request1.load_flags = 0; |
| 12043 | TestCompletionCallback callback1; |
| 12044 | |
| 12045 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12046 | rv = callback1.GetResult(rv); |
| 12047 | EXPECT_EQ(OK, rv); |
| 12048 | |
| 12049 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12050 | ASSERT_TRUE(response1 != nullptr); |
| 12051 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12052 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12053 | |
| 12054 | std::string response_data1; |
| 12055 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12056 | EXPECT_EQ("foobar", response_data1); |
| 12057 | |
| 12058 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12059 | // for alternative service. |
| 12060 | EXPECT_TRUE( |
| 12061 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12062 | |
| 12063 | // Since |alternative_service| is broken, a second transaction to origin |
| 12064 | // should not start an alternate Job. It should pool to existing connection |
| 12065 | // to origin. |
| 12066 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12067 | HttpRequestInfo request2; |
| 12068 | request2.method = "GET"; |
| 12069 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12070 | request2.load_flags = 0; |
| 12071 | TestCompletionCallback callback2; |
| 12072 | |
| 12073 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12074 | rv = callback2.GetResult(rv); |
| 12075 | EXPECT_EQ(OK, rv); |
| 12076 | |
| 12077 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12078 | ASSERT_TRUE(response2 != nullptr); |
| 12079 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12080 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12081 | |
| 12082 | std::string response_data2; |
| 12083 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12084 | EXPECT_EQ("another", response_data2); |
| 12085 | } |
| 12086 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12087 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12088 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12089 | // used. |
| 12090 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12091 | HostPortPair origin("origin.example.org", 443); |
| 12092 | HostPortPair alternative("alternative.example.org", 443); |
| 12093 | std::string origin_url = "https://origin.example.org:443"; |
| 12094 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12095 | |
| 12096 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12097 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12098 | ssl.SetNextProto(kProtoHTTP11); |
| 12099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12100 | |
| 12101 | // HTTP/1.1 data for |request1| and |request2|. |
| 12102 | MockWrite http_writes[] = { |
| 12103 | MockWrite( |
| 12104 | "GET / HTTP/1.1\r\n" |
| 12105 | "Host: alternative.example.org\r\n" |
| 12106 | "Connection: keep-alive\r\n\r\n"), |
| 12107 | MockWrite( |
| 12108 | "GET / HTTP/1.1\r\n" |
| 12109 | "Host: alternative.example.org\r\n" |
| 12110 | "Connection: keep-alive\r\n\r\n"), |
| 12111 | }; |
| 12112 | |
| 12113 | MockRead http_reads[] = { |
| 12114 | MockRead( |
| 12115 | "HTTP/1.1 200 OK\r\n" |
| 12116 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12117 | "Content-Length: 40\r\n\r\n" |
| 12118 | "first HTTP/1.1 response from alternative"), |
| 12119 | MockRead( |
| 12120 | "HTTP/1.1 200 OK\r\n" |
| 12121 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12122 | "Content-Length: 41\r\n\r\n" |
| 12123 | "second HTTP/1.1 response from alternative"), |
| 12124 | }; |
| 12125 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12126 | http_writes, arraysize(http_writes)); |
| 12127 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12128 | |
| 12129 | // This test documents that an alternate Job should not pool to an already |
| 12130 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12131 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12132 | StaticSocketDataProvider data_refused; |
| 12133 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12134 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12135 | |
| 12136 | // Set up alternative service for origin. |
| 12137 | session_deps_.use_alternate_protocols = true; |
| 12138 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12139 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12140 | session->http_server_properties(); |
| 12141 | AlternativeService alternative_service( |
| 12142 | AlternateProtocolFromNextProto(GetParam()), alternative); |
| 12143 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 12144 | 1.0); |
| 12145 | |
| 12146 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12147 | scoped_ptr<HttpTransaction> trans1( |
| 12148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12149 | HttpRequestInfo request1; |
| 12150 | request1.method = "GET"; |
| 12151 | request1.url = GURL(alternative_url); |
| 12152 | request1.load_flags = 0; |
| 12153 | TestCompletionCallback callback1; |
| 12154 | |
| 12155 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12156 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12157 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12158 | ASSERT_TRUE(response1); |
| 12159 | ASSERT_TRUE(response1->headers.get()); |
| 12160 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12161 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12162 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12163 | std::string response_data1; |
| 12164 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12165 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12166 | |
| 12167 | // Request for origin.example.org, which has an alternative service. This |
| 12168 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12169 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12170 | // open other connections to alternative server. The Job to origin fails, so |
| 12171 | // this request fails. |
| 12172 | scoped_ptr<HttpTransaction> trans2( |
| 12173 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12174 | HttpRequestInfo request2; |
| 12175 | request2.method = "GET"; |
| 12176 | request2.url = GURL(origin_url); |
| 12177 | request2.load_flags = 0; |
| 12178 | TestCompletionCallback callback2; |
| 12179 | |
| 12180 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12181 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12182 | |
| 12183 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12184 | // socket is still open and in the pool. |
| 12185 | scoped_ptr<HttpTransaction> trans3( |
| 12186 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12187 | HttpRequestInfo request3; |
| 12188 | request3.method = "GET"; |
| 12189 | request3.url = GURL(alternative_url); |
| 12190 | request3.load_flags = 0; |
| 12191 | TestCompletionCallback callback3; |
| 12192 | |
| 12193 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12194 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12195 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12196 | ASSERT_TRUE(response3); |
| 12197 | ASSERT_TRUE(response3->headers.get()); |
| 12198 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12199 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12200 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12201 | std::string response_data3; |
| 12202 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12203 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12204 | } |
| 12205 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12206 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12207 | const std::string https_url = "https://www.example.org:8080/"; |
| 12208 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12209 | |
| 12210 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12211 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12212 | scoped_ptr<SpdyFrame> connect( |
| 12213 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12214 | scoped_ptr<SpdyFrame> req1( |
| 12215 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12216 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12217 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12218 | |
| 12219 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12220 | SpdyHeaderBlock req2_block; |
| 12221 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 12222 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12223 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12224 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 12225 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12226 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12227 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12228 | |
| 12229 | MockWrite writes1[] = { |
| 12230 | CreateMockWrite(*connect, 0), |
| 12231 | CreateMockWrite(*wrapped_req1, 2), |
| 12232 | CreateMockWrite(*req2, 5), |
| 12233 | }; |
| 12234 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12235 | scoped_ptr<SpdyFrame> conn_resp( |
| 12236 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12237 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12238 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12239 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12240 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12241 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12242 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12243 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12244 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12245 | MockRead reads1[] = { |
| 12246 | CreateMockRead(*conn_resp, 1), |
| 12247 | CreateMockRead(*wrapped_resp1, 3), |
| 12248 | CreateMockRead(*wrapped_body1, 4), |
| 12249 | CreateMockRead(*resp2, 6), |
| 12250 | CreateMockRead(*body2, 7), |
| 12251 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12252 | }; |
| 12253 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12254 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12255 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12256 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12257 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12258 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12259 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12260 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12261 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12262 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12263 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12264 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12265 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12266 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12267 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12268 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12269 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12270 | |
| 12271 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12272 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12273 | |
| 12274 | // Start the first transaction to set up the SpdySession |
| 12275 | HttpRequestInfo request1; |
| 12276 | request1.method = "GET"; |
| 12277 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12278 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12279 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12280 | TestCompletionCallback callback1; |
| 12281 | EXPECT_EQ(ERR_IO_PENDING, |
| 12282 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12283 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12284 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12285 | |
| 12286 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12287 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12288 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12289 | LoadTimingInfo load_timing_info1; |
| 12290 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12291 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12292 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12293 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12294 | // Now, start the HTTP request |
| 12295 | HttpRequestInfo request2; |
| 12296 | request2.method = "GET"; |
| 12297 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12298 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12299 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12300 | TestCompletionCallback callback2; |
| 12301 | EXPECT_EQ(ERR_IO_PENDING, |
| 12302 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12303 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12304 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12305 | |
| 12306 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12307 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12308 | |
| 12309 | LoadTimingInfo load_timing_info2; |
| 12310 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12311 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12312 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12313 | // HTTP requests over a SPDY session should have a different connection |
| 12314 | // socket_log_id than requests over a tunnel. |
| 12315 | 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] | 12316 | } |
| 12317 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12318 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12319 | // that we do not pool other origins that resolve to the same IP when |
| 12320 | // the certificate does not match the new origin. |
| 12321 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12322 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12323 | const std::string url1 = "http://www.example.org/"; |
| 12324 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12325 | const std::string ip_addr = "1.2.3.4"; |
| 12326 | |
| 12327 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12328 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12329 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12330 | scoped_ptr<SpdyFrame> req1( |
| 12331 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12332 | |
| 12333 | MockWrite writes1[] = { |
| 12334 | CreateMockWrite(*req1, 0), |
| 12335 | }; |
| 12336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12337 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12338 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12339 | MockRead reads1[] = { |
| 12340 | CreateMockRead(*resp1, 1), |
| 12341 | CreateMockRead(*body1, 2), |
| 12342 | MockRead(ASYNC, OK, 3) // EOF |
| 12343 | }; |
| 12344 | |
| 12345 | scoped_ptr<DeterministicSocketData> data1( |
| 12346 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12347 | writes1, arraysize(writes1))); |
| 12348 | IPAddressNumber ip; |
| 12349 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12350 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12351 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12352 | data1->set_connect_data(connect_data1); |
| 12353 | |
| 12354 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12355 | scoped_ptr<SpdyFrame> req2( |
| 12356 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12357 | |
| 12358 | MockWrite writes2[] = { |
| 12359 | CreateMockWrite(*req2, 0), |
| 12360 | }; |
| 12361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12362 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12363 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12364 | MockRead reads2[] = { |
| 12365 | CreateMockRead(*resp2, 1), |
| 12366 | CreateMockRead(*body2, 2), |
| 12367 | MockRead(ASYNC, OK, 3) // EOF |
| 12368 | }; |
| 12369 | |
| 12370 | scoped_ptr<DeterministicSocketData> data2( |
| 12371 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12372 | writes2, arraysize(writes2))); |
| 12373 | MockConnect connect_data2(ASYNC, OK); |
| 12374 | data2->set_connect_data(connect_data2); |
| 12375 | |
| 12376 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12377 | // all others direct. |
| 12378 | ProxyConfig proxy_config; |
| 12379 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12380 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12381 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12382 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12383 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12384 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12385 | // Load a valid cert. Note, that this does not need to |
| 12386 | // be valid for proxy because the MockSSLClientSocket does |
| 12387 | // not actually verify it. But SpdySession will use this |
| 12388 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12389 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12390 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12391 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12392 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12393 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12394 | |
| 12395 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12396 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12397 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12398 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12399 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12400 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12401 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12402 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12403 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12404 | |
| 12405 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12406 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12407 | |
| 12408 | // Start the first transaction to set up the SpdySession |
| 12409 | HttpRequestInfo request1; |
| 12410 | request1.method = "GET"; |
| 12411 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12412 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12413 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12414 | TestCompletionCallback callback1; |
| 12415 | ASSERT_EQ(ERR_IO_PENDING, |
| 12416 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12417 | data1->RunFor(3); |
| 12418 | |
| 12419 | ASSERT_TRUE(callback1.have_result()); |
| 12420 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12421 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12422 | |
| 12423 | // Now, start the HTTP request |
| 12424 | HttpRequestInfo request2; |
| 12425 | request2.method = "GET"; |
| 12426 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12427 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12428 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12429 | TestCompletionCallback callback2; |
| 12430 | EXPECT_EQ(ERR_IO_PENDING, |
| 12431 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12432 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12433 | data2->RunFor(3); |
| 12434 | |
| 12435 | ASSERT_TRUE(callback2.have_result()); |
| 12436 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12437 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12438 | } |
| 12439 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12440 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12441 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12442 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12443 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12444 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12445 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12446 | |
| 12447 | MockRead reads1[] = { |
| 12448 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12449 | }; |
| 12450 | |
| 12451 | scoped_ptr<DeterministicSocketData> data1( |
| 12452 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 12453 | data1->SetStop(1); |
| 12454 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12455 | scoped_ptr<SpdyFrame> req2( |
| 12456 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12457 | MockWrite writes2[] = { |
| 12458 | CreateMockWrite(*req2, 0), |
| 12459 | }; |
| 12460 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12461 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12462 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12463 | MockRead reads2[] = { |
| 12464 | CreateMockRead(*resp2, 1), |
| 12465 | CreateMockRead(*body2, 2), |
| 12466 | MockRead(ASYNC, OK, 3) // EOF |
| 12467 | }; |
| 12468 | |
| 12469 | scoped_ptr<DeterministicSocketData> data2( |
| 12470 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12471 | writes2, arraysize(writes2))); |
| 12472 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12473 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12474 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12475 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12476 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12477 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12478 | |
| 12479 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12480 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12481 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12482 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12483 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12484 | |
| 12485 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12486 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12487 | |
| 12488 | // Start the first transaction to set up the SpdySession and verify that |
| 12489 | // connection was closed. |
| 12490 | HttpRequestInfo request1; |
| 12491 | request1.method = "GET"; |
| 12492 | request1.url = GURL(https_url); |
| 12493 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12494 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12495 | TestCompletionCallback callback1; |
| 12496 | EXPECT_EQ(ERR_IO_PENDING, |
| 12497 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12498 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12499 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12500 | |
| 12501 | // Now, start the second request and make sure it succeeds. |
| 12502 | HttpRequestInfo request2; |
| 12503 | request2.method = "GET"; |
| 12504 | request2.url = GURL(https_url); |
| 12505 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12506 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12507 | TestCompletionCallback callback2; |
| 12508 | EXPECT_EQ(ERR_IO_PENDING, |
| 12509 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12510 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12511 | data2->RunFor(3); |
| 12512 | |
| 12513 | ASSERT_TRUE(callback2.have_result()); |
| 12514 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12515 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12516 | } |
| 12517 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12518 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12519 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12520 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12521 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12522 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12523 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12524 | |
| 12525 | // Use two different hosts with different IPs so they don't get pooled. |
| 12526 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12527 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12528 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12529 | |
| 12530 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12531 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12532 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12533 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12536 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12537 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12538 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12539 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12540 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12541 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12542 | scoped_ptr<SpdyFrame> host1_resp( |
| 12543 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12544 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12545 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12546 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12547 | CreateMockRead(*host1_resp, 1), |
| 12548 | CreateMockRead(*host1_resp_body, 2), |
| 12549 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12550 | }; |
| 12551 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12552 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12553 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12554 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12555 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12556 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12557 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12558 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12559 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12560 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12561 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12562 | scoped_ptr<SpdyFrame> host2_resp( |
| 12563 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12564 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12565 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12566 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12567 | CreateMockRead(*host2_resp, 1), |
| 12568 | CreateMockRead(*host2_resp_body, 2), |
| 12569 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12570 | }; |
| 12571 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12572 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12573 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12574 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12575 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12576 | |
| 12577 | MockWrite http_write[] = { |
| 12578 | MockWrite("GET / HTTP/1.1\r\n" |
| 12579 | "Host: www.a.com\r\n" |
| 12580 | "Connection: keep-alive\r\n\r\n"), |
| 12581 | }; |
| 12582 | |
| 12583 | MockRead http_read[] = { |
| 12584 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12586 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12587 | MockRead("hello!"), |
| 12588 | }; |
| 12589 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12590 | http_write, arraysize(http_write)); |
| 12591 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12592 | |
| 12593 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12594 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12595 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12596 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12597 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12598 | |
| 12599 | TestCompletionCallback callback; |
| 12600 | HttpRequestInfo request1; |
| 12601 | request1.method = "GET"; |
| 12602 | request1.url = GURL("https://www.a.com/"); |
| 12603 | request1.load_flags = 0; |
| 12604 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12606 | |
| 12607 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12609 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12610 | |
| 12611 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12612 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12613 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12614 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12615 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12616 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12617 | |
| 12618 | std::string response_data; |
| 12619 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12620 | EXPECT_EQ("hello!", response_data); |
| 12621 | trans.reset(); |
| 12622 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12623 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12624 | |
| 12625 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12626 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12627 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12628 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12629 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12630 | HttpRequestInfo request2; |
| 12631 | request2.method = "GET"; |
| 12632 | request2.url = GURL("https://www.b.com/"); |
| 12633 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12634 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12635 | |
| 12636 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 12637 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12638 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12639 | |
| 12640 | response = trans->GetResponseInfo(); |
| 12641 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12642 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12643 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12644 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12645 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12646 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12647 | EXPECT_EQ("hello!", response_data); |
| 12648 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12649 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12650 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12651 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12652 | |
| 12653 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12654 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12655 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12656 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12657 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12658 | HttpRequestInfo request3; |
| 12659 | request3.method = "GET"; |
| 12660 | request3.url = GURL("http://www.a.com/"); |
| 12661 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12662 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12663 | |
| 12664 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 12665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12666 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12667 | |
| 12668 | response = trans->GetResponseInfo(); |
| 12669 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12670 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12671 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12672 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12673 | EXPECT_FALSE(response->was_npn_negotiated); |
| 12674 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12675 | EXPECT_EQ("hello!", response_data); |
| 12676 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12677 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12678 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12679 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12680 | } |
| 12681 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12682 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 12683 | HttpRequestInfo request; |
| 12684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12685 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12686 | request.load_flags = 0; |
| 12687 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12688 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12689 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12690 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12691 | |
| 12692 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 12693 | StaticSocketDataProvider data; |
| 12694 | data.set_connect_data(mock_connect); |
| 12695 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12696 | |
| 12697 | TestCompletionCallback callback; |
| 12698 | |
| 12699 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12700 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12701 | |
| 12702 | rv = callback.WaitForResult(); |
| 12703 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12704 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12705 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12706 | HttpRequestHeaders request_headers; |
| 12707 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 12708 | |
| 12709 | ConnectionAttempts attempts; |
| 12710 | trans->GetConnectionAttempts(&attempts); |
| 12711 | ASSERT_EQ(1u, attempts.size()); |
| 12712 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12713 | } |
| 12714 | |
| 12715 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 12716 | HttpRequestInfo request; |
| 12717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12718 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12719 | request.load_flags = 0; |
| 12720 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12721 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12722 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12723 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12724 | |
| 12725 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12726 | StaticSocketDataProvider data; |
| 12727 | data.set_connect_data(mock_connect); |
| 12728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12729 | |
| 12730 | TestCompletionCallback callback; |
| 12731 | |
| 12732 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12734 | |
| 12735 | rv = callback.WaitForResult(); |
| 12736 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12737 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12738 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12739 | HttpRequestHeaders request_headers; |
| 12740 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 12741 | |
| 12742 | ConnectionAttempts attempts; |
| 12743 | trans->GetConnectionAttempts(&attempts); |
| 12744 | ASSERT_EQ(1u, attempts.size()); |
| 12745 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12746 | } |
| 12747 | |
| 12748 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12749 | HttpRequestInfo request; |
| 12750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12751 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12752 | request.load_flags = 0; |
| 12753 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12754 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12755 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12757 | |
| 12758 | MockWrite data_writes[] = { |
| 12759 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12760 | }; |
| 12761 | MockRead data_reads[] = { |
| 12762 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12763 | }; |
| 12764 | |
| 12765 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12766 | data_writes, arraysize(data_writes)); |
| 12767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12768 | |
| 12769 | TestCompletionCallback callback; |
| 12770 | |
| 12771 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12773 | |
| 12774 | rv = callback.WaitForResult(); |
| 12775 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12776 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12777 | HttpRequestHeaders request_headers; |
| 12778 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12779 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12780 | } |
| 12781 | |
| 12782 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12783 | HttpRequestInfo request; |
| 12784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12785 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12786 | request.load_flags = 0; |
| 12787 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12788 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12789 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12790 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12791 | |
| 12792 | MockWrite data_writes[] = { |
| 12793 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12794 | }; |
| 12795 | MockRead data_reads[] = { |
| 12796 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12797 | }; |
| 12798 | |
| 12799 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12800 | data_writes, arraysize(data_writes)); |
| 12801 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12802 | |
| 12803 | TestCompletionCallback callback; |
| 12804 | |
| 12805 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12806 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12807 | |
| 12808 | rv = callback.WaitForResult(); |
| 12809 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12810 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12811 | HttpRequestHeaders request_headers; |
| 12812 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12813 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12814 | } |
| 12815 | |
| 12816 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12817 | HttpRequestInfo request; |
| 12818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12820 | request.load_flags = 0; |
| 12821 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12822 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12823 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12825 | |
| 12826 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12827 | MockWrite( |
| 12828 | "GET / HTTP/1.1\r\n" |
| 12829 | "Host: www.example.org\r\n" |
| 12830 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12831 | }; |
| 12832 | MockRead data_reads[] = { |
| 12833 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12834 | }; |
| 12835 | |
| 12836 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12837 | data_writes, arraysize(data_writes)); |
| 12838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12839 | |
| 12840 | TestCompletionCallback callback; |
| 12841 | |
| 12842 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12844 | |
| 12845 | rv = callback.WaitForResult(); |
| 12846 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12847 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12848 | HttpRequestHeaders request_headers; |
| 12849 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12850 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12851 | } |
| 12852 | |
| 12853 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12854 | HttpRequestInfo request; |
| 12855 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12856 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12857 | request.load_flags = 0; |
| 12858 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12859 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12860 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12862 | |
| 12863 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12864 | MockWrite( |
| 12865 | "GET / HTTP/1.1\r\n" |
| 12866 | "Host: www.example.org\r\n" |
| 12867 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12868 | }; |
| 12869 | MockRead data_reads[] = { |
| 12870 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12871 | }; |
| 12872 | |
| 12873 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12874 | data_writes, arraysize(data_writes)); |
| 12875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12876 | |
| 12877 | TestCompletionCallback callback; |
| 12878 | |
| 12879 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12880 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12881 | |
| 12882 | rv = callback.WaitForResult(); |
| 12883 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12884 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12885 | HttpRequestHeaders request_headers; |
| 12886 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12887 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12888 | } |
| 12889 | |
| 12890 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12891 | HttpRequestInfo request; |
| 12892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12893 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12894 | request.load_flags = 0; |
| 12895 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12896 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12897 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12898 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12900 | |
| 12901 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12902 | MockWrite( |
| 12903 | "GET / HTTP/1.1\r\n" |
| 12904 | "Host: www.example.org\r\n" |
| 12905 | "Connection: keep-alive\r\n" |
| 12906 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12907 | }; |
| 12908 | MockRead data_reads[] = { |
| 12909 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12910 | "Content-Length: 5\r\n\r\n" |
| 12911 | "hello"), |
| 12912 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12913 | }; |
| 12914 | |
| 12915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12916 | data_writes, arraysize(data_writes)); |
| 12917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12918 | |
| 12919 | TestCompletionCallback callback; |
| 12920 | |
| 12921 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12923 | |
| 12924 | rv = callback.WaitForResult(); |
| 12925 | EXPECT_EQ(OK, rv); |
| 12926 | |
| 12927 | HttpRequestHeaders request_headers; |
| 12928 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12929 | std::string foo; |
| 12930 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12931 | EXPECT_EQ("bar", foo); |
| 12932 | } |
| 12933 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12934 | namespace { |
| 12935 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12936 | // Fake HttpStream that simply records calls to SetPriority(). |
| 12937 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12938 | public base::SupportsWeakPtr<FakeStream> { |
| 12939 | public: |
| 12940 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12941 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12942 | |
| 12943 | RequestPriority priority() const { return priority_; } |
| 12944 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12945 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12946 | RequestPriority priority, |
| 12947 | const BoundNetLog& net_log, |
| 12948 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12949 | return ERR_IO_PENDING; |
| 12950 | } |
| 12951 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12952 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12953 | HttpResponseInfo* response, |
| 12954 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12955 | ADD_FAILURE(); |
| 12956 | return ERR_UNEXPECTED; |
| 12957 | } |
| 12958 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12959 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12960 | ADD_FAILURE(); |
| 12961 | return ERR_UNEXPECTED; |
| 12962 | } |
| 12963 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12964 | int ReadResponseBody(IOBuffer* buf, |
| 12965 | int buf_len, |
| 12966 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12967 | ADD_FAILURE(); |
| 12968 | return ERR_UNEXPECTED; |
| 12969 | } |
| 12970 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12971 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12972 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12973 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12974 | ADD_FAILURE(); |
| 12975 | return false; |
| 12976 | } |
| 12977 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12978 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12979 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12980 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12981 | ADD_FAILURE(); |
| 12982 | return false; |
| 12983 | } |
| 12984 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12985 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12986 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12987 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12988 | ADD_FAILURE(); |
| 12989 | return false; |
| 12990 | } |
| 12991 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12992 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12993 | ADD_FAILURE(); |
| 12994 | return 0; |
| 12995 | } |
| 12996 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12997 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12998 | ADD_FAILURE(); |
| 12999 | return false; |
| 13000 | } |
| 13001 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13002 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13003 | |
| 13004 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13005 | ADD_FAILURE(); |
| 13006 | } |
| 13007 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13008 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13009 | ADD_FAILURE(); |
| 13010 | return false; |
| 13011 | } |
| 13012 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13013 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13014 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13015 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13016 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13017 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13018 | |
| 13019 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13020 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13021 | private: |
| 13022 | RequestPriority priority_; |
| 13023 | |
| 13024 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13025 | }; |
| 13026 | |
| 13027 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13028 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13029 | class FakeStreamRequest : public HttpStreamRequest, |
| 13030 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13031 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13032 | FakeStreamRequest(RequestPriority priority, |
| 13033 | HttpStreamRequest::Delegate* delegate) |
| 13034 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13035 | delegate_(delegate), |
| 13036 | websocket_stream_create_helper_(NULL) {} |
| 13037 | |
| 13038 | FakeStreamRequest(RequestPriority priority, |
| 13039 | HttpStreamRequest::Delegate* delegate, |
| 13040 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13041 | : priority_(priority), |
| 13042 | delegate_(delegate), |
| 13043 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13044 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13045 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13046 | |
| 13047 | RequestPriority priority() const { return priority_; } |
| 13048 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13049 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13050 | websocket_stream_create_helper() const { |
| 13051 | return websocket_stream_create_helper_; |
| 13052 | } |
| 13053 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13054 | // Create a new FakeStream and pass it to the request's |
| 13055 | // delegate. Returns a weak pointer to the FakeStream. |
| 13056 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13057 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13058 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13059 | // immediately delete |fake_stream|. |
| 13060 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13061 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13062 | return weak_stream; |
| 13063 | } |
| 13064 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13065 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13066 | ADD_FAILURE(); |
| 13067 | return ERR_UNEXPECTED; |
| 13068 | } |
| 13069 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13070 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13071 | ADD_FAILURE(); |
| 13072 | return LoadState(); |
| 13073 | } |
| 13074 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13075 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13076 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13077 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13078 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13079 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13080 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13081 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13082 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13083 | const ConnectionAttempts& connection_attempts() const override { |
| 13084 | static ConnectionAttempts no_attempts; |
| 13085 | return no_attempts; |
| 13086 | } |
| 13087 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13088 | private: |
| 13089 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13090 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13091 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13092 | |
| 13093 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13094 | }; |
| 13095 | |
| 13096 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13097 | class FakeStreamFactory : public HttpStreamFactory { |
| 13098 | public: |
| 13099 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13100 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13101 | |
| 13102 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13103 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13104 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13105 | return last_stream_request_; |
| 13106 | } |
| 13107 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13108 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13109 | RequestPriority priority, |
| 13110 | const SSLConfig& server_ssl_config, |
| 13111 | const SSLConfig& proxy_ssl_config, |
| 13112 | HttpStreamRequest::Delegate* delegate, |
| 13113 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13114 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13115 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13116 | return fake_request; |
| 13117 | } |
| 13118 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13119 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13120 | const HttpRequestInfo& info, |
| 13121 | RequestPriority priority, |
| 13122 | const SSLConfig& server_ssl_config, |
| 13123 | const SSLConfig& proxy_ssl_config, |
| 13124 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13125 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13126 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13127 | FakeStreamRequest* fake_request = |
| 13128 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13129 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13130 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13131 | } |
| 13132 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13133 | void PreconnectStreams(int num_streams, |
| 13134 | const HttpRequestInfo& info, |
| 13135 | RequestPriority priority, |
| 13136 | const SSLConfig& server_ssl_config, |
| 13137 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13138 | ADD_FAILURE(); |
| 13139 | } |
| 13140 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13141 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13142 | ADD_FAILURE(); |
| 13143 | return NULL; |
| 13144 | } |
| 13145 | |
| 13146 | private: |
| 13147 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13148 | |
| 13149 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13150 | }; |
| 13151 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13152 | // TODO(ricea): Maybe unify this with the one in |
| 13153 | // url_request_http_job_unittest.cc ? |
| 13154 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13155 | public: |
| 13156 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13157 | bool using_proxy) |
| 13158 | : state_(connection.release(), using_proxy) {} |
| 13159 | |
| 13160 | // Fake implementation of HttpStreamBase methods. |
| 13161 | // This ends up being quite "real" because this object has to really send data |
| 13162 | // on the mock socket. It might be easier to use the real implementation, but |
| 13163 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13164 | // difficult. |
| 13165 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13166 | RequestPriority priority, |
| 13167 | const BoundNetLog& net_log, |
| 13168 | const CompletionCallback& callback) override { |
| 13169 | state_.Initialize(request_info, priority, net_log, callback); |
| 13170 | return OK; |
| 13171 | } |
| 13172 | |
| 13173 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13174 | HttpResponseInfo* response, |
| 13175 | const CompletionCallback& callback) override { |
| 13176 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13177 | response, callback); |
| 13178 | } |
| 13179 | |
| 13180 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13181 | return parser()->ReadResponseHeaders(callback); |
| 13182 | } |
| 13183 | |
| 13184 | int ReadResponseBody(IOBuffer* buf, |
| 13185 | int buf_len, |
| 13186 | const CompletionCallback& callback) override { |
| 13187 | NOTREACHED(); |
| 13188 | return ERR_IO_PENDING; |
| 13189 | } |
| 13190 | |
| 13191 | void Close(bool not_reusable) override { |
| 13192 | if (parser()) |
| 13193 | parser()->Close(true); |
| 13194 | } |
| 13195 | |
| 13196 | bool IsResponseBodyComplete() const override { |
| 13197 | NOTREACHED(); |
| 13198 | return false; |
| 13199 | } |
| 13200 | |
| 13201 | bool CanFindEndOfResponse() const override { |
| 13202 | return parser()->CanFindEndOfResponse(); |
| 13203 | } |
| 13204 | |
| 13205 | bool IsConnectionReused() const override { |
| 13206 | NOTREACHED(); |
| 13207 | return false; |
| 13208 | } |
| 13209 | void SetConnectionReused() override { NOTREACHED(); } |
| 13210 | |
| 13211 | bool IsConnectionReusable() const override { |
| 13212 | NOTREACHED(); |
| 13213 | return false; |
| 13214 | } |
| 13215 | |
| 13216 | int64 GetTotalReceivedBytes() const override { |
| 13217 | NOTREACHED(); |
| 13218 | return 0; |
| 13219 | } |
| 13220 | |
| 13221 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13222 | NOTREACHED(); |
| 13223 | return false; |
| 13224 | } |
| 13225 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13226 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13227 | |
| 13228 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13229 | NOTREACHED(); |
| 13230 | } |
| 13231 | |
| 13232 | bool IsSpdyHttpStream() const override { |
| 13233 | NOTREACHED(); |
| 13234 | return false; |
| 13235 | } |
| 13236 | |
| 13237 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13238 | |
| 13239 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13240 | |
| 13241 | UploadProgress GetUploadProgress() const override { |
| 13242 | NOTREACHED(); |
| 13243 | return UploadProgress(); |
| 13244 | } |
| 13245 | |
| 13246 | HttpStream* RenewStreamForAuth() override { |
| 13247 | NOTREACHED(); |
| 13248 | return nullptr; |
| 13249 | } |
| 13250 | |
| 13251 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13252 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13253 | NOTREACHED(); |
| 13254 | return scoped_ptr<WebSocketStream>(); |
| 13255 | } |
| 13256 | |
| 13257 | private: |
| 13258 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13259 | HttpBasicState state_; |
| 13260 | |
| 13261 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13262 | }; |
| 13263 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13264 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13265 | // worth doing. |
| 13266 | class FakeWebSocketStreamCreateHelper : |
| 13267 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13268 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13269 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13270 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13271 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13272 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13273 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13274 | } |
| 13275 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13276 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13277 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13278 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13279 | NOTREACHED(); |
| 13280 | return NULL; |
| 13281 | }; |
| 13282 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13283 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13284 | |
| 13285 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13286 | NOTREACHED(); |
| 13287 | return scoped_ptr<WebSocketStream>(); |
| 13288 | } |
| 13289 | }; |
| 13290 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13291 | } // namespace |
| 13292 | |
| 13293 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13294 | // stream request on start. |
| 13295 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 13296 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13297 | HttpNetworkSessionPeer peer(session); |
| 13298 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13299 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13300 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13301 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13302 | |
| 13303 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13304 | |
| 13305 | HttpRequestInfo request; |
| 13306 | TestCompletionCallback callback; |
| 13307 | EXPECT_EQ(ERR_IO_PENDING, |
| 13308 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13309 | |
| 13310 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13311 | fake_factory->last_stream_request(); |
| 13312 | ASSERT_TRUE(fake_request != NULL); |
| 13313 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13314 | } |
| 13315 | |
| 13316 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13317 | // updates to its stream request. |
| 13318 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 13319 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13320 | HttpNetworkSessionPeer peer(session); |
| 13321 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13322 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13323 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13324 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13325 | |
| 13326 | HttpRequestInfo request; |
| 13327 | TestCompletionCallback callback; |
| 13328 | EXPECT_EQ(ERR_IO_PENDING, |
| 13329 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13330 | |
| 13331 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13332 | fake_factory->last_stream_request(); |
| 13333 | ASSERT_TRUE(fake_request != NULL); |
| 13334 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13335 | |
| 13336 | trans.SetPriority(LOWEST); |
| 13337 | ASSERT_TRUE(fake_request != NULL); |
| 13338 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13339 | } |
| 13340 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13341 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13342 | // updates to its stream. |
| 13343 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 13344 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13345 | HttpNetworkSessionPeer peer(session); |
| 13346 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13347 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13348 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13349 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13350 | |
| 13351 | HttpRequestInfo request; |
| 13352 | TestCompletionCallback callback; |
| 13353 | EXPECT_EQ(ERR_IO_PENDING, |
| 13354 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13355 | |
| 13356 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13357 | fake_factory->last_stream_request(); |
| 13358 | ASSERT_TRUE(fake_request != NULL); |
| 13359 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13360 | ASSERT_TRUE(fake_stream != NULL); |
| 13361 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13362 | |
| 13363 | trans.SetPriority(LOWEST); |
| 13364 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13365 | } |
| 13366 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13367 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13368 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13369 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13370 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13371 | std::string test_cases[] = {"ws://www.example.org/", |
| 13372 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13373 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 13374 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13375 | HttpNetworkSessionPeer peer(session); |
| 13376 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13377 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13378 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13379 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13380 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13381 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13382 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13383 | &websocket_stream_create_helper); |
| 13384 | |
| 13385 | HttpRequestInfo request; |
| 13386 | TestCompletionCallback callback; |
| 13387 | request.method = "GET"; |
| 13388 | request.url = GURL(test_cases[i]); |
| 13389 | |
| 13390 | EXPECT_EQ(ERR_IO_PENDING, |
| 13391 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13392 | |
| 13393 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13394 | fake_factory->last_stream_request(); |
| 13395 | ASSERT_TRUE(fake_request != NULL); |
| 13396 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13397 | fake_request->websocket_stream_create_helper()); |
| 13398 | } |
| 13399 | } |
| 13400 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13401 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13402 | // if the transport socket pool is stalled on the global socket limit. |
| 13403 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13404 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13405 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13406 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13407 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13408 | |
| 13409 | // Set up SSL request. |
| 13410 | |
| 13411 | HttpRequestInfo ssl_request; |
| 13412 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13413 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13414 | |
| 13415 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13416 | MockWrite( |
| 13417 | "GET / HTTP/1.1\r\n" |
| 13418 | "Host: www.example.org\r\n" |
| 13419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13420 | }; |
| 13421 | MockRead ssl_reads[] = { |
| 13422 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13423 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13424 | MockRead("hello world"), |
| 13425 | MockRead(SYNCHRONOUS, OK), |
| 13426 | }; |
| 13427 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13428 | ssl_writes, arraysize(ssl_writes)); |
| 13429 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13430 | |
| 13431 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13433 | |
| 13434 | // Set up HTTP request. |
| 13435 | |
| 13436 | HttpRequestInfo http_request; |
| 13437 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13438 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13439 | |
| 13440 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13441 | MockWrite( |
| 13442 | "GET / HTTP/1.1\r\n" |
| 13443 | "Host: www.example.org\r\n" |
| 13444 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13445 | }; |
| 13446 | MockRead http_reads[] = { |
| 13447 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13448 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13449 | MockRead("falafel"), |
| 13450 | MockRead(SYNCHRONOUS, OK), |
| 13451 | }; |
| 13452 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13453 | http_writes, arraysize(http_writes)); |
| 13454 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13455 | |
| 13456 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13457 | |
| 13458 | // Start the SSL request. |
| 13459 | TestCompletionCallback ssl_callback; |
| 13460 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13461 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13462 | ASSERT_EQ(ERR_IO_PENDING, |
| 13463 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13464 | BoundNetLog())); |
| 13465 | |
| 13466 | // Start the HTTP request. Pool should stall. |
| 13467 | TestCompletionCallback http_callback; |
| 13468 | scoped_ptr<HttpTransaction> http_trans( |
| 13469 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13470 | ASSERT_EQ(ERR_IO_PENDING, |
| 13471 | http_trans->Start(&http_request, http_callback.callback(), |
| 13472 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13473 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13474 | |
| 13475 | // Wait for response from SSL request. |
| 13476 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13477 | std::string response_data; |
| 13478 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13479 | EXPECT_EQ("hello world", response_data); |
| 13480 | |
| 13481 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13482 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13483 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13484 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13485 | |
| 13486 | // The HTTP request can now complete. |
| 13487 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13488 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13489 | EXPECT_EQ("falafel", response_data); |
| 13490 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13491 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13492 | } |
| 13493 | |
| 13494 | // Tests that when a SSL connection is established but there's no corresponding |
| 13495 | // request that needs it, the new socket is closed if the transport socket pool |
| 13496 | // is stalled on the global socket limit. |
| 13497 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13498 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13499 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13500 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13501 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13502 | |
| 13503 | // Set up an ssl request. |
| 13504 | |
| 13505 | HttpRequestInfo ssl_request; |
| 13506 | ssl_request.method = "GET"; |
| 13507 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13508 | |
| 13509 | // No data will be sent on the SSL socket. |
| 13510 | StaticSocketDataProvider ssl_data; |
| 13511 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13512 | |
| 13513 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13515 | |
| 13516 | // Set up HTTP request. |
| 13517 | |
| 13518 | HttpRequestInfo http_request; |
| 13519 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13520 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13521 | |
| 13522 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13523 | MockWrite( |
| 13524 | "GET / HTTP/1.1\r\n" |
| 13525 | "Host: www.example.org\r\n" |
| 13526 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13527 | }; |
| 13528 | MockRead http_reads[] = { |
| 13529 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13530 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13531 | MockRead("falafel"), |
| 13532 | MockRead(SYNCHRONOUS, OK), |
| 13533 | }; |
| 13534 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13535 | http_writes, arraysize(http_writes)); |
| 13536 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13537 | |
| 13538 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13539 | |
| 13540 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13541 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13542 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13543 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13544 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 13545 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 13546 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13547 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13548 | |
| 13549 | // Start the HTTP request. Pool should stall. |
| 13550 | TestCompletionCallback http_callback; |
| 13551 | scoped_ptr<HttpTransaction> http_trans( |
| 13552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13553 | ASSERT_EQ(ERR_IO_PENDING, |
| 13554 | http_trans->Start(&http_request, http_callback.callback(), |
| 13555 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13556 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13557 | |
| 13558 | // The SSL connection will automatically be closed once the connection is |
| 13559 | // established, to let the HTTP request start. |
| 13560 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13561 | std::string response_data; |
| 13562 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13563 | EXPECT_EQ("falafel", response_data); |
| 13564 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13565 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13566 | } |
| 13567 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13568 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13569 | ScopedVector<UploadElementReader> element_readers; |
| 13570 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13571 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13572 | |
| 13573 | HttpRequestInfo request; |
| 13574 | request.method = "POST"; |
| 13575 | request.url = GURL("http://www.foo.com/"); |
| 13576 | request.upload_data_stream = &upload_data_stream; |
| 13577 | request.load_flags = 0; |
| 13578 | |
| 13579 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13580 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13582 | // Send headers successfully, but get an error while sending the body. |
| 13583 | MockWrite data_writes[] = { |
| 13584 | MockWrite("POST / HTTP/1.1\r\n" |
| 13585 | "Host: www.foo.com\r\n" |
| 13586 | "Connection: keep-alive\r\n" |
| 13587 | "Content-Length: 3\r\n\r\n"), |
| 13588 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13589 | }; |
| 13590 | |
| 13591 | MockRead data_reads[] = { |
| 13592 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13593 | MockRead("hello world"), |
| 13594 | MockRead(SYNCHRONOUS, OK), |
| 13595 | }; |
| 13596 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13597 | arraysize(data_writes)); |
| 13598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13599 | |
| 13600 | TestCompletionCallback callback; |
| 13601 | |
| 13602 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13603 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13604 | |
| 13605 | rv = callback.WaitForResult(); |
| 13606 | EXPECT_EQ(OK, rv); |
| 13607 | |
| 13608 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13609 | ASSERT_TRUE(response != NULL); |
| 13610 | |
| 13611 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13612 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13613 | |
| 13614 | std::string response_data; |
| 13615 | rv = ReadTransaction(trans.get(), &response_data); |
| 13616 | EXPECT_EQ(OK, rv); |
| 13617 | EXPECT_EQ("hello world", response_data); |
| 13618 | } |
| 13619 | |
| 13620 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13621 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13622 | TEST_P(HttpNetworkTransactionTest, |
| 13623 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13624 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13625 | MockWrite data_writes[] = { |
| 13626 | MockWrite("GET / HTTP/1.1\r\n" |
| 13627 | "Host: www.foo.com\r\n" |
| 13628 | "Connection: keep-alive\r\n\r\n"), |
| 13629 | MockWrite("POST / HTTP/1.1\r\n" |
| 13630 | "Host: www.foo.com\r\n" |
| 13631 | "Connection: keep-alive\r\n" |
| 13632 | "Content-Length: 3\r\n\r\n"), |
| 13633 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13634 | }; |
| 13635 | |
| 13636 | MockRead data_reads[] = { |
| 13637 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 13638 | "Content-Length: 14\r\n\r\n"), |
| 13639 | MockRead("first response"), |
| 13640 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 13641 | "Content-Length: 15\r\n\r\n"), |
| 13642 | MockRead("second response"), |
| 13643 | MockRead(SYNCHRONOUS, OK), |
| 13644 | }; |
| 13645 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13646 | arraysize(data_writes)); |
| 13647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13648 | |
| 13649 | TestCompletionCallback callback; |
| 13650 | HttpRequestInfo request1; |
| 13651 | request1.method = "GET"; |
| 13652 | request1.url = GURL("http://www.foo.com/"); |
| 13653 | request1.load_flags = 0; |
| 13654 | |
| 13655 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13657 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 13658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13659 | |
| 13660 | rv = callback.WaitForResult(); |
| 13661 | EXPECT_EQ(OK, rv); |
| 13662 | |
| 13663 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13664 | ASSERT_TRUE(response1 != NULL); |
| 13665 | |
| 13666 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 13667 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 13668 | |
| 13669 | std::string response_data1; |
| 13670 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 13671 | EXPECT_EQ(OK, rv); |
| 13672 | EXPECT_EQ("first response", response_data1); |
| 13673 | // Delete the transaction to release the socket back into the socket pool. |
| 13674 | trans1.reset(); |
| 13675 | |
| 13676 | ScopedVector<UploadElementReader> element_readers; |
| 13677 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13678 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13679 | |
| 13680 | HttpRequestInfo request2; |
| 13681 | request2.method = "POST"; |
| 13682 | request2.url = GURL("http://www.foo.com/"); |
| 13683 | request2.upload_data_stream = &upload_data_stream; |
| 13684 | request2.load_flags = 0; |
| 13685 | |
| 13686 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13688 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 13689 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13690 | |
| 13691 | rv = callback.WaitForResult(); |
| 13692 | EXPECT_EQ(OK, rv); |
| 13693 | |
| 13694 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 13695 | ASSERT_TRUE(response2 != NULL); |
| 13696 | |
| 13697 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 13698 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 13699 | |
| 13700 | std::string response_data2; |
| 13701 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 13702 | EXPECT_EQ(OK, rv); |
| 13703 | EXPECT_EQ("second response", response_data2); |
| 13704 | } |
| 13705 | |
| 13706 | TEST_P(HttpNetworkTransactionTest, |
| 13707 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 13708 | ScopedVector<UploadElementReader> element_readers; |
| 13709 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13710 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13711 | |
| 13712 | HttpRequestInfo request; |
| 13713 | request.method = "POST"; |
| 13714 | request.url = GURL("http://www.foo.com/"); |
| 13715 | request.upload_data_stream = &upload_data_stream; |
| 13716 | request.load_flags = 0; |
| 13717 | |
| 13718 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13719 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13720 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13721 | // Send headers successfully, but get an error while sending the body. |
| 13722 | MockWrite data_writes[] = { |
| 13723 | MockWrite("POST / HTTP/1.1\r\n" |
| 13724 | "Host: www.foo.com\r\n" |
| 13725 | "Connection: keep-alive\r\n" |
| 13726 | "Content-Length: 3\r\n\r\n" |
| 13727 | "fo"), |
| 13728 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13729 | }; |
| 13730 | |
| 13731 | MockRead data_reads[] = { |
| 13732 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13733 | MockRead("hello world"), |
| 13734 | MockRead(SYNCHRONOUS, OK), |
| 13735 | }; |
| 13736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13737 | arraysize(data_writes)); |
| 13738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13739 | |
| 13740 | TestCompletionCallback callback; |
| 13741 | |
| 13742 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13744 | |
| 13745 | rv = callback.WaitForResult(); |
| 13746 | EXPECT_EQ(OK, rv); |
| 13747 | |
| 13748 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13749 | ASSERT_TRUE(response != NULL); |
| 13750 | |
| 13751 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13752 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13753 | |
| 13754 | std::string response_data; |
| 13755 | rv = ReadTransaction(trans.get(), &response_data); |
| 13756 | EXPECT_EQ(OK, rv); |
| 13757 | EXPECT_EQ("hello world", response_data); |
| 13758 | } |
| 13759 | |
| 13760 | // This tests the more common case than the previous test, where headers and |
| 13761 | // body are not merged into a single request. |
| 13762 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 13763 | ScopedVector<UploadElementReader> element_readers; |
| 13764 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13765 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13766 | |
| 13767 | HttpRequestInfo request; |
| 13768 | request.method = "POST"; |
| 13769 | request.url = GURL("http://www.foo.com/"); |
| 13770 | request.upload_data_stream = &upload_data_stream; |
| 13771 | request.load_flags = 0; |
| 13772 | |
| 13773 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13774 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13775 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13776 | // Send headers successfully, but get an error while sending the body. |
| 13777 | MockWrite data_writes[] = { |
| 13778 | MockWrite("POST / HTTP/1.1\r\n" |
| 13779 | "Host: www.foo.com\r\n" |
| 13780 | "Connection: keep-alive\r\n" |
| 13781 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 13782 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13783 | }; |
| 13784 | |
| 13785 | MockRead data_reads[] = { |
| 13786 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13787 | MockRead("hello world"), |
| 13788 | MockRead(SYNCHRONOUS, OK), |
| 13789 | }; |
| 13790 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13791 | arraysize(data_writes)); |
| 13792 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13793 | |
| 13794 | TestCompletionCallback callback; |
| 13795 | |
| 13796 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13797 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13798 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 13799 | // they can't be merged with the body in a single send. Not currently |
| 13800 | // necessary since a chunked body is never merged with headers, but this makes |
| 13801 | // the test more future proof. |
| 13802 | base::RunLoop().RunUntilIdle(); |
| 13803 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13804 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13805 | |
| 13806 | rv = callback.WaitForResult(); |
| 13807 | EXPECT_EQ(OK, rv); |
| 13808 | |
| 13809 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13810 | ASSERT_TRUE(response != NULL); |
| 13811 | |
| 13812 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13813 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13814 | |
| 13815 | std::string response_data; |
| 13816 | rv = ReadTransaction(trans.get(), &response_data); |
| 13817 | EXPECT_EQ(OK, rv); |
| 13818 | EXPECT_EQ("hello world", response_data); |
| 13819 | } |
| 13820 | |
| 13821 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 13822 | ScopedVector<UploadElementReader> element_readers; |
| 13823 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13824 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13825 | |
| 13826 | HttpRequestInfo request; |
| 13827 | request.method = "POST"; |
| 13828 | request.url = GURL("http://www.foo.com/"); |
| 13829 | request.upload_data_stream = &upload_data_stream; |
| 13830 | request.load_flags = 0; |
| 13831 | |
| 13832 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13833 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13835 | |
| 13836 | MockWrite data_writes[] = { |
| 13837 | MockWrite("POST / HTTP/1.1\r\n" |
| 13838 | "Host: www.foo.com\r\n" |
| 13839 | "Connection: keep-alive\r\n" |
| 13840 | "Content-Length: 3\r\n\r\n"), |
| 13841 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13842 | }; |
| 13843 | |
| 13844 | MockRead data_reads[] = { |
| 13845 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13846 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13847 | MockRead("hello world"), |
| 13848 | MockRead(SYNCHRONOUS, OK), |
| 13849 | }; |
| 13850 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13851 | arraysize(data_writes)); |
| 13852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13853 | |
| 13854 | TestCompletionCallback callback; |
| 13855 | |
| 13856 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13857 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13858 | |
| 13859 | rv = callback.WaitForResult(); |
| 13860 | EXPECT_EQ(OK, rv); |
| 13861 | |
| 13862 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13863 | ASSERT_TRUE(response != NULL); |
| 13864 | |
| 13865 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13866 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13867 | |
| 13868 | std::string response_data; |
| 13869 | rv = ReadTransaction(trans.get(), &response_data); |
| 13870 | EXPECT_EQ(OK, rv); |
| 13871 | EXPECT_EQ("hello world", response_data); |
| 13872 | } |
| 13873 | |
| 13874 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13875 | ScopedVector<UploadElementReader> element_readers; |
| 13876 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13877 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13878 | |
| 13879 | HttpRequestInfo request; |
| 13880 | request.method = "POST"; |
| 13881 | request.url = GURL("http://www.foo.com/"); |
| 13882 | request.upload_data_stream = &upload_data_stream; |
| 13883 | request.load_flags = 0; |
| 13884 | |
| 13885 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13886 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13887 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13888 | // Send headers successfully, but get an error while sending the body. |
| 13889 | MockWrite data_writes[] = { |
| 13890 | MockWrite("POST / HTTP/1.1\r\n" |
| 13891 | "Host: www.foo.com\r\n" |
| 13892 | "Connection: keep-alive\r\n" |
| 13893 | "Content-Length: 3\r\n\r\n"), |
| 13894 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13895 | }; |
| 13896 | |
| 13897 | MockRead data_reads[] = { |
| 13898 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13899 | MockRead("hello world"), |
| 13900 | MockRead(SYNCHRONOUS, OK), |
| 13901 | }; |
| 13902 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13903 | arraysize(data_writes)); |
| 13904 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13905 | |
| 13906 | TestCompletionCallback callback; |
| 13907 | |
| 13908 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13909 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13910 | |
| 13911 | rv = callback.WaitForResult(); |
| 13912 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13913 | } |
| 13914 | |
| 13915 | TEST_P(HttpNetworkTransactionTest, |
| 13916 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13917 | ScopedVector<UploadElementReader> element_readers; |
| 13918 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13919 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13920 | |
| 13921 | HttpRequestInfo request; |
| 13922 | request.method = "POST"; |
| 13923 | request.url = GURL("http://www.foo.com/"); |
| 13924 | request.upload_data_stream = &upload_data_stream; |
| 13925 | request.load_flags = 0; |
| 13926 | |
| 13927 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13928 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13930 | // Send headers successfully, but get an error while sending the body. |
| 13931 | MockWrite data_writes[] = { |
| 13932 | MockWrite("POST / HTTP/1.1\r\n" |
| 13933 | "Host: www.foo.com\r\n" |
| 13934 | "Connection: keep-alive\r\n" |
| 13935 | "Content-Length: 3\r\n\r\n"), |
| 13936 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13937 | }; |
| 13938 | |
| 13939 | MockRead data_reads[] = { |
| 13940 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13941 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13942 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13943 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13944 | MockRead(SYNCHRONOUS, OK), |
| 13945 | }; |
| 13946 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13947 | arraysize(data_writes)); |
| 13948 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13949 | |
| 13950 | TestCompletionCallback callback; |
| 13951 | |
| 13952 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13953 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13954 | |
| 13955 | rv = callback.WaitForResult(); |
| 13956 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13957 | } |
| 13958 | |
| 13959 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13960 | ScopedVector<UploadElementReader> element_readers; |
| 13961 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13962 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13963 | |
| 13964 | HttpRequestInfo request; |
| 13965 | request.method = "POST"; |
| 13966 | request.url = GURL("http://www.foo.com/"); |
| 13967 | request.upload_data_stream = &upload_data_stream; |
| 13968 | request.load_flags = 0; |
| 13969 | |
| 13970 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13971 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13972 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13973 | // Send headers successfully, but get an error while sending the body. |
| 13974 | MockWrite data_writes[] = { |
| 13975 | MockWrite("POST / HTTP/1.1\r\n" |
| 13976 | "Host: www.foo.com\r\n" |
| 13977 | "Connection: keep-alive\r\n" |
| 13978 | "Content-Length: 3\r\n\r\n"), |
| 13979 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13980 | }; |
| 13981 | |
| 13982 | MockRead data_reads[] = { |
| 13983 | MockRead("HTTP 0.9 rocks!"), |
| 13984 | MockRead(SYNCHRONOUS, OK), |
| 13985 | }; |
| 13986 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13987 | arraysize(data_writes)); |
| 13988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13989 | |
| 13990 | TestCompletionCallback callback; |
| 13991 | |
| 13992 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13994 | |
| 13995 | rv = callback.WaitForResult(); |
| 13996 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13997 | } |
| 13998 | |
| 13999 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14000 | ScopedVector<UploadElementReader> element_readers; |
| 14001 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14002 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14003 | |
| 14004 | HttpRequestInfo request; |
| 14005 | request.method = "POST"; |
| 14006 | request.url = GURL("http://www.foo.com/"); |
| 14007 | request.upload_data_stream = &upload_data_stream; |
| 14008 | request.load_flags = 0; |
| 14009 | |
| 14010 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14011 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14012 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14013 | // Send headers successfully, but get an error while sending the body. |
| 14014 | MockWrite data_writes[] = { |
| 14015 | MockWrite("POST / HTTP/1.1\r\n" |
| 14016 | "Host: www.foo.com\r\n" |
| 14017 | "Connection: keep-alive\r\n" |
| 14018 | "Content-Length: 3\r\n\r\n"), |
| 14019 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14020 | }; |
| 14021 | |
| 14022 | MockRead data_reads[] = { |
| 14023 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14024 | MockRead(SYNCHRONOUS, OK), |
| 14025 | }; |
| 14026 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14027 | arraysize(data_writes)); |
| 14028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14029 | |
| 14030 | TestCompletionCallback callback; |
| 14031 | |
| 14032 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14034 | |
| 14035 | rv = callback.WaitForResult(); |
| 14036 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14037 | } |
| 14038 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14039 | // Verify that proxy headers are not sent to the destination server when |
| 14040 | // establishing a tunnel for a secure WebSocket connection. |
| 14041 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14042 | HttpRequestInfo request; |
| 14043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14044 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14045 | AddWebSocketHeaders(&request.extra_headers); |
| 14046 | |
| 14047 | // Configure against proxy server "myproxy:70". |
| 14048 | session_deps_.proxy_service.reset( |
| 14049 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14050 | |
| 14051 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14052 | |
| 14053 | // Since a proxy is configured, try to establish a tunnel. |
| 14054 | MockWrite data_writes[] = { |
| 14055 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14056 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14057 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14058 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14059 | |
| 14060 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14061 | // be issuing -- the final header line contains the credentials. |
| 14062 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14063 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14064 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14065 | "Proxy-Connection: keep-alive\r\n" |
| 14066 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14067 | |
| 14068 | MockWrite( |
| 14069 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14070 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14071 | "Connection: Upgrade\r\n" |
| 14072 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14073 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14074 | "Sec-WebSocket-Version: 13\r\n" |
| 14075 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14076 | }; |
| 14077 | |
| 14078 | // The proxy responds to the connect with a 407, using a persistent |
| 14079 | // connection. |
| 14080 | MockRead data_reads[] = { |
| 14081 | // No credentials. |
| 14082 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14083 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 14084 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 14085 | |
| 14086 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14087 | |
| 14088 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14089 | MockRead("Upgrade: websocket\r\n"), |
| 14090 | MockRead("Connection: Upgrade\r\n"), |
| 14091 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14092 | }; |
| 14093 | |
| 14094 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14095 | arraysize(data_writes)); |
| 14096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14097 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14099 | |
| 14100 | scoped_ptr<HttpTransaction> trans( |
| 14101 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14102 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14103 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14104 | &websocket_stream_create_helper); |
| 14105 | |
| 14106 | { |
| 14107 | TestCompletionCallback callback; |
| 14108 | |
| 14109 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14110 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14111 | |
| 14112 | rv = callback.WaitForResult(); |
| 14113 | EXPECT_EQ(OK, rv); |
| 14114 | } |
| 14115 | |
| 14116 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14117 | ASSERT_TRUE(response); |
| 14118 | ASSERT_TRUE(response->headers.get()); |
| 14119 | EXPECT_EQ(407, response->headers->response_code()); |
| 14120 | |
| 14121 | { |
| 14122 | TestCompletionCallback callback; |
| 14123 | |
| 14124 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14125 | callback.callback()); |
| 14126 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14127 | |
| 14128 | rv = callback.WaitForResult(); |
| 14129 | EXPECT_EQ(OK, rv); |
| 14130 | } |
| 14131 | |
| 14132 | response = trans->GetResponseInfo(); |
| 14133 | ASSERT_TRUE(response); |
| 14134 | ASSERT_TRUE(response->headers.get()); |
| 14135 | |
| 14136 | EXPECT_EQ(101, response->headers->response_code()); |
| 14137 | |
| 14138 | trans.reset(); |
| 14139 | session->CloseAllConnections(); |
| 14140 | } |
| 14141 | |
| 14142 | // Verify that proxy headers are not sent to the destination server when |
| 14143 | // establishing a tunnel for an insecure WebSocket connection. |
| 14144 | // This requires the authentication info to be injected into the auth cache |
| 14145 | // due to crbug.com/395064 |
| 14146 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14147 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14148 | HttpRequestInfo request; |
| 14149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14150 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14151 | AddWebSocketHeaders(&request.extra_headers); |
| 14152 | |
| 14153 | // Configure against proxy server "myproxy:70". |
| 14154 | session_deps_.proxy_service.reset( |
| 14155 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14156 | |
| 14157 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14158 | |
| 14159 | MockWrite data_writes[] = { |
| 14160 | // Try to establish a tunnel for the WebSocket connection, with |
| 14161 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14162 | // they cannot and will not use the same TCP/IP connection as the |
| 14163 | // preflight HTTP request. |
| 14164 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14165 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14166 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14167 | "Proxy-Connection: keep-alive\r\n" |
| 14168 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14169 | |
| 14170 | MockWrite( |
| 14171 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14172 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14173 | "Connection: Upgrade\r\n" |
| 14174 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14175 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14176 | "Sec-WebSocket-Version: 13\r\n" |
| 14177 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14178 | }; |
| 14179 | |
| 14180 | MockRead data_reads[] = { |
| 14181 | // HTTP CONNECT with credentials. |
| 14182 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14183 | |
| 14184 | // WebSocket connection established inside tunnel. |
| 14185 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14186 | MockRead("Upgrade: websocket\r\n"), |
| 14187 | MockRead("Connection: Upgrade\r\n"), |
| 14188 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14189 | }; |
| 14190 | |
| 14191 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14192 | arraysize(data_writes)); |
| 14193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14194 | |
| 14195 | session->http_auth_cache()->Add( |
| 14196 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14197 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14198 | |
| 14199 | scoped_ptr<HttpTransaction> trans( |
| 14200 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14201 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14202 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14203 | &websocket_stream_create_helper); |
| 14204 | |
| 14205 | TestCompletionCallback callback; |
| 14206 | |
| 14207 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14208 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14209 | |
| 14210 | rv = callback.WaitForResult(); |
| 14211 | EXPECT_EQ(OK, rv); |
| 14212 | |
| 14213 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14214 | ASSERT_TRUE(response); |
| 14215 | ASSERT_TRUE(response->headers.get()); |
| 14216 | |
| 14217 | EXPECT_EQ(101, response->headers->response_code()); |
| 14218 | |
| 14219 | trans.reset(); |
| 14220 | session->CloseAllConnections(); |
| 14221 | } |
| 14222 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14223 | } // namespace net |