[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] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 14 | #include "base/file_util.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 15 | #include "base/files/file_path.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 17 | #include "base/memory/scoped_ptr.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 18 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 19 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 20 | #include "base/test/test_file_util.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 21 | #include "net/base/auth.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 22 | #include "net/base/capturing_net_log.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 23 | #include "net/base/completion_callback.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 24 | #include "net/base/load_timing_info.h" |
| 25 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 26 | #include "net/base/net_log.h" |
| 27 | #include "net/base/net_log_unittest.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 28 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 29 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 30 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 31 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 32 | #include "net/base/upload_data_stream.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 33 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 34 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 35 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 36 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 37 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 38 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 39 | #include "net/http/http_auth_handler_ntlm.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 40 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 42 | #include "net/http/http_network_session_peer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 43 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 44 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 45 | #include "net/http/http_stream_factory.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | #include "net/http/http_transaction_unittest.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 47 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 48 | #include "net/proxy/proxy_resolver.h" |
| 49 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 50 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 51 | #include "net/socket/client_socket_pool_manager.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 52 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 53 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 54 | #include "net/socket/socket_test_util.h" |
| 55 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 56 | #include "net/spdy/spdy_framer.h" |
| 57 | #include "net/spdy/spdy_session.h" |
| 58 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 59 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 60 | #include "net/ssl/ssl_cert_request_info.h" |
| 61 | #include "net/ssl/ssl_config_service_defaults.h" |
| 62 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 63 | #include "net/test/cert_test_util.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 64 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 65 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 66 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 67 | |
| 68 | //----------------------------------------------------------------------------- |
| 69 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 70 | namespace { |
| 71 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 72 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 73 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 74 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 75 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 76 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 77 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 78 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 79 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 80 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 81 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 82 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 83 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 84 | |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 85 | int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { |
| 86 | return session->GetTransportSocketPool( |
| 87 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 88 | } |
| 89 | |
| 90 | int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { |
| 91 | return session->GetSSLSocketPool( |
| 92 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 93 | } |
| 94 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 95 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 96 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 97 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 98 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 99 | if (!params) |
| 100 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 101 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 102 | if (!params->GetList("headers", &header_list)) |
| 103 | return false; |
| 104 | std::string double_quote_headers; |
| 105 | base::JSONWriter::Write(header_list, &double_quote_headers); |
| 106 | ReplaceChars(double_quote_headers, "\"", "'", headers); |
| 107 | return true; |
| 108 | } |
| 109 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 110 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 111 | // used. |
| 112 | void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { |
| 113 | EXPECT_TRUE(load_timing_info.socket_reused); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 114 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 115 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 116 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 117 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 118 | |
| 119 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 120 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 121 | |
| 122 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 123 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 124 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 125 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 126 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 127 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 128 | } |
| 129 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 130 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 131 | // used. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 132 | void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, |
| 133 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 134 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 135 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 136 | |
| 137 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 138 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 139 | |
| 140 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 141 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 142 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 143 | load_timing_info.send_start); |
| 144 | |
| 145 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 146 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 147 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 149 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 150 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 154 | // used. |
| 155 | void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { |
| 156 | EXPECT_TRUE(load_timing_info.socket_reused); |
| 157 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 158 | |
| 159 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 160 | |
| 161 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 162 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 163 | load_timing_info.proxy_resolve_end); |
| 164 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 165 | load_timing_info.send_start); |
| 166 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 167 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 168 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 169 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 170 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 171 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 175 | // used. |
| 176 | void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, |
| 177 | int connect_timing_flags) { |
| 178 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 179 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 180 | |
| 181 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 182 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 183 | load_timing_info.proxy_resolve_end); |
| 184 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 185 | load_timing_info.connect_timing.connect_start); |
| 186 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 187 | connect_timing_flags); |
| 188 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 189 | load_timing_info.send_start); |
| 190 | |
| 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] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 199 | } // namespace |
| 200 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 201 | namespace net { |
| 202 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 203 | namespace { |
| 204 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 205 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 206 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 209 | } // namespace |
| 210 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 211 | class HttpNetworkTransactionTest |
| 212 | : public PlatformTest, |
| 213 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 214 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 215 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 216 | // Important to restore the per-pool limit first, since the pool limit must |
| 217 | // always be greater than group limit, and the tests reduce both limits. |
| 218 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 219 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 220 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 221 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 222 | } |
| 223 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 224 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 225 | HttpNetworkTransactionTest() |
| 226 | : spdy_util_(GetParam()), |
| 227 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 228 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 229 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 230 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 231 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 232 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 233 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 234 | struct SimpleGetHelperResult { |
| 235 | int rv; |
| 236 | std::string status_line; |
| 237 | std::string response_data; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 238 | LoadTimingInfo load_timing_info; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 239 | }; |
| 240 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 241 | virtual void SetUp() { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 242 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 243 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 246 | virtual void TearDown() { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 247 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 248 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 249 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 250 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 251 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 252 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 253 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 254 | HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame^] | 255 | HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 258 | // This is the expected return from a current server advertising SPDY. |
| 259 | std::string GetAlternateProtocolHttpHeader() { |
| 260 | return |
| 261 | std::string("Alternate-Protocol: 443:") + |
| 262 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())) + |
| 263 | "\r\n\r\n"; |
| 264 | } |
| 265 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 266 | // Either |write_failure| specifies a write failure or |read_failure| |
| 267 | // specifies a read failure when using a reused socket. In either case, the |
| 268 | // failure should cause the network transaction to resend the request, and the |
| 269 | // other argument should be NULL. |
| 270 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 271 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 272 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 273 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 274 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 275 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 276 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 277 | HttpRequestInfo request; |
| 278 | request.method = "GET"; |
| 279 | request.url = GURL("http://www.google.com/"); |
| 280 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 281 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 283 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 284 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 285 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 286 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 287 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 288 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 289 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 290 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 292 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 293 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 294 | EXPECT_TRUE(log.bound().IsLoggingAllEvents()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 295 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 297 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 298 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 299 | |
| 300 | // Even in the failure cases that use this function, connections are always |
| 301 | // successfully established before the error. |
| 302 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 303 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 304 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 305 | if (out.rv != OK) |
| 306 | return out; |
| 307 | |
| 308 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 309 | // Can't use ASSERT_* inside helper functions like this, so |
| 310 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 311 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 312 | out.rv = ERR_UNEXPECTED; |
| 313 | return out; |
| 314 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 315 | out.status_line = response->headers->GetStatusLine(); |
| 316 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 317 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 318 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 319 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 320 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 321 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 322 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 323 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 324 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 325 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 326 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 327 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 328 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 329 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 330 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 331 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 332 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 333 | std::string line; |
| 334 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 335 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 336 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 337 | HttpRequestHeaders request_headers; |
| 338 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 339 | std::string value; |
| 340 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 341 | EXPECT_EQ("www.google.com", value); |
| 342 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 343 | EXPECT_EQ("keep-alive", value); |
| 344 | |
| 345 | std::string response_headers; |
| 346 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 347 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 348 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 349 | |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 350 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 351 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 352 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 353 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 354 | size_t reads_count) { |
| 355 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 356 | StaticSocketDataProvider* data[] = { &reads }; |
| 357 | return SimpleGetHelperForData(data, 1); |
| 358 | } |
| 359 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 360 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 361 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 362 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 363 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 364 | |
| 365 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 366 | |
| 367 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 368 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 369 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 370 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 371 | |
| 372 | // Original socket limits. Some tests set these. Safest to always restore |
| 373 | // them once each test has been run. |
| 374 | int old_max_group_sockets_; |
| 375 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 376 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 377 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 378 | INSTANTIATE_TEST_CASE_P( |
| 379 | NextProto, |
| 380 | HttpNetworkTransactionTest, |
| 381 | testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); |
| 382 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 383 | namespace { |
| 384 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 385 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 386 | void FillLargeHeadersString(std::string* str, int size) { |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 387 | const char* row = |
| 388 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 389 | const int sizeof_row = strlen(row); |
| 390 | const int num_rows = static_cast<int>( |
| 391 | ceil(static_cast<float>(size) / sizeof_row)); |
| 392 | const int sizeof_data = num_rows * sizeof_row; |
| 393 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 394 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 395 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 396 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 397 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 398 | } |
| 399 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 400 | // Alternative functions that eliminate randomness and dependency on the local |
| 401 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 402 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 403 | static const uint8 bytes[] = { |
| 404 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 405 | }; |
| 406 | static size_t current_byte = 0; |
| 407 | for (size_t i = 0; i < n; ++i) { |
| 408 | output[i] = bytes[current_byte++]; |
| 409 | current_byte %= arraysize(bytes); |
| 410 | } |
| 411 | } |
| 412 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 413 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 414 | static const uint8 bytes[] = { |
| 415 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 416 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 417 | }; |
| 418 | static size_t current_byte = 0; |
| 419 | for (size_t i = 0; i < n; ++i) { |
| 420 | output[i] = bytes[current_byte++]; |
| 421 | current_byte %= arraysize(bytes); |
| 422 | } |
| 423 | } |
| 424 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 425 | std::string MockGetHostName() { |
| 426 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 429 | template<typename ParentPool> |
| 430 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 431 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 432 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 433 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 434 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 435 | const std::string last_group_name_received() const { |
| 436 | return last_group_name_; |
| 437 | } |
| 438 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 439 | virtual int RequestSocket(const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 440 | const void* socket_params, |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 441 | RequestPriority priority, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 442 | ClientSocketHandle* handle, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 443 | const CompletionCallback& callback, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 444 | const BoundNetLog& net_log) { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 445 | last_group_name_ = group_name; |
| 446 | return ERR_IO_PENDING; |
| 447 | } |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 448 | virtual void CancelRequest(const std::string& group_name, |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 449 | ClientSocketHandle* handle) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 450 | virtual void ReleaseSocket(const std::string& group_name, |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 451 | StreamSocket* socket, |
[email protected] | 9f95c69 | 2011-02-11 19:20:19 | [diff] [blame] | 452 | int id) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 453 | virtual void CloseIdleSockets() {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 454 | virtual int IdleSocketCount() const { |
| 455 | return 0; |
| 456 | } |
| 457 | virtual int IdleSocketCountInGroup(const std::string& group_name) const { |
| 458 | return 0; |
| 459 | } |
| 460 | virtual LoadState GetLoadState(const std::string& group_name, |
| 461 | const ClientSocketHandle* handle) const { |
| 462 | return LOAD_STATE_IDLE; |
| 463 | } |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 464 | virtual base::TimeDelta ConnectionTimeout() const { |
| 465 | return base::TimeDelta(); |
| 466 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 467 | |
| 468 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 469 | std::string last_group_name_; |
| 470 | }; |
| 471 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 472 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 473 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 474 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 475 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 476 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 477 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 478 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 479 | CaptureGroupNameSSLSocketPool; |
| 480 | |
| 481 | template<typename ParentPool> |
| 482 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 483 | HostResolver* host_resolver, |
| 484 | CertVerifier* /* cert_verifier */) |
| 485 | : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 486 | |
| 487 | template<> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 488 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 489 | HostResolver* host_resolver, |
| 490 | CertVerifier* /* cert_verifier */) |
| 491 | : HttpProxyClientSocketPool(0, 0, NULL, host_resolver, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 492 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 493 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 494 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 495 | HostResolver* host_resolver, |
| 496 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 497 | : SSLClientSocketPool(0, |
| 498 | 0, |
| 499 | NULL, |
| 500 | host_resolver, |
| 501 | cert_verifier, |
| 502 | NULL, |
| 503 | NULL, |
| 504 | std::string(), |
| 505 | NULL, |
| 506 | NULL, |
| 507 | NULL, |
| 508 | NULL, |
| 509 | NULL, |
| 510 | NULL) {} |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 511 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 512 | //----------------------------------------------------------------------------- |
| 513 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 514 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 515 | // configured for common cases. |
| 516 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 517 | if (!auth_challenge) |
| 518 | return false; |
| 519 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 520 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 521 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 522 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 523 | return true; |
| 524 | } |
| 525 | |
| 526 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 527 | if (!auth_challenge) |
| 528 | return false; |
| 529 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 530 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 531 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 532 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 537 | if (!auth_challenge) |
| 538 | return false; |
| 539 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 540 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 541 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 542 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 543 | return true; |
| 544 | } |
| 545 | |
| 546 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 547 | if (!auth_challenge) |
| 548 | return false; |
| 549 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 550 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 551 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 552 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 553 | return true; |
| 554 | } |
| 555 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 556 | } // namespace |
| 557 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 558 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 559 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 560 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 561 | CreateSession(&session_deps_))); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 562 | } |
| 563 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 564 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 565 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 566 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 567 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 568 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 569 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 570 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 571 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 572 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 573 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 574 | EXPECT_EQ("hello world", out.response_data); |
| 575 | } |
| 576 | |
| 577 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 578 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 579 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 580 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 582 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 583 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 584 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 585 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 586 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 587 | EXPECT_EQ("hello world", out.response_data); |
| 588 | } |
| 589 | |
| 590 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 591 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 592 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 593 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 594 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 595 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 596 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 597 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 598 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 599 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 600 | EXPECT_EQ("DATA", out.response_data); |
| 601 | } |
| 602 | |
| 603 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 604 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 605 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 606 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 608 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 609 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 610 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 611 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 612 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 613 | EXPECT_EQ("DATA", out.response_data); |
| 614 | } |
| 615 | |
| 616 | // 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] | 617 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 618 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 619 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 620 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 621 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 622 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 623 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 624 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 625 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 626 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 630 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 631 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 632 | MockRead("\n"), |
| 633 | MockRead("\n"), |
| 634 | MockRead("Q"), |
| 635 | MockRead("J"), |
| 636 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 638 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 639 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 640 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 641 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 642 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 643 | EXPECT_EQ("DATA", out.response_data); |
| 644 | } |
| 645 | |
| 646 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 647 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 648 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 649 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 650 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 651 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 652 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 653 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 654 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 655 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 656 | EXPECT_EQ("HTT", out.response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 659 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 660 | // persistent connection. The response should still terminate since a 204 |
| 661 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 662 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 663 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 664 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 665 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 667 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 668 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 669 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 670 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 671 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 672 | EXPECT_EQ("", out.response_data); |
| 673 | } |
| 674 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 675 | // A simple request using chunked encoding with some extra data after. |
| 676 | // (Like might be seen in a pipelined response.) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 677 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 678 | MockRead data_reads[] = { |
| 679 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 680 | MockRead("5\r\nHello\r\n"), |
| 681 | MockRead("1\r\n"), |
| 682 | MockRead(" \r\n"), |
| 683 | MockRead("5\r\nworld\r\n"), |
| 684 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 686 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 687 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 688 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 689 | EXPECT_EQ(OK, out.rv); |
| 690 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 691 | EXPECT_EQ("Hello world", out.response_data); |
| 692 | } |
| 693 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 694 | // Next tests deal with http://crbug.com/56344. |
| 695 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 696 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 697 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 698 | MockRead data_reads[] = { |
| 699 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 700 | MockRead("Content-Length: 10\r\n"), |
| 701 | MockRead("Content-Length: 5\r\n\r\n"), |
| 702 | }; |
| 703 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 704 | arraysize(data_reads)); |
| 705 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 706 | } |
| 707 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 708 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 709 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 710 | MockRead data_reads[] = { |
| 711 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 712 | MockRead("Content-Length: 5\r\n"), |
| 713 | MockRead("Content-Length: 5\r\n\r\n"), |
| 714 | MockRead("Hello"), |
| 715 | }; |
| 716 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 717 | arraysize(data_reads)); |
| 718 | EXPECT_EQ(OK, out.rv); |
| 719 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 720 | EXPECT_EQ("Hello", out.response_data); |
| 721 | } |
| 722 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 723 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 724 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 725 | // More than 2 dupes. |
| 726 | { |
| 727 | MockRead data_reads[] = { |
| 728 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 729 | MockRead("Content-Length: 5\r\n"), |
| 730 | MockRead("Content-Length: 5\r\n"), |
| 731 | MockRead("Content-Length: 5\r\n\r\n"), |
| 732 | MockRead("Hello"), |
| 733 | }; |
| 734 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 735 | arraysize(data_reads)); |
| 736 | EXPECT_EQ(OK, out.rv); |
| 737 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 738 | EXPECT_EQ("Hello", out.response_data); |
| 739 | } |
| 740 | // HTTP/1.0 |
| 741 | { |
| 742 | MockRead data_reads[] = { |
| 743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 744 | MockRead("Content-Length: 5\r\n"), |
| 745 | MockRead("Content-Length: 5\r\n"), |
| 746 | MockRead("Content-Length: 5\r\n\r\n"), |
| 747 | MockRead("Hello"), |
| 748 | }; |
| 749 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 750 | arraysize(data_reads)); |
| 751 | EXPECT_EQ(OK, out.rv); |
| 752 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 753 | EXPECT_EQ("Hello", out.response_data); |
| 754 | } |
| 755 | // 2 dupes and one mismatched. |
| 756 | { |
| 757 | MockRead data_reads[] = { |
| 758 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 759 | MockRead("Content-Length: 10\r\n"), |
| 760 | MockRead("Content-Length: 10\r\n"), |
| 761 | MockRead("Content-Length: 5\r\n\r\n"), |
| 762 | }; |
| 763 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 764 | arraysize(data_reads)); |
| 765 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 766 | } |
| 767 | } |
| 768 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 769 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 770 | MultipleContentLengthHeadersTransferEncoding) { |
| 771 | MockRead data_reads[] = { |
| 772 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 773 | MockRead("Content-Length: 666\r\n"), |
| 774 | MockRead("Content-Length: 1337\r\n"), |
| 775 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 776 | MockRead("5\r\nHello\r\n"), |
| 777 | MockRead("1\r\n"), |
| 778 | MockRead(" \r\n"), |
| 779 | MockRead("5\r\nworld\r\n"), |
| 780 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 782 | }; |
| 783 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 784 | arraysize(data_reads)); |
| 785 | EXPECT_EQ(OK, out.rv); |
| 786 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 787 | EXPECT_EQ("Hello world", out.response_data); |
| 788 | } |
| 789 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 790 | // Next tests deal with http://crbug.com/98895. |
| 791 | |
| 792 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 793 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 794 | MockRead data_reads[] = { |
| 795 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 796 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 797 | MockRead("Content-Length: 5\r\n\r\n"), |
| 798 | MockRead("Hello"), |
| 799 | }; |
| 800 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 801 | arraysize(data_reads)); |
| 802 | EXPECT_EQ(OK, out.rv); |
| 803 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 804 | EXPECT_EQ("Hello", out.response_data); |
| 805 | } |
| 806 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 807 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 808 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 809 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 810 | MockRead data_reads[] = { |
| 811 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 812 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 813 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 814 | MockRead("Content-Length: 5\r\n\r\n"), |
| 815 | MockRead("Hello"), |
| 816 | }; |
| 817 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 818 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 819 | EXPECT_EQ(OK, out.rv); |
| 820 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 821 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 825 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 826 | MockRead data_reads[] = { |
| 827 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 828 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 829 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 830 | MockRead("Content-Length: 5\r\n\r\n"), |
| 831 | MockRead("Hello"), |
| 832 | }; |
| 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
| 835 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 836 | } |
| 837 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 838 | // Checks that two identical Location headers result in no error. |
| 839 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 840 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 841 | MockRead data_reads[] = { |
| 842 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 843 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 844 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 845 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 847 | }; |
| 848 | |
| 849 | HttpRequestInfo request; |
| 850 | request.method = "GET"; |
| 851 | request.url = GURL("http://redirect.com/"); |
| 852 | request.load_flags = 0; |
| 853 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 854 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 856 | CreateSession(&session_deps_))); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 857 | |
| 858 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 861 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 863 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 865 | |
| 866 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 867 | |
| 868 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 869 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 870 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 871 | std::string url; |
| 872 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 873 | EXPECT_EQ("http://good.com/", url); |
| 874 | } |
| 875 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 876 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 877 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 878 | MockRead data_reads[] = { |
| 879 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 880 | MockRead("Location: http://good.com/\r\n"), |
| 881 | MockRead("Location: http://evil.com/\r\n"), |
| 882 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 883 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 884 | }; |
| 885 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 886 | arraysize(data_reads)); |
| 887 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 888 | } |
| 889 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 890 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 891 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 892 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 893 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 894 | request.method = "HEAD"; |
| 895 | request.url = GURL("http://www.google.com/"); |
| 896 | request.load_flags = 0; |
| 897 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 898 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 900 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 901 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 902 | MockWrite data_writes1[] = { |
| 903 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 904 | "Host: www.google.com\r\n" |
| 905 | "Connection: keep-alive\r\n" |
| 906 | "Content-Length: 0\r\n\r\n"), |
| 907 | }; |
| 908 | MockRead data_reads1[] = { |
| 909 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 910 | MockRead("Server: Blah\r\n"), |
| 911 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 912 | |
| 913 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 914 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 915 | }; |
| 916 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 917 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 918 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 919 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 921 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 923 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 924 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 925 | |
| 926 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 927 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 928 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 929 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 930 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 931 | |
| 932 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 933 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 934 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 935 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
| 936 | |
| 937 | std::string server_header; |
| 938 | void* iter = NULL; |
| 939 | bool has_server_header = response->headers->EnumerateHeader( |
| 940 | &iter, "Server", &server_header); |
| 941 | EXPECT_TRUE(has_server_header); |
| 942 | EXPECT_EQ("Blah", server_header); |
| 943 | |
| 944 | // Reading should give EOF right away, since there is no message body |
| 945 | // (despite non-zero content-length). |
| 946 | std::string response_data; |
| 947 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 948 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 949 | EXPECT_EQ("", response_data); |
| 950 | } |
| 951 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 952 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 953 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 954 | |
| 955 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 956 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 957 | MockRead("hello"), |
| 958 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 959 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 960 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 961 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 962 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 963 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 964 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 965 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 966 | "hello", "world" |
| 967 | }; |
| 968 | |
| 969 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 970 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 971 | request.method = "GET"; |
| 972 | request.url = GURL("http://www.google.com/"); |
| 973 | request.load_flags = 0; |
| 974 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 975 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 976 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 978 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 980 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 981 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 982 | |
| 983 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 984 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 985 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 986 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 987 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 988 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 989 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 990 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 991 | |
| 992 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 993 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 994 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 995 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 999 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1000 | ScopedVector<UploadElementReader> element_readers; |
| 1001 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 1002 | UploadDataStream upload_data_stream(&element_readers, 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1003 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1004 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1005 | request.method = "POST"; |
| 1006 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1007 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1008 | request.load_flags = 0; |
| 1009 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1010 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1011 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1012 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1013 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1014 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1015 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1016 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1017 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1018 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1019 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1020 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1021 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1023 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1025 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1026 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1027 | |
| 1028 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1029 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1030 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1032 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1033 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1034 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1035 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1036 | |
| 1037 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1038 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1039 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1040 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1041 | } |
| 1042 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1043 | // This test is almost the same as Ignores100 above, but the response contains |
| 1044 | // 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] | 1045 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1046 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1047 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1048 | request.method = "GET"; |
| 1049 | request.url = GURL("http://www.foo.com/"); |
| 1050 | request.load_flags = 0; |
| 1051 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1052 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1053 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1054 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1055 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1056 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1057 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1058 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1059 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1061 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1062 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1065 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1067 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1068 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1069 | |
| 1070 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1071 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1072 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1074 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1075 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1076 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1077 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1078 | |
| 1079 | std::string response_data; |
| 1080 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1081 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1082 | EXPECT_EQ("hello world", response_data); |
| 1083 | } |
| 1084 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1085 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1086 | HttpRequestInfo request; |
| 1087 | request.method = "POST"; |
| 1088 | request.url = GURL("http://www.foo.com/"); |
| 1089 | request.load_flags = 0; |
| 1090 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1091 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1092 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1093 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1094 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1095 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1096 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1097 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1098 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1102 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1104 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1106 | |
| 1107 | rv = callback.WaitForResult(); |
| 1108 | EXPECT_EQ(OK, rv); |
| 1109 | |
| 1110 | std::string response_data; |
| 1111 | rv = ReadTransaction(trans.get(), &response_data); |
| 1112 | EXPECT_EQ(OK, rv); |
| 1113 | EXPECT_EQ("", response_data); |
| 1114 | } |
| 1115 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1116 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1117 | HttpRequestInfo request; |
| 1118 | request.method = "POST"; |
| 1119 | request.url = GURL("http://www.foo.com/"); |
| 1120 | request.load_flags = 0; |
| 1121 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1122 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1124 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1125 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1126 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1127 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1128 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1130 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1132 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1134 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1136 | |
| 1137 | rv = callback.WaitForResult(); |
| 1138 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1139 | } |
| 1140 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1141 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1142 | const MockWrite* write_failure, |
| 1143 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1144 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1145 | request.method = "GET"; |
| 1146 | request.url = GURL("http://www.foo.com/"); |
| 1147 | request.load_flags = 0; |
| 1148 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1149 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1150 | session_deps_.net_log = &net_log; |
| 1151 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1152 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1153 | // Written data for successfully sending both requests. |
| 1154 | MockWrite data1_writes[] = { |
| 1155 | MockWrite("GET / HTTP/1.1\r\n" |
| 1156 | "Host: www.foo.com\r\n" |
| 1157 | "Connection: keep-alive\r\n\r\n"), |
| 1158 | MockWrite("GET / HTTP/1.1\r\n" |
| 1159 | "Host: www.foo.com\r\n" |
| 1160 | "Connection: keep-alive\r\n\r\n") |
| 1161 | }; |
| 1162 | |
| 1163 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1165 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1166 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1167 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1169 | |
| 1170 | if (write_failure) { |
| 1171 | ASSERT_TRUE(!read_failure); |
| 1172 | data1_writes[1] = *write_failure; |
| 1173 | } else { |
| 1174 | ASSERT_TRUE(read_failure); |
| 1175 | data1_reads[2] = *read_failure; |
| 1176 | } |
| 1177 | |
| 1178 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1179 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1180 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1181 | |
| 1182 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1183 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1184 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1185 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1186 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1187 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1188 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | |
| 1190 | const char* kExpectedResponseData[] = { |
| 1191 | "hello", "world" |
| 1192 | }; |
| 1193 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1194 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1195 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1196 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1197 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1198 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1201 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1203 | |
| 1204 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1205 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1207 | LoadTimingInfo load_timing_info; |
| 1208 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1209 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1210 | if (i == 0) { |
| 1211 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1212 | } else { |
| 1213 | // The second request should be using a new socket. |
| 1214 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1215 | } |
| 1216 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1217 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1218 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1219 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1220 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1221 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1222 | |
| 1223 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1224 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1225 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1226 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1227 | } |
| 1228 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1229 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1230 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1231 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1232 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1233 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1234 | } |
| 1235 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1236 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1237 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1238 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1239 | } |
| 1240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1241 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1242 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1243 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1244 | } |
| 1245 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1246 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1247 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1248 | request.method = "GET"; |
| 1249 | request.url = GURL("http://www.google.com/"); |
| 1250 | request.load_flags = 0; |
| 1251 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1252 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1253 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1254 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1255 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1256 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1257 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1258 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1259 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1260 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1261 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1262 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1263 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1265 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1266 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1267 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1268 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1269 | |
| 1270 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1271 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1272 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1273 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1274 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | // What do various browsers do when the server closes a non-keepalive |
| 1278 | // connection without sending any response header or body? |
| 1279 | // |
| 1280 | // IE7: error page |
| 1281 | // Safari 3.1.2 (Windows): error page |
| 1282 | // Firefox 3.0.1: blank page |
| 1283 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1284 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1285 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1286 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1287 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1288 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1289 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1290 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1291 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1292 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1293 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1294 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1295 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1296 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1297 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1298 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1299 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1300 | // destructor in such situations. |
| 1301 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1302 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1303 | HttpRequestInfo request; |
| 1304 | request.method = "GET"; |
| 1305 | request.url = GURL("http://www.google.com/"); |
| 1306 | request.load_flags = 0; |
| 1307 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1308 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1309 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1310 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1311 | |
| 1312 | MockRead data_reads[] = { |
| 1313 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1314 | MockRead("Connection: keep-alive\r\n"), |
| 1315 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1316 | MockRead("hello"), |
| 1317 | MockRead(SYNCHRONOUS, 0), |
| 1318 | }; |
| 1319 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1321 | |
| 1322 | TestCompletionCallback callback; |
| 1323 | |
| 1324 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1325 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1326 | |
| 1327 | rv = callback.WaitForResult(); |
| 1328 | EXPECT_EQ(OK, rv); |
| 1329 | |
| 1330 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1331 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1332 | if (rv == ERR_IO_PENDING) |
| 1333 | rv = callback.WaitForResult(); |
| 1334 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1335 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1336 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1337 | |
| 1338 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1339 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1340 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1341 | } |
| 1342 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1343 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1344 | HttpRequestInfo request; |
| 1345 | request.method = "GET"; |
| 1346 | request.url = GURL("http://www.google.com/"); |
| 1347 | request.load_flags = 0; |
| 1348 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1349 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1350 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1351 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1352 | |
| 1353 | MockRead data_reads[] = { |
| 1354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1355 | MockRead("Connection: keep-alive\r\n"), |
| 1356 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1357 | MockRead(SYNCHRONOUS, 0), |
| 1358 | }; |
| 1359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1361 | |
| 1362 | TestCompletionCallback callback; |
| 1363 | |
| 1364 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1365 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1366 | |
| 1367 | rv = callback.WaitForResult(); |
| 1368 | EXPECT_EQ(OK, rv); |
| 1369 | |
| 1370 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1371 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1372 | if (rv == ERR_IO_PENDING) |
| 1373 | rv = callback.WaitForResult(); |
| 1374 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1375 | |
| 1376 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1377 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1378 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1379 | } |
| 1380 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1381 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1382 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1383 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1384 | HttpRequestInfo request; |
| 1385 | request.method = "GET"; |
| 1386 | request.url = GURL("http://www.foo.com/"); |
| 1387 | request.load_flags = 0; |
| 1388 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1389 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1390 | session_deps_.net_log = &net_log; |
| 1391 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1392 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1393 | // Note that because all these reads happen in the same |
| 1394 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1395 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1396 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1397 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1398 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1399 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1400 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1401 | "Content-Length: 0\r\n\r\n"), |
| 1402 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1403 | "Content-Length: 5\r\n\r\n" |
| 1404 | "hello"), |
| 1405 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1406 | "Content-Length: 0\r\n\r\n"), |
| 1407 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1408 | "Content-Length: 5\r\n\r\n" |
| 1409 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1410 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1411 | MockRead("hello"), |
| 1412 | }; |
| 1413 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1415 | |
| 1416 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1417 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1418 | }; |
| 1419 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1421 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1422 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1423 | std::string response_lines[kNumUnreadBodies]; |
| 1424 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1425 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1426 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1427 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1428 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1429 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1430 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1432 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1433 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1434 | |
| 1435 | rv = callback.WaitForResult(); |
| 1436 | EXPECT_EQ(OK, rv); |
| 1437 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1438 | LoadTimingInfo load_timing_info; |
| 1439 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1440 | if (i == 0) { |
| 1441 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1442 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1443 | } else { |
| 1444 | TestLoadTimingReused(load_timing_info); |
| 1445 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1446 | } |
| 1447 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1448 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1449 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1450 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1451 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1452 | response_lines[i] = response->headers->GetStatusLine(); |
| 1453 | |
| 1454 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1455 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1456 | |
| 1457 | const char* const kStatusLines[] = { |
| 1458 | "HTTP/1.1 204 No Content", |
| 1459 | "HTTP/1.1 205 Reset Content", |
| 1460 | "HTTP/1.1 304 Not Modified", |
| 1461 | "HTTP/1.1 302 Found", |
| 1462 | "HTTP/1.1 302 Found", |
| 1463 | "HTTP/1.1 301 Moved Permanently", |
| 1464 | "HTTP/1.1 301 Moved Permanently", |
| 1465 | }; |
| 1466 | |
| 1467 | COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines), |
| 1468 | forgot_to_update_kStatusLines); |
| 1469 | |
| 1470 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1471 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1473 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1474 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1476 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1477 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1478 | rv = callback.WaitForResult(); |
| 1479 | EXPECT_EQ(OK, rv); |
| 1480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1481 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1482 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1483 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1484 | std::string response_data; |
| 1485 | rv = ReadTransaction(trans.get(), &response_data); |
| 1486 | EXPECT_EQ(OK, rv); |
| 1487 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1488 | } |
| 1489 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1490 | // Test the request-challenge-retry sequence for basic auth. |
| 1491 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1492 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1493 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1494 | request.method = "GET"; |
| 1495 | request.url = GURL("http://www.google.com/"); |
| 1496 | request.load_flags = 0; |
| 1497 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1498 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1499 | session_deps_.net_log = &log; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1500 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1501 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1502 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1503 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1504 | MockWrite data_writes1[] = { |
| 1505 | MockWrite("GET / HTTP/1.1\r\n" |
| 1506 | "Host: www.google.com\r\n" |
| 1507 | "Connection: keep-alive\r\n\r\n"), |
| 1508 | }; |
| 1509 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1510 | MockRead data_reads1[] = { |
| 1511 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1512 | // Give a couple authenticate options (only the middle one is actually |
| 1513 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1514 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1515 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1516 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1517 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1518 | // Large content-length -- won't matter, as connection will be reset. |
| 1519 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1520 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1521 | }; |
| 1522 | |
| 1523 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1524 | // be issuing -- the final header line contains the credentials. |
| 1525 | MockWrite data_writes2[] = { |
| 1526 | MockWrite("GET / HTTP/1.1\r\n" |
| 1527 | "Host: www.google.com\r\n" |
| 1528 | "Connection: keep-alive\r\n" |
| 1529 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1530 | }; |
| 1531 | |
| 1532 | // Lastly, the server responds with the actual content. |
| 1533 | MockRead data_reads2[] = { |
| 1534 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1535 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1536 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1537 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1538 | }; |
| 1539 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1540 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1541 | data_writes1, arraysize(data_writes1)); |
| 1542 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1543 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1544 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1545 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1547 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1549 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1550 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1551 | |
| 1552 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1553 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1554 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1555 | LoadTimingInfo load_timing_info1; |
| 1556 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1557 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1558 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1559 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1560 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1561 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1563 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1565 | rv = trans->RestartWithAuth( |
| 1566 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1568 | |
| 1569 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1570 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1571 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1572 | LoadTimingInfo load_timing_info2; |
| 1573 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1574 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1575 | // The load timing after restart should have a new socket ID, and times after |
| 1576 | // those of the first load timing. |
| 1577 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1578 | load_timing_info2.connect_timing.connect_start); |
| 1579 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1580 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1581 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1582 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1583 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1584 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1585 | } |
| 1586 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1587 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1588 | HttpRequestInfo request; |
| 1589 | request.method = "GET"; |
| 1590 | request.url = GURL("http://www.google.com/"); |
| 1591 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1592 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1593 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1595 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1596 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1597 | MockWrite data_writes[] = { |
| 1598 | MockWrite("GET / HTTP/1.1\r\n" |
| 1599 | "Host: www.google.com\r\n" |
| 1600 | "Connection: keep-alive\r\n\r\n"), |
| 1601 | }; |
| 1602 | |
| 1603 | MockRead data_reads[] = { |
| 1604 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1605 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1606 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1607 | // Large content-length -- won't matter, as connection will be reset. |
| 1608 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1609 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1610 | }; |
| 1611 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1612 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 1613 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1614 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1615 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1616 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1617 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1619 | |
| 1620 | rv = callback.WaitForResult(); |
| 1621 | EXPECT_EQ(0, rv); |
| 1622 | |
| 1623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1624 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1625 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1626 | } |
| 1627 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1628 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1629 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1630 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1631 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1632 | request.method = "GET"; |
| 1633 | request.url = GURL("http://www.google.com/"); |
| 1634 | request.load_flags = 0; |
| 1635 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1636 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1637 | session_deps_.net_log = &log; |
| 1638 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1639 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1640 | MockWrite data_writes1[] = { |
| 1641 | MockWrite("GET / HTTP/1.1\r\n" |
| 1642 | "Host: www.google.com\r\n" |
| 1643 | "Connection: keep-alive\r\n\r\n"), |
| 1644 | |
| 1645 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1646 | // be issuing -- the final header line contains the credentials. |
| 1647 | MockWrite("GET / HTTP/1.1\r\n" |
| 1648 | "Host: www.google.com\r\n" |
| 1649 | "Connection: keep-alive\r\n" |
| 1650 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1651 | }; |
| 1652 | |
| 1653 | MockRead data_reads1[] = { |
| 1654 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1655 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1656 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1657 | MockRead("Content-Length: 14\r\n\r\n"), |
| 1658 | MockRead("Unauthorized\r\n"), |
| 1659 | |
| 1660 | // Lastly, the server responds with the actual content. |
| 1661 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1662 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1663 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1664 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1665 | }; |
| 1666 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1667 | // If there is a regression where we disconnect a Keep-Alive |
| 1668 | // connection during an auth roundtrip, we'll end up reading this. |
| 1669 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1670 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1671 | }; |
| 1672 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1673 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1674 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1675 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1676 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1677 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1678 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1680 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1681 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1682 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1683 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1684 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1686 | |
| 1687 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1688 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1689 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1690 | LoadTimingInfo load_timing_info1; |
| 1691 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1692 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1693 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1694 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1695 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1696 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1697 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1698 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1700 | rv = trans->RestartWithAuth( |
| 1701 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1703 | |
| 1704 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1705 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1706 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1707 | LoadTimingInfo load_timing_info2; |
| 1708 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1709 | TestLoadTimingReused(load_timing_info2); |
| 1710 | // The load timing after restart should have the same socket ID, and times |
| 1711 | // those of the first load timing. |
| 1712 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1713 | load_timing_info2.send_start); |
| 1714 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1715 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1716 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1717 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1718 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1719 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1723 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1724 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1725 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1726 | request.method = "GET"; |
| 1727 | request.url = GURL("http://www.google.com/"); |
| 1728 | request.load_flags = 0; |
| 1729 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1730 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1731 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1732 | MockWrite data_writes1[] = { |
| 1733 | MockWrite("GET / HTTP/1.1\r\n" |
| 1734 | "Host: www.google.com\r\n" |
| 1735 | "Connection: keep-alive\r\n\r\n"), |
| 1736 | |
| 1737 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1738 | // be issuing -- the final header line contains the credentials. |
| 1739 | MockWrite("GET / HTTP/1.1\r\n" |
| 1740 | "Host: www.google.com\r\n" |
| 1741 | "Connection: keep-alive\r\n" |
| 1742 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1743 | }; |
| 1744 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1745 | MockRead data_reads1[] = { |
| 1746 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1747 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1748 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1749 | |
| 1750 | // Lastly, the server responds with the actual content. |
| 1751 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1753 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1754 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1755 | }; |
| 1756 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1757 | // An incorrect reconnect would cause this to be read. |
| 1758 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1759 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1760 | }; |
| 1761 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1762 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1763 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1764 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1765 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1766 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1767 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1769 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1770 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1771 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1772 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1773 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1774 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1775 | |
| 1776 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1777 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1778 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1779 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1780 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1781 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1783 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1785 | rv = trans->RestartWithAuth( |
| 1786 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1787 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1788 | |
| 1789 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1790 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1791 | |
| 1792 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1793 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1794 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1795 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1799 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1800 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1801 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1802 | request.method = "GET"; |
| 1803 | request.url = GURL("http://www.google.com/"); |
| 1804 | request.load_flags = 0; |
| 1805 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1806 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1807 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1808 | MockWrite data_writes1[] = { |
| 1809 | MockWrite("GET / HTTP/1.1\r\n" |
| 1810 | "Host: www.google.com\r\n" |
| 1811 | "Connection: keep-alive\r\n\r\n"), |
| 1812 | |
| 1813 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1814 | // be issuing -- the final header line contains the credentials. |
| 1815 | MockWrite("GET / HTTP/1.1\r\n" |
| 1816 | "Host: www.google.com\r\n" |
| 1817 | "Connection: keep-alive\r\n" |
| 1818 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1819 | }; |
| 1820 | |
| 1821 | // Respond with 5 kb of response body. |
| 1822 | std::string large_body_string("Unauthorized"); |
| 1823 | large_body_string.append(5 * 1024, ' '); |
| 1824 | large_body_string.append("\r\n"); |
| 1825 | |
| 1826 | MockRead data_reads1[] = { |
| 1827 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1828 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1829 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1830 | // 5134 = 12 + 5 * 1024 + 2 |
| 1831 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1832 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1833 | |
| 1834 | // Lastly, the server responds with the actual content. |
| 1835 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1836 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1837 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1838 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1839 | }; |
| 1840 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1841 | // An incorrect reconnect would cause this to be read. |
| 1842 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1843 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1844 | }; |
| 1845 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1846 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1847 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1848 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1849 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1850 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1851 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1853 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1854 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1855 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1856 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1857 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1858 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1859 | |
| 1860 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1861 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1862 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1863 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1864 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1865 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1867 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1869 | rv = trans->RestartWithAuth( |
| 1870 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1871 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1872 | |
| 1873 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1874 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1875 | |
| 1876 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1877 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1878 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1879 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1883 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1884 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1885 | HttpRequestInfo request; |
| 1886 | request.method = "GET"; |
| 1887 | request.url = GURL("http://www.google.com/"); |
| 1888 | request.load_flags = 0; |
| 1889 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1890 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1891 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1892 | MockWrite data_writes1[] = { |
| 1893 | MockWrite("GET / HTTP/1.1\r\n" |
| 1894 | "Host: www.google.com\r\n" |
| 1895 | "Connection: keep-alive\r\n\r\n"), |
| 1896 | // This simulates the seemingly successful write to a closed connection |
| 1897 | // if the bug is not fixed. |
| 1898 | MockWrite("GET / HTTP/1.1\r\n" |
| 1899 | "Host: www.google.com\r\n" |
| 1900 | "Connection: keep-alive\r\n" |
| 1901 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1902 | }; |
| 1903 | |
| 1904 | MockRead data_reads1[] = { |
| 1905 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1906 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1908 | MockRead("Content-Length: 14\r\n\r\n"), |
| 1909 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1910 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1911 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1912 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1913 | }; |
| 1914 | |
| 1915 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1916 | // be issuing -- the final header line contains the credentials. |
| 1917 | MockWrite data_writes2[] = { |
| 1918 | MockWrite("GET / HTTP/1.1\r\n" |
| 1919 | "Host: www.google.com\r\n" |
| 1920 | "Connection: keep-alive\r\n" |
| 1921 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1922 | }; |
| 1923 | |
| 1924 | // Lastly, the server responds with the actual content. |
| 1925 | MockRead data_reads2[] = { |
| 1926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1928 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1929 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1930 | }; |
| 1931 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1932 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1933 | data_writes1, arraysize(data_writes1)); |
| 1934 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1935 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1936 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1937 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1939 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1940 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1941 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1942 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1943 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1944 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1945 | |
| 1946 | rv = callback1.WaitForResult(); |
| 1947 | EXPECT_EQ(OK, rv); |
| 1948 | |
| 1949 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1950 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1951 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1953 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1955 | rv = trans->RestartWithAuth( |
| 1956 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1958 | |
| 1959 | rv = callback2.WaitForResult(); |
| 1960 | EXPECT_EQ(OK, rv); |
| 1961 | |
| 1962 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1963 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1964 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1965 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1966 | } |
| 1967 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1968 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 1969 | // that requires a restart when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1970 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1971 | HttpRequestInfo request; |
| 1972 | request.method = "GET"; |
| 1973 | request.url = GURL("https://www.google.com/"); |
| 1974 | // when the no authentication data flag is set. |
| 1975 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1976 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1977 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1978 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 1979 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 1980 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1981 | session_deps_.net_log = log.bound().net_log(); |
| 1982 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1983 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1984 | // Since we have proxy, should try to establish tunnel. |
| 1985 | MockWrite data_writes1[] = { |
| 1986 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1987 | "Host: www.google.com\r\n" |
| 1988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 1989 | |
| 1990 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1991 | // be issuing -- the final header line contains the credentials. |
| 1992 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1993 | "Host: www.google.com\r\n" |
| 1994 | "Proxy-Connection: keep-alive\r\n" |
| 1995 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1996 | |
| 1997 | MockWrite("GET / HTTP/1.1\r\n" |
| 1998 | "Host: www.google.com\r\n" |
| 1999 | "Connection: keep-alive\r\n\r\n"), |
| 2000 | }; |
| 2001 | |
| 2002 | // The proxy responds to the connect with a 407, using a persistent |
| 2003 | // connection. |
| 2004 | MockRead data_reads1[] = { |
| 2005 | // No credentials. |
| 2006 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2007 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2008 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2009 | |
| 2010 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2011 | |
| 2012 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2013 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2014 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2015 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2016 | }; |
| 2017 | |
| 2018 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2019 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2020 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2021 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2024 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2025 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2026 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2027 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2029 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2030 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2031 | |
| 2032 | rv = callback1.WaitForResult(); |
| 2033 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2034 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2035 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2036 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2037 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2038 | NetLog::PHASE_NONE); |
| 2039 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2040 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2041 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2042 | NetLog::PHASE_NONE); |
| 2043 | |
| 2044 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2045 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2046 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2047 | EXPECT_EQ(407, response->headers->response_code()); |
| 2048 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2049 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2050 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2051 | LoadTimingInfo load_timing_info; |
| 2052 | // CONNECT requests and responses are handled at the connect job level, so |
| 2053 | // the transaction does not yet have a connection. |
| 2054 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2056 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2058 | rv = trans->RestartWithAuth( |
| 2059 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2061 | |
| 2062 | rv = callback2.WaitForResult(); |
| 2063 | EXPECT_EQ(OK, rv); |
| 2064 | |
| 2065 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2066 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2067 | |
| 2068 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2069 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2070 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2071 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2072 | |
| 2073 | // The password prompt info should not be set. |
| 2074 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2075 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2076 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2077 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2078 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2079 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2080 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2081 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2082 | } |
| 2083 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2084 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2085 | // proxy connection, when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2086 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2087 | HttpRequestInfo request; |
| 2088 | request.method = "GET"; |
| 2089 | request.url = GURL("https://www.google.com/"); |
| 2090 | // Ensure that proxy authentication is attempted even |
| 2091 | // when the no authentication data flag is set. |
| 2092 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2093 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2094 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2095 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2096 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2097 | session_deps_.net_log = log.bound().net_log(); |
| 2098 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2099 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2100 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2101 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2102 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2103 | // Since we have proxy, should try to establish tunnel. |
| 2104 | MockWrite data_writes1[] = { |
| 2105 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2106 | "Host: www.google.com\r\n" |
| 2107 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2108 | |
| 2109 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2110 | // be issuing -- the final header line contains the credentials. |
| 2111 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2112 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2113 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2114 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2115 | }; |
| 2116 | |
| 2117 | // The proxy responds to the connect with a 407, using a persistent |
| 2118 | // connection. |
| 2119 | MockRead data_reads1[] = { |
| 2120 | // No credentials. |
| 2121 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2122 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2123 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2124 | MockRead("0123456789"), |
| 2125 | |
| 2126 | // Wrong credentials (wrong password). |
| 2127 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2128 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2129 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2130 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2131 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2132 | }; |
| 2133 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2134 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2135 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2136 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2138 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2140 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2141 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2142 | |
| 2143 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2144 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2145 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2146 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2147 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2148 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2149 | NetLog::PHASE_NONE); |
| 2150 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2151 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2152 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2153 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2154 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2156 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2157 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2158 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2159 | EXPECT_EQ(407, response->headers->response_code()); |
| 2160 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2161 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2162 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2164 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2165 | |
| 2166 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2167 | rv = trans->RestartWithAuth( |
| 2168 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2169 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2170 | |
| 2171 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2172 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2173 | |
| 2174 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2175 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2176 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2177 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2178 | EXPECT_EQ(407, response->headers->response_code()); |
| 2179 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2180 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2181 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2182 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2183 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2184 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2185 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | } |
| 2187 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2188 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2189 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2190 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2191 | HttpRequestInfo request; |
| 2192 | request.method = "GET"; |
| 2193 | request.url = GURL("https://www.google.com/"); |
| 2194 | request.load_flags = 0; |
| 2195 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2196 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2197 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2198 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2199 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2200 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2201 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2203 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2204 | // Since we have proxy, should try to establish tunnel. |
| 2205 | MockWrite data_writes[] = { |
| 2206 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2207 | "Host: www.google.com\r\n" |
| 2208 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2209 | }; |
| 2210 | |
| 2211 | // The proxy responds to the connect with a 407. |
| 2212 | MockRead data_reads[] = { |
| 2213 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2214 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2215 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2216 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2217 | }; |
| 2218 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2219 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2220 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2221 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2223 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2225 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2226 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2227 | |
| 2228 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2229 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2230 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2231 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2232 | ASSERT_TRUE(response != NULL); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2233 | |
| 2234 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2235 | EXPECT_EQ(407, response->headers->response_code()); |
| 2236 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2237 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2238 | |
| 2239 | std::string response_data; |
| 2240 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2241 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2242 | |
| 2243 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2244 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2245 | } |
| 2246 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2247 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2248 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2249 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2250 | HttpRequestInfo request; |
| 2251 | request.method = "GET"; |
| 2252 | request.url = GURL("http://www.google.com/"); |
| 2253 | request.load_flags = 0; |
| 2254 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2255 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2256 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2258 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2259 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2260 | MockWrite data_writes1[] = { |
| 2261 | MockWrite("GET / HTTP/1.1\r\n" |
| 2262 | "Host: www.google.com\r\n" |
| 2263 | "Connection: keep-alive\r\n\r\n"), |
| 2264 | }; |
| 2265 | |
| 2266 | MockRead data_reads1[] = { |
| 2267 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2268 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2269 | // Large content-length -- won't matter, as connection will be reset. |
| 2270 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2271 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2272 | }; |
| 2273 | |
| 2274 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2275 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2276 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2278 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2280 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2281 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2282 | |
| 2283 | rv = callback.WaitForResult(); |
| 2284 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2285 | } |
| 2286 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2287 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2288 | // through a non-authenticating proxy. The request should fail with |
| 2289 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2290 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2291 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2292 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2293 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2294 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2295 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2296 | HttpRequestInfo request; |
| 2297 | request.method = "GET"; |
| 2298 | request.url = GURL("https://www.google.com/"); |
| 2299 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2300 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2301 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2302 | session_deps_.net_log = log.bound().net_log(); |
| 2303 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2304 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2305 | // Since we have proxy, should try to establish tunnel. |
| 2306 | MockWrite data_writes1[] = { |
| 2307 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2308 | "Host: www.google.com\r\n" |
| 2309 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2310 | |
| 2311 | MockWrite("GET / HTTP/1.1\r\n" |
| 2312 | "Host: www.google.com\r\n" |
| 2313 | "Connection: keep-alive\r\n\r\n"), |
| 2314 | }; |
| 2315 | |
| 2316 | MockRead data_reads1[] = { |
| 2317 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2318 | |
| 2319 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 2320 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2321 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2322 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2323 | }; |
| 2324 | |
| 2325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2326 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2328 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2329 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2331 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2332 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2333 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2334 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2336 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2337 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2338 | |
| 2339 | rv = callback1.WaitForResult(); |
| 2340 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2341 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2342 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2343 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2344 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2345 | NetLog::PHASE_NONE); |
| 2346 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2347 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2348 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2349 | NetLog::PHASE_NONE); |
| 2350 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2351 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2352 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2353 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2354 | HttpRequestInfo request1; |
| 2355 | request1.method = "GET"; |
| 2356 | request1.url = GURL("https://www.google.com/1"); |
| 2357 | |
| 2358 | HttpRequestInfo request2; |
| 2359 | request2.method = "GET"; |
| 2360 | request2.url = GURL("https://www.google.com/2"); |
| 2361 | |
| 2362 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2363 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2364 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 2365 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2366 | session_deps_.net_log = log.bound().net_log(); |
| 2367 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2368 | |
| 2369 | // Since we have proxy, should try to establish tunnel. |
| 2370 | MockWrite data_writes1[] = { |
| 2371 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2372 | "Host: www.google.com\r\n" |
| 2373 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2374 | |
| 2375 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2376 | "Host: www.google.com\r\n" |
| 2377 | "Connection: keep-alive\r\n\r\n"), |
| 2378 | |
| 2379 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2380 | "Host: www.google.com\r\n" |
| 2381 | "Connection: keep-alive\r\n\r\n"), |
| 2382 | }; |
| 2383 | |
| 2384 | // The proxy responds to the connect with a 407, using a persistent |
| 2385 | // connection. |
| 2386 | MockRead data_reads1[] = { |
| 2387 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2388 | |
| 2389 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2390 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2391 | MockRead(SYNCHRONOUS, "1"), |
| 2392 | |
| 2393 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2394 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2395 | MockRead(SYNCHRONOUS, "22"), |
| 2396 | }; |
| 2397 | |
| 2398 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2399 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2400 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2401 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2403 | |
| 2404 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2405 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2406 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2407 | |
| 2408 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2410 | |
| 2411 | rv = callback1.WaitForResult(); |
| 2412 | EXPECT_EQ(OK, rv); |
| 2413 | |
| 2414 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2415 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2416 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2417 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2418 | |
| 2419 | LoadTimingInfo load_timing_info1; |
| 2420 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2421 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2422 | |
| 2423 | trans1.reset(); |
| 2424 | |
| 2425 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2426 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2427 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2428 | |
| 2429 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2431 | |
| 2432 | rv = callback2.WaitForResult(); |
| 2433 | EXPECT_EQ(OK, rv); |
| 2434 | |
| 2435 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2436 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2437 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2438 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2439 | |
| 2440 | LoadTimingInfo load_timing_info2; |
| 2441 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2442 | TestLoadTimingReused(load_timing_info2); |
| 2443 | |
| 2444 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2445 | |
| 2446 | trans2.reset(); |
| 2447 | session->CloseAllConnections(); |
| 2448 | } |
| 2449 | |
| 2450 | // 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] | 2451 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2452 | HttpRequestInfo request1; |
| 2453 | request1.method = "GET"; |
| 2454 | request1.url = GURL("https://www.google.com/1"); |
| 2455 | |
| 2456 | HttpRequestInfo request2; |
| 2457 | request2.method = "GET"; |
| 2458 | request2.url = GURL("https://www.google.com/2"); |
| 2459 | |
| 2460 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2461 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2462 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2463 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2464 | session_deps_.net_log = log.bound().net_log(); |
| 2465 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2466 | |
| 2467 | // Since we have proxy, should try to establish tunnel. |
| 2468 | MockWrite data_writes1[] = { |
| 2469 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2470 | "Host: www.google.com\r\n" |
| 2471 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2472 | |
| 2473 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2474 | "Host: www.google.com\r\n" |
| 2475 | "Connection: keep-alive\r\n\r\n"), |
| 2476 | |
| 2477 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2478 | "Host: www.google.com\r\n" |
| 2479 | "Connection: keep-alive\r\n\r\n"), |
| 2480 | }; |
| 2481 | |
| 2482 | // The proxy responds to the connect with a 407, using a persistent |
| 2483 | // connection. |
| 2484 | MockRead data_reads1[] = { |
| 2485 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2486 | |
| 2487 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2488 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2489 | MockRead(SYNCHRONOUS, "1"), |
| 2490 | |
| 2491 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2492 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2493 | MockRead(SYNCHRONOUS, "22"), |
| 2494 | }; |
| 2495 | |
| 2496 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2497 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2498 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2499 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2501 | |
| 2502 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2503 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2504 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2505 | |
| 2506 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2507 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2508 | |
| 2509 | rv = callback1.WaitForResult(); |
| 2510 | EXPECT_EQ(OK, rv); |
| 2511 | |
| 2512 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2513 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2514 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2515 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2516 | |
| 2517 | LoadTimingInfo load_timing_info1; |
| 2518 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2519 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 2520 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2521 | |
| 2522 | trans1.reset(); |
| 2523 | |
| 2524 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2525 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2526 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2527 | |
| 2528 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2530 | |
| 2531 | rv = callback2.WaitForResult(); |
| 2532 | EXPECT_EQ(OK, rv); |
| 2533 | |
| 2534 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2535 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2536 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2537 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2538 | |
| 2539 | LoadTimingInfo load_timing_info2; |
| 2540 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2541 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 2542 | |
| 2543 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2544 | |
| 2545 | trans2.reset(); |
| 2546 | session->CloseAllConnections(); |
| 2547 | } |
| 2548 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2549 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2550 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2551 | HttpRequestInfo request; |
| 2552 | request.method = "GET"; |
| 2553 | request.url = GURL("http://www.google.com/"); |
| 2554 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2555 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2556 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2557 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2558 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2559 | session_deps_.net_log = log.bound().net_log(); |
| 2560 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2561 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2562 | // Since we have proxy, should use full url |
| 2563 | MockWrite data_writes1[] = { |
| 2564 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 2565 | "Host: www.google.com\r\n" |
| 2566 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2567 | }; |
| 2568 | |
| 2569 | MockRead data_reads1[] = { |
| 2570 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2571 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2572 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2573 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2574 | }; |
| 2575 | |
| 2576 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2577 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2578 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2579 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2582 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2583 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2584 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2585 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2587 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2588 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2589 | |
| 2590 | rv = callback1.WaitForResult(); |
| 2591 | EXPECT_EQ(OK, rv); |
| 2592 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2593 | LoadTimingInfo load_timing_info; |
| 2594 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2595 | TestLoadTimingNotReused(load_timing_info, |
| 2596 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2597 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2598 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2599 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2600 | |
| 2601 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2602 | EXPECT_EQ(200, response->headers->response_code()); |
| 2603 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2604 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2605 | |
| 2606 | // The password prompt info should not be set. |
| 2607 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2608 | } |
| 2609 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2610 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2611 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2612 | HttpRequestInfo request; |
| 2613 | request.method = "GET"; |
| 2614 | request.url = GURL("http://www.google.com/"); |
| 2615 | request.load_flags = 0; |
| 2616 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2617 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2618 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2619 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2620 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2621 | session_deps_.net_log = log.bound().net_log(); |
| 2622 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2623 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2624 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2625 | scoped_ptr<SpdyFrame> req( |
| 2626 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2627 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 2628 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2629 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2630 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2631 | MockRead spdy_reads[] = { |
| 2632 | CreateMockRead(*resp), |
| 2633 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2634 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2635 | }; |
| 2636 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2637 | DelayedSocketData spdy_data( |
| 2638 | 1, // wait for one write to finish before reading. |
| 2639 | spdy_reads, arraysize(spdy_reads), |
| 2640 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2641 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2642 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2643 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2644 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2645 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2647 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2648 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2649 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2650 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2652 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2653 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2654 | |
| 2655 | rv = callback1.WaitForResult(); |
| 2656 | EXPECT_EQ(OK, rv); |
| 2657 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2658 | LoadTimingInfo load_timing_info; |
| 2659 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2660 | TestLoadTimingNotReused(load_timing_info, |
| 2661 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2662 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2663 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2664 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2665 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2666 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2667 | |
| 2668 | std::string response_data; |
| 2669 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2670 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2671 | } |
| 2672 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2673 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2674 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2675 | HttpRequestInfo request; |
| 2676 | request.method = "GET"; |
| 2677 | request.url = GURL("http://www.google.com/"); |
| 2678 | request.load_flags = 0; |
| 2679 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2680 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2681 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2682 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2683 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2684 | session_deps_.net_log = log.bound().net_log(); |
| 2685 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2686 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2687 | // The first request will be a bare GET, the second request will be a |
| 2688 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2689 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2690 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2691 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2692 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2693 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2694 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2695 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 2696 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 2697 | false, |
| 2698 | 3, |
| 2699 | LOWEST, |
| 2700 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2701 | MockWrite spdy_writes[] = { |
| 2702 | CreateMockWrite(*req_get, 1), |
| 2703 | CreateMockWrite(*req_get_authorization, 4), |
| 2704 | }; |
| 2705 | |
| 2706 | // The first response is a 407 proxy authentication challenge, and the second |
| 2707 | // response will be a 200 response since the second request includes a valid |
| 2708 | // Authorization header. |
| 2709 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2710 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2711 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2712 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2713 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2714 | "407 Proxy Authentication Required", |
| 2715 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 2716 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2717 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2718 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2719 | scoped_ptr<SpdyFrame> resp_data( |
| 2720 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 2721 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2722 | MockRead spdy_reads[] = { |
| 2723 | CreateMockRead(*resp_authentication, 2), |
| 2724 | CreateMockRead(*body_authentication, 3), |
| 2725 | CreateMockRead(*resp_data, 5), |
| 2726 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2727 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2728 | }; |
| 2729 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2730 | OrderedSocketData data( |
| 2731 | spdy_reads, arraysize(spdy_reads), |
| 2732 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2734 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2735 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2736 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2739 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2740 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2741 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2742 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2744 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2746 | |
| 2747 | rv = callback1.WaitForResult(); |
| 2748 | EXPECT_EQ(OK, rv); |
| 2749 | |
| 2750 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 2751 | |
| 2752 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2753 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2754 | EXPECT_EQ(407, response->headers->response_code()); |
| 2755 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2756 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2758 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2760 | rv = trans->RestartWithAuth( |
| 2761 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2762 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2763 | |
| 2764 | rv = callback2.WaitForResult(); |
| 2765 | EXPECT_EQ(OK, rv); |
| 2766 | |
| 2767 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 2768 | |
| 2769 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2770 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2771 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 2772 | // The password prompt info should not be set. |
| 2773 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 2774 | } |
| 2775 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2776 | // 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] | 2777 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2778 | HttpRequestInfo request; |
| 2779 | request.method = "GET"; |
| 2780 | request.url = GURL("https://www.google.com/"); |
| 2781 | request.load_flags = 0; |
| 2782 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2783 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2784 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2785 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2786 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2787 | session_deps_.net_log = log.bound().net_log(); |
| 2788 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2789 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2790 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2792 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2793 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 2794 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2795 | // fetch https://www.google.com/ via HTTP |
| 2796 | |
| 2797 | const char get[] = "GET / HTTP/1.1\r\n" |
| 2798 | "Host: www.google.com\r\n" |
| 2799 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2800 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2801 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 2802 | scoped_ptr<SpdyFrame> conn_resp( |
| 2803 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2804 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 2805 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2806 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2807 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2808 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2809 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2810 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2811 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2812 | |
| 2813 | MockWrite spdy_writes[] = { |
| 2814 | CreateMockWrite(*connect, 1), |
| 2815 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2816 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2817 | }; |
| 2818 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2819 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2820 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 2821 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 2822 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 2823 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 2824 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2825 | }; |
| 2826 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2827 | OrderedSocketData spdy_data( |
| 2828 | spdy_reads, arraysize(spdy_reads), |
| 2829 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2830 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2831 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2832 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2833 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2834 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2835 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2836 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 2837 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2838 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2840 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2842 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2844 | |
| 2845 | rv = callback1.WaitForResult(); |
| 2846 | EXPECT_EQ(OK, rv); |
| 2847 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2848 | LoadTimingInfo load_timing_info; |
| 2849 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2850 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2851 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2852 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2853 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2854 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2855 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2856 | |
| 2857 | std::string response_data; |
| 2858 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 2859 | EXPECT_EQ("1234567890", response_data); |
| 2860 | } |
| 2861 | |
| 2862 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2863 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2864 | HttpRequestInfo request; |
| 2865 | request.method = "GET"; |
| 2866 | request.url = GURL("https://www.google.com/"); |
| 2867 | request.load_flags = 0; |
| 2868 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2869 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2870 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2871 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2872 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2873 | session_deps_.net_log = log.bound().net_log(); |
| 2874 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2875 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2876 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2878 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2879 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 2880 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2881 | // fetch https://www.google.com/ via SPDY |
| 2882 | const char* const kMyUrl = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2883 | scoped_ptr<SpdyFrame> get( |
| 2884 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2885 | scoped_ptr<SpdyFrame> wrapped_get( |
| 2886 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 2887 | scoped_ptr<SpdyFrame> conn_resp( |
| 2888 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2889 | scoped_ptr<SpdyFrame> get_resp( |
| 2890 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2891 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2892 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 2893 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2894 | scoped_ptr<SpdyFrame> wrapped_body( |
| 2895 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2896 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2897 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2898 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2899 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2900 | |
| 2901 | MockWrite spdy_writes[] = { |
| 2902 | CreateMockWrite(*connect, 1), |
| 2903 | CreateMockWrite(*wrapped_get, 3), |
| 2904 | CreateMockWrite(*window_update_get_resp, 5), |
| 2905 | CreateMockWrite(*window_update_body, 7), |
| 2906 | }; |
| 2907 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2908 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2909 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 2910 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 2911 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 2912 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2913 | }; |
| 2914 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2915 | OrderedSocketData spdy_data( |
| 2916 | spdy_reads, arraysize(spdy_reads), |
| 2917 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2918 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2919 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2920 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2921 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2922 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2923 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2924 | ssl2.SetNextProto(GetParam()); |
| 2925 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2926 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2928 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2930 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2931 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2932 | |
| 2933 | rv = callback1.WaitForResult(); |
| 2934 | EXPECT_EQ(OK, rv); |
| 2935 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2936 | LoadTimingInfo load_timing_info; |
| 2937 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2938 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2939 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2941 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2942 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2943 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2944 | |
| 2945 | std::string response_data; |
| 2946 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2947 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2951 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2952 | HttpRequestInfo request; |
| 2953 | request.method = "GET"; |
| 2954 | request.url = GURL("https://www.google.com/"); |
| 2955 | request.load_flags = 0; |
| 2956 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2957 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2958 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2959 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2960 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2961 | session_deps_.net_log = log.bound().net_log(); |
| 2962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2963 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2964 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2965 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2966 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2967 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 2968 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2969 | scoped_ptr<SpdyFrame> get( |
| 2970 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2971 | |
| 2972 | MockWrite spdy_writes[] = { |
| 2973 | CreateMockWrite(*connect, 1), |
| 2974 | CreateMockWrite(*get, 3), |
| 2975 | }; |
| 2976 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2977 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 2978 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2979 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2980 | CreateMockRead(*resp, 2, ASYNC), |
| 2981 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2982 | }; |
| 2983 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2984 | OrderedSocketData spdy_data( |
| 2985 | spdy_reads, arraysize(spdy_reads), |
| 2986 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2987 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2988 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2989 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2990 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2992 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2993 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2996 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2998 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2999 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3000 | |
| 3001 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3002 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3003 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3004 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3005 | } |
| 3006 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3007 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3008 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3009 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3010 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3011 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3012 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3013 | "https://proxy:70")); |
| 3014 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3015 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3016 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3017 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3018 | |
| 3019 | HttpRequestInfo request1; |
| 3020 | request1.method = "GET"; |
| 3021 | request1.url = GURL("https://www.google.com/"); |
| 3022 | request1.load_flags = 0; |
| 3023 | |
| 3024 | HttpRequestInfo request2; |
| 3025 | request2.method = "GET"; |
| 3026 | request2.url = GURL("https://news.google.com/"); |
| 3027 | request2.load_flags = 0; |
| 3028 | |
| 3029 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 3030 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3031 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3032 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3033 | |
| 3034 | // Fetch https://www.google.com/ via HTTP. |
| 3035 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3036 | "Host: www.google.com\r\n" |
| 3037 | "Connection: keep-alive\r\n\r\n"; |
| 3038 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3039 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3040 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3041 | "Content-Length: 1\r\n\r\n"; |
| 3042 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3043 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3044 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3045 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3046 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3047 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3048 | |
| 3049 | // CONNECT to news.google.com:443 via SPDY. |
| 3050 | const char* const kConnectHeaders2[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3051 | spdy_util_.GetMethodKey(), "CONNECT", |
| 3052 | spdy_util_.GetPathKey(), "news.google.com:443", |
| 3053 | spdy_util_.GetHostKey(), "news.google.com", |
| 3054 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3055 | }; |
| 3056 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3057 | spdy_util_.ConstructSpdyControlFrame(NULL, |
| 3058 | 0, |
| 3059 | /*compressed*/ false, |
| 3060 | 3, |
| 3061 | LOWEST, |
| 3062 | SYN_STREAM, |
| 3063 | CONTROL_FLAG_NONE, |
| 3064 | kConnectHeaders2, |
| 3065 | arraysize(kConnectHeaders2), |
| 3066 | 0)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3067 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3068 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3069 | |
| 3070 | // Fetch https://news.google.com/ via HTTP. |
| 3071 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3072 | "Host: news.google.com\r\n" |
| 3073 | "Connection: keep-alive\r\n\r\n"; |
| 3074 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3075 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3076 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3077 | "Content-Length: 2\r\n\r\n"; |
| 3078 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3079 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3080 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3081 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3082 | |
| 3083 | MockWrite spdy_writes[] = { |
| 3084 | CreateMockWrite(*connect1, 0), |
| 3085 | CreateMockWrite(*wrapped_get1, 2), |
| 3086 | CreateMockWrite(*connect2, 5), |
| 3087 | CreateMockWrite(*wrapped_get2, 7), |
| 3088 | }; |
| 3089 | |
| 3090 | MockRead spdy_reads[] = { |
| 3091 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3092 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3093 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3094 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3095 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3096 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3097 | MockRead(ASYNC, 0, 10), |
| 3098 | }; |
| 3099 | |
| 3100 | DeterministicSocketData spdy_data( |
| 3101 | spdy_reads, arraysize(spdy_reads), |
| 3102 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3103 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3104 | |
| 3105 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3106 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3107 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3108 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3109 | ssl2.was_npn_negotiated = false; |
| 3110 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3111 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3112 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3113 | ssl3.was_npn_negotiated = false; |
| 3114 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3115 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3116 | |
| 3117 | TestCompletionCallback callback; |
| 3118 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3119 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3121 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3123 | // The first connect and request, each of their responses, and the body. |
| 3124 | spdy_data.RunFor(5); |
| 3125 | |
| 3126 | rv = callback.WaitForResult(); |
| 3127 | EXPECT_EQ(OK, rv); |
| 3128 | |
| 3129 | LoadTimingInfo load_timing_info; |
| 3130 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3131 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3132 | |
| 3133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3134 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3135 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3136 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3137 | |
| 3138 | std::string response_data; |
| 3139 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3140 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3141 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3142 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3144 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3145 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3146 | |
| 3147 | // The second connect and request, each of their responses, and the body. |
| 3148 | spdy_data.RunFor(5); |
| 3149 | rv = callback.WaitForResult(); |
| 3150 | EXPECT_EQ(OK, rv); |
| 3151 | |
| 3152 | LoadTimingInfo load_timing_info2; |
| 3153 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3154 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3155 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3156 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3157 | |
| 3158 | // The requests should have different IDs, since they each are using their own |
| 3159 | // separate stream. |
| 3160 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3161 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3162 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3166 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3167 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3168 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3169 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3170 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3171 | "https://proxy:70")); |
| 3172 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3173 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3174 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3175 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3176 | |
| 3177 | HttpRequestInfo request1; |
| 3178 | request1.method = "GET"; |
| 3179 | request1.url = GURL("https://www.google.com/"); |
| 3180 | request1.load_flags = 0; |
| 3181 | |
| 3182 | HttpRequestInfo request2; |
| 3183 | request2.method = "GET"; |
| 3184 | request2.url = GURL("https://www.google.com/2"); |
| 3185 | request2.load_flags = 0; |
| 3186 | |
| 3187 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 3188 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3189 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3190 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3191 | |
| 3192 | // Fetch https://www.google.com/ via HTTP. |
| 3193 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3194 | "Host: www.google.com\r\n" |
| 3195 | "Connection: keep-alive\r\n\r\n"; |
| 3196 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3197 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3198 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3199 | "Content-Length: 1\r\n\r\n"; |
| 3200 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3201 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3202 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3203 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3204 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3205 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3206 | |
| 3207 | // Fetch https://www.google.com/2 via HTTP. |
| 3208 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3209 | "Host: www.google.com\r\n" |
| 3210 | "Connection: keep-alive\r\n\r\n"; |
| 3211 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3212 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3213 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3214 | "Content-Length: 2\r\n\r\n"; |
| 3215 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3216 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3217 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3218 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3219 | |
| 3220 | MockWrite spdy_writes[] = { |
| 3221 | CreateMockWrite(*connect1, 0), |
| 3222 | CreateMockWrite(*wrapped_get1, 2), |
| 3223 | CreateMockWrite(*wrapped_get2, 5), |
| 3224 | }; |
| 3225 | |
| 3226 | MockRead spdy_reads[] = { |
| 3227 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3228 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3229 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3230 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3231 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3232 | MockRead(ASYNC, 0, 8), |
| 3233 | }; |
| 3234 | |
| 3235 | DeterministicSocketData spdy_data( |
| 3236 | spdy_reads, arraysize(spdy_reads), |
| 3237 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3238 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3239 | |
| 3240 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3241 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3242 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3243 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3244 | ssl2.was_npn_negotiated = false; |
| 3245 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3246 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3247 | |
| 3248 | TestCompletionCallback callback; |
| 3249 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3250 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3252 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3254 | // The first connect and request, each of their responses, and the body. |
| 3255 | spdy_data.RunFor(5); |
| 3256 | |
| 3257 | rv = callback.WaitForResult(); |
| 3258 | EXPECT_EQ(OK, rv); |
| 3259 | |
| 3260 | LoadTimingInfo load_timing_info; |
| 3261 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3262 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3263 | |
| 3264 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3265 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3266 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3267 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3268 | |
| 3269 | std::string response_data; |
| 3270 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3271 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3272 | trans.reset(); |
| 3273 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3274 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3276 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3278 | |
| 3279 | // The second request, response, and body. There should not be a second |
| 3280 | // connect. |
| 3281 | spdy_data.RunFor(3); |
| 3282 | rv = callback.WaitForResult(); |
| 3283 | EXPECT_EQ(OK, rv); |
| 3284 | |
| 3285 | LoadTimingInfo load_timing_info2; |
| 3286 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3287 | TestLoadTimingReused(load_timing_info2); |
| 3288 | |
| 3289 | // The requests should have the same ID. |
| 3290 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3291 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3292 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 3296 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3297 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3298 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 3299 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3300 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3301 | "https://proxy:70")); |
| 3302 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3303 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3304 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3305 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3306 | |
| 3307 | HttpRequestInfo request1; |
| 3308 | request1.method = "GET"; |
| 3309 | request1.url = GURL("http://www.google.com/"); |
| 3310 | request1.load_flags = 0; |
| 3311 | |
| 3312 | HttpRequestInfo request2; |
| 3313 | request2.method = "GET"; |
| 3314 | request2.url = GURL("http://news.google.com/"); |
| 3315 | request2.load_flags = 0; |
| 3316 | |
| 3317 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3318 | scoped_ptr<SpdyHeaderBlock> headers( |
| 3319 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3320 | scoped_ptr<SpdyFrame> get1(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3321 | headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
| 3322 | scoped_ptr<SpdyFrame> get_resp1( |
| 3323 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3324 | scoped_ptr<SpdyFrame> body1( |
| 3325 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3326 | |
| 3327 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3328 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 3329 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3330 | scoped_ptr<SpdyFrame> get2(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3331 | headers2.Pass(), false, 3, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
| 3332 | scoped_ptr<SpdyFrame> get_resp2( |
| 3333 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3334 | scoped_ptr<SpdyFrame> body2( |
| 3335 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3336 | |
| 3337 | MockWrite spdy_writes[] = { |
| 3338 | CreateMockWrite(*get1, 0), |
| 3339 | CreateMockWrite(*get2, 3), |
| 3340 | }; |
| 3341 | |
| 3342 | MockRead spdy_reads[] = { |
| 3343 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 3344 | CreateMockRead(*body1, 2, ASYNC), |
| 3345 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 3346 | CreateMockRead(*body2, 5, ASYNC), |
| 3347 | MockRead(ASYNC, 0, 6), |
| 3348 | }; |
| 3349 | |
| 3350 | DeterministicSocketData spdy_data( |
| 3351 | spdy_reads, arraysize(spdy_reads), |
| 3352 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3353 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3354 | |
| 3355 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3356 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3357 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3358 | |
| 3359 | TestCompletionCallback callback; |
| 3360 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3361 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3362 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3363 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3364 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3365 | spdy_data.RunFor(2); |
| 3366 | |
| 3367 | rv = callback.WaitForResult(); |
| 3368 | EXPECT_EQ(OK, rv); |
| 3369 | |
| 3370 | LoadTimingInfo load_timing_info; |
| 3371 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3372 | TestLoadTimingNotReused(load_timing_info, |
| 3373 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3374 | |
| 3375 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3376 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3377 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3378 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3379 | |
| 3380 | std::string response_data; |
| 3381 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3382 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3383 | spdy_data.RunFor(1); |
| 3384 | EXPECT_EQ(1, callback.WaitForResult()); |
| 3385 | // Delete the first request, so the second one can reuse the socket. |
| 3386 | trans.reset(); |
| 3387 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3388 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3389 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3390 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3392 | |
| 3393 | spdy_data.RunFor(2); |
| 3394 | rv = callback.WaitForResult(); |
| 3395 | EXPECT_EQ(OK, rv); |
| 3396 | |
| 3397 | LoadTimingInfo load_timing_info2; |
| 3398 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3399 | TestLoadTimingReused(load_timing_info2); |
| 3400 | |
| 3401 | // The requests should have the same ID. |
| 3402 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3403 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3404 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3405 | spdy_data.RunFor(1); |
| 3406 | EXPECT_EQ(2, callback.WaitForResult()); |
| 3407 | } |
| 3408 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3409 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3410 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3411 | HttpRequestInfo request; |
| 3412 | request.method = "GET"; |
| 3413 | request.url = GURL("http://www.google.com/"); |
| 3414 | // when the no authentication data flag is set. |
| 3415 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3416 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3417 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3418 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3419 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3420 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3421 | session_deps_.net_log = log.bound().net_log(); |
| 3422 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3423 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3424 | // Since we have proxy, should use full url |
| 3425 | MockWrite data_writes1[] = { |
| 3426 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3427 | "Host: www.google.com\r\n" |
| 3428 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3429 | |
| 3430 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3431 | // be issuing -- the final header line contains the credentials. |
| 3432 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3433 | "Host: www.google.com\r\n" |
| 3434 | "Proxy-Connection: keep-alive\r\n" |
| 3435 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3436 | }; |
| 3437 | |
| 3438 | // The proxy responds to the GET with a 407, using a persistent |
| 3439 | // connection. |
| 3440 | MockRead data_reads1[] = { |
| 3441 | // No credentials. |
| 3442 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3443 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3444 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3445 | MockRead("Content-Length: 0\r\n\r\n"), |
| 3446 | |
| 3447 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3448 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3449 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3451 | }; |
| 3452 | |
| 3453 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3454 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3455 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3456 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3459 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3460 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3461 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3464 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3465 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3466 | |
| 3467 | rv = callback1.WaitForResult(); |
| 3468 | EXPECT_EQ(OK, rv); |
| 3469 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3470 | LoadTimingInfo load_timing_info; |
| 3471 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3472 | TestLoadTimingNotReused(load_timing_info, |
| 3473 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3474 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3475 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3476 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3477 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3478 | EXPECT_EQ(407, response->headers->response_code()); |
| 3479 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3480 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3482 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3484 | rv = trans->RestartWithAuth( |
| 3485 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3486 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3487 | |
| 3488 | rv = callback2.WaitForResult(); |
| 3489 | EXPECT_EQ(OK, rv); |
| 3490 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3491 | load_timing_info = LoadTimingInfo(); |
| 3492 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3493 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 3494 | TestLoadTimingReused(load_timing_info); |
| 3495 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3496 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3497 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3498 | |
| 3499 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3500 | EXPECT_EQ(200, response->headers->response_code()); |
| 3501 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3502 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3503 | |
| 3504 | // The password prompt info should not be set. |
| 3505 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3506 | } |
| 3507 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3508 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3509 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3510 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3511 | request.method = "GET"; |
| 3512 | request.url = GURL("https://www.google.com/"); |
| 3513 | request.load_flags = 0; |
| 3514 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3515 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3516 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3517 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3518 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3519 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3520 | // Since we have proxy, should try to establish tunnel. |
| 3521 | MockWrite data_writes[] = { |
| 3522 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 3523 | "Host: www.google.com\r\n" |
| 3524 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3525 | }; |
| 3526 | |
| 3527 | MockRead data_reads[] = { |
| 3528 | status, |
| 3529 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3530 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3531 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3532 | }; |
| 3533 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3534 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3535 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3536 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3537 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3538 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3539 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3540 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3541 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3543 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3544 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3545 | |
| 3546 | rv = callback.WaitForResult(); |
| 3547 | EXPECT_EQ(expected_status, rv); |
| 3548 | } |
| 3549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3550 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3551 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3552 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3553 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3554 | } |
| 3555 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3556 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3557 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 3558 | } |
| 3559 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3560 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3561 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 3562 | } |
| 3563 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3564 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3565 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 3566 | } |
| 3567 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3568 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3569 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 3570 | } |
| 3571 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3572 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3573 | ConnectStatusHelper( |
| 3574 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 3575 | } |
| 3576 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3577 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3578 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 3579 | } |
| 3580 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3581 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3582 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 3583 | } |
| 3584 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3585 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3586 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 3587 | } |
| 3588 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3589 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3590 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 3591 | } |
| 3592 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3593 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3594 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 3595 | } |
| 3596 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3597 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3598 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 3599 | } |
| 3600 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3601 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3602 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 3603 | } |
| 3604 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3605 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3606 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 3607 | } |
| 3608 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3609 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3610 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 3611 | } |
| 3612 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3613 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3614 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 3615 | } |
| 3616 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3617 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3618 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 3619 | } |
| 3620 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3621 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3622 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 3623 | } |
| 3624 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3625 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3626 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 3627 | } |
| 3628 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3629 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3630 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 3631 | } |
| 3632 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3633 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3634 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 3635 | } |
| 3636 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3637 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3638 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 3639 | } |
| 3640 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3641 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3642 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 3643 | } |
| 3644 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3645 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3646 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 3647 | } |
| 3648 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3649 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3650 | ConnectStatusHelperWithExpectedStatus( |
| 3651 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 3652 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3653 | } |
| 3654 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3655 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3656 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 3657 | } |
| 3658 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3659 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3660 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 3661 | } |
| 3662 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3663 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3664 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 3665 | } |
| 3666 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3667 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3668 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 3669 | } |
| 3670 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3671 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3672 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 3673 | } |
| 3674 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3675 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3676 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 3677 | } |
| 3678 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3679 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3680 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 3681 | } |
| 3682 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3683 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3684 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 3685 | } |
| 3686 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3687 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3688 | ConnectStatusHelper( |
| 3689 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 3690 | } |
| 3691 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3692 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3693 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 3694 | } |
| 3695 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3696 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3697 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 3698 | } |
| 3699 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3700 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3701 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 3702 | } |
| 3703 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3704 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3705 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 3706 | } |
| 3707 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3708 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3709 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 3710 | } |
| 3711 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3712 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3713 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 3714 | } |
| 3715 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3716 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3717 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 3718 | } |
| 3719 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3720 | // Test the flow when both the proxy server AND origin server require |
| 3721 | // authentication. Again, this uses basic auth for both since that is |
| 3722 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3723 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3724 | HttpRequestInfo request; |
| 3725 | request.method = "GET"; |
| 3726 | request.url = GURL("http://www.google.com/"); |
| 3727 | request.load_flags = 0; |
| 3728 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3729 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 3730 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3731 | // Configure against proxy server "myproxy:70". |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3732 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3733 | CreateSession(&session_deps_))); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3734 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 3735 | MockWrite data_writes1[] = { |
| 3736 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3737 | "Host: www.google.com\r\n" |
| 3738 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3739 | }; |
| 3740 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3741 | MockRead data_reads1[] = { |
| 3742 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 3743 | // Give a couple authenticate options (only the middle one is actually |
| 3744 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 3745 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3746 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3747 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 3748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3749 | // Large content-length -- won't matter, as connection will be reset. |
| 3750 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3751 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3752 | }; |
| 3753 | |
| 3754 | // After calling trans->RestartWithAuth() the first time, this is the |
| 3755 | // request we should be issuing -- the final header line contains the |
| 3756 | // proxy's credentials. |
| 3757 | MockWrite data_writes2[] = { |
| 3758 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3759 | "Host: www.google.com\r\n" |
| 3760 | "Proxy-Connection: keep-alive\r\n" |
| 3761 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3762 | }; |
| 3763 | |
| 3764 | // Now the proxy server lets the request pass through to origin server. |
| 3765 | // The origin server responds with a 401. |
| 3766 | MockRead data_reads2[] = { |
| 3767 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 3768 | // Note: We are using the same realm-name as the proxy server. This is |
| 3769 | // completely valid, as realms are unique across hosts. |
| 3770 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3771 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3772 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3773 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3774 | }; |
| 3775 | |
| 3776 | // After calling trans->RestartWithAuth() the second time, we should send |
| 3777 | // the credentials for both the proxy and origin server. |
| 3778 | MockWrite data_writes3[] = { |
| 3779 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3780 | "Host: www.google.com\r\n" |
| 3781 | "Proxy-Connection: keep-alive\r\n" |
| 3782 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 3783 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 3784 | }; |
| 3785 | |
| 3786 | // Lastly we get the desired content. |
| 3787 | MockRead data_reads3[] = { |
| 3788 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3789 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3790 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3792 | }; |
| 3793 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3794 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3795 | data_writes1, arraysize(data_writes1)); |
| 3796 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3797 | data_writes2, arraysize(data_writes2)); |
| 3798 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 3799 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3800 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3801 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3802 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3804 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3806 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3808 | |
| 3809 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3810 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3811 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3812 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3813 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3814 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3816 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3818 | rv = trans->RestartWithAuth( |
| 3819 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3821 | |
| 3822 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3823 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3824 | |
| 3825 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3826 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3827 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3829 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3831 | rv = trans->RestartWithAuth( |
| 3832 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3834 | |
| 3835 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3836 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3837 | |
| 3838 | response = trans->GetResponseInfo(); |
| 3839 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3840 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3841 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 3842 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 3843 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 3844 | // can't hook into its internals to cause it to generate predictable NTLM |
| 3845 | // authorization headers. |
| 3846 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3847 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 3848 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 3849 | // bytes in the debugger. |
| 3850 | |
| 3851 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3852 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3853 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3854 | request.method = "GET"; |
| 3855 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 3856 | request.load_flags = 0; |
| 3857 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3858 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 3859 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3860 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3861 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3862 | MockWrite data_writes1[] = { |
| 3863 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3864 | "Host: 172.22.68.17\r\n" |
| 3865 | "Connection: keep-alive\r\n\r\n"), |
| 3866 | }; |
| 3867 | |
| 3868 | MockRead data_reads1[] = { |
| 3869 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 3870 | // Negotiate and NTLM are often requested together. However, we only want |
| 3871 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 3872 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3873 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 3874 | MockRead("Connection: close\r\n"), |
| 3875 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 3876 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3877 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3878 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3879 | }; |
| 3880 | |
| 3881 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3882 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3883 | // request we should be issuing -- the final header line contains a Type |
| 3884 | // 1 message. |
| 3885 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3886 | "Host: 172.22.68.17\r\n" |
| 3887 | "Connection: keep-alive\r\n" |
| 3888 | "Authorization: NTLM " |
| 3889 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 3890 | |
| 3891 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 3892 | // (the credentials for the origin server). The second request continues |
| 3893 | // on the same connection. |
| 3894 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3895 | "Host: 172.22.68.17\r\n" |
| 3896 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3897 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 3898 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 3899 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 3900 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 3901 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3902 | }; |
| 3903 | |
| 3904 | MockRead data_reads2[] = { |
| 3905 | // The origin server responds with a Type 2 message. |
| 3906 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 3907 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3908 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3909 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 3910 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 3911 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 3912 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 3913 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 3914 | "BtAAAAAAA=\r\n"), |
| 3915 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 3916 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3917 | MockRead("You are not authorized to view this page\r\n"), |
| 3918 | |
| 3919 | // Lastly we get the desired content. |
| 3920 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3921 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 3922 | MockRead("Content-Length: 13\r\n\r\n"), |
| 3923 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3925 | }; |
| 3926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3927 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3928 | data_writes1, arraysize(data_writes1)); |
| 3929 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3930 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3932 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3934 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3935 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3936 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3937 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3939 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3941 | |
| 3942 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3943 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3944 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3945 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3946 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3947 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3948 | ASSERT_FALSE(response == NULL); |
| 3949 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3951 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3952 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 3953 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3954 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3956 | |
| 3957 | rv = callback2.WaitForResult(); |
| 3958 | EXPECT_EQ(OK, rv); |
| 3959 | |
| 3960 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3961 | |
| 3962 | response = trans->GetResponseInfo(); |
| 3963 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3964 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3966 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3968 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3970 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3971 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3972 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3973 | |
| 3974 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3975 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3976 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3977 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 3978 | } |
| 3979 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3980 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3981 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3982 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3983 | request.method = "GET"; |
| 3984 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 3985 | request.load_flags = 0; |
| 3986 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3987 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 3988 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3989 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3990 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3991 | MockWrite data_writes1[] = { |
| 3992 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3993 | "Host: 172.22.68.17\r\n" |
| 3994 | "Connection: keep-alive\r\n\r\n"), |
| 3995 | }; |
| 3996 | |
| 3997 | MockRead data_reads1[] = { |
| 3998 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 3999 | // Negotiate and NTLM are often requested together. However, we only want |
| 4000 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4001 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4002 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4003 | MockRead("Connection: close\r\n"), |
| 4004 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4005 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4006 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4007 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4008 | }; |
| 4009 | |
| 4010 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4011 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4012 | // request we should be issuing -- the final header line contains a Type |
| 4013 | // 1 message. |
| 4014 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4015 | "Host: 172.22.68.17\r\n" |
| 4016 | "Connection: keep-alive\r\n" |
| 4017 | "Authorization: NTLM " |
| 4018 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4019 | |
| 4020 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4021 | // (the credentials for the origin server). The second request continues |
| 4022 | // on the same connection. |
| 4023 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4024 | "Host: 172.22.68.17\r\n" |
| 4025 | "Connection: keep-alive\r\n" |
| 4026 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4027 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4028 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4029 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4030 | "4Ww7b7E=\r\n\r\n"), |
| 4031 | }; |
| 4032 | |
| 4033 | MockRead data_reads2[] = { |
| 4034 | // The origin server responds with a Type 2 message. |
| 4035 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4036 | MockRead("WWW-Authenticate: NTLM " |
| 4037 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4038 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4039 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4040 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4041 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4042 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4043 | "BtAAAAAAA=\r\n"), |
| 4044 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4045 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4046 | MockRead("You are not authorized to view this page\r\n"), |
| 4047 | |
| 4048 | // Wrong password. |
| 4049 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4050 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4051 | MockRead("Connection: close\r\n"), |
| 4052 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4053 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4054 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4055 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4056 | }; |
| 4057 | |
| 4058 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4059 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4060 | // request we should be issuing -- the final header line contains a Type |
| 4061 | // 1 message. |
| 4062 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4063 | "Host: 172.22.68.17\r\n" |
| 4064 | "Connection: keep-alive\r\n" |
| 4065 | "Authorization: NTLM " |
| 4066 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4067 | |
| 4068 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4069 | // (the credentials for the origin server). The second request continues |
| 4070 | // on the same connection. |
| 4071 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4072 | "Host: 172.22.68.17\r\n" |
| 4073 | "Connection: keep-alive\r\n" |
| 4074 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4075 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4076 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4077 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4078 | "+4MUm7c=\r\n\r\n"), |
| 4079 | }; |
| 4080 | |
| 4081 | MockRead data_reads3[] = { |
| 4082 | // The origin server responds with a Type 2 message. |
| 4083 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4084 | MockRead("WWW-Authenticate: NTLM " |
| 4085 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4086 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4087 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4088 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4089 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4090 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4091 | "BtAAAAAAA=\r\n"), |
| 4092 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4093 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4094 | MockRead("You are not authorized to view this page\r\n"), |
| 4095 | |
| 4096 | // Lastly we get the desired content. |
| 4097 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4098 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4099 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4100 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4101 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4102 | }; |
| 4103 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4104 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4105 | data_writes1, arraysize(data_writes1)); |
| 4106 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4107 | data_writes2, arraysize(data_writes2)); |
| 4108 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4109 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4110 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4111 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4112 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4114 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4115 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4116 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4117 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4119 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4121 | |
| 4122 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4123 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4124 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4125 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4126 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4128 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4129 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4131 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4132 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4133 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4134 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4135 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4137 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4138 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4139 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4140 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4141 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4142 | TestCompletionCallback callback3; |
| 4143 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4145 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4146 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4147 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4148 | |
| 4149 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4150 | ASSERT_FALSE(response == NULL); |
| 4151 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4153 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4154 | |
| 4155 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4156 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4157 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4159 | |
| 4160 | rv = callback4.WaitForResult(); |
| 4161 | EXPECT_EQ(OK, rv); |
| 4162 | |
| 4163 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4165 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4166 | |
| 4167 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4168 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4169 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4170 | |
| 4171 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4172 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4173 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4174 | response = trans->GetResponseInfo(); |
| 4175 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4176 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4177 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4178 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4179 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4180 | // Test reading a server response which has only headers, and no body. |
| 4181 | // After some maximum number of bytes is consumed, the transaction should |
| 4182 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4183 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4184 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4185 | request.method = "GET"; |
| 4186 | request.url = GURL("http://www.google.com/"); |
| 4187 | request.load_flags = 0; |
| 4188 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4189 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4191 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4192 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4193 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4194 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4195 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4196 | |
| 4197 | MockRead data_reads[] = { |
| 4198 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4199 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4200 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4201 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4202 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4203 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4206 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4208 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4209 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4210 | |
| 4211 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4212 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4213 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4214 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4215 | EXPECT_TRUE(response == NULL); |
| 4216 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4217 | |
| 4218 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4219 | // establish tunnel. |
| 4220 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4221 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4222 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4223 | HttpRequestInfo request; |
| 4224 | request.method = "GET"; |
| 4225 | request.url = GURL("https://www.google.com/"); |
| 4226 | request.load_flags = 0; |
| 4227 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4228 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4229 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 4230 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4231 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4232 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4233 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4234 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4235 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4236 | // Since we have proxy, should try to establish tunnel. |
| 4237 | MockWrite data_writes1[] = { |
| 4238 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4239 | "Host: www.google.com\r\n" |
| 4240 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4241 | }; |
| 4242 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 4243 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4244 | // connection. Usually a proxy would return 501 (not implemented), |
| 4245 | // or 200 (tunnel established). |
| 4246 | MockRead data_reads1[] = { |
| 4247 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 4248 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4249 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4250 | }; |
| 4251 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4252 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4253 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4254 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4256 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4258 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4259 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4260 | |
| 4261 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4262 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4263 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4264 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4265 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4266 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4267 | // Empty the current queue. This is necessary because idle sockets are |
| 4268 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4269 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4270 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4271 | // We now check to make sure the TCPClientSocket was not added back to |
| 4272 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4273 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4274 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4275 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4276 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4277 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4278 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4279 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4280 | // 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] | 4281 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4282 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4283 | request.method = "GET"; |
| 4284 | request.url = GURL("http://www.google.com/"); |
| 4285 | request.load_flags = 0; |
| 4286 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4287 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4288 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4289 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4291 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4292 | MockRead data_reads[] = { |
| 4293 | // A part of the response body is received with the response headers. |
| 4294 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 4295 | // The rest of the response body is received in two parts. |
| 4296 | MockRead("lo"), |
| 4297 | MockRead(" world"), |
| 4298 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4299 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4300 | }; |
| 4301 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4303 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4305 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4307 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4308 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4309 | |
| 4310 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4311 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4312 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4313 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4314 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4315 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4316 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4317 | std::string status_line = response->headers->GetStatusLine(); |
| 4318 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 4319 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4320 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4321 | |
| 4322 | std::string response_data; |
| 4323 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4324 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4325 | EXPECT_EQ("hello world", response_data); |
| 4326 | |
| 4327 | // Empty the current queue. This is necessary because idle sockets are |
| 4328 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4329 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4330 | |
| 4331 | // 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] | 4332 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4333 | } |
| 4334 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4335 | // Make sure that we recycle a SSL socket after reading all of the response |
| 4336 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4337 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4338 | HttpRequestInfo request; |
| 4339 | request.method = "GET"; |
| 4340 | request.url = GURL("https://www.google.com/"); |
| 4341 | request.load_flags = 0; |
| 4342 | |
| 4343 | MockWrite data_writes[] = { |
| 4344 | MockWrite("GET / HTTP/1.1\r\n" |
| 4345 | "Host: www.google.com\r\n" |
| 4346 | "Connection: keep-alive\r\n\r\n"), |
| 4347 | }; |
| 4348 | |
| 4349 | MockRead data_reads[] = { |
| 4350 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4351 | MockRead("Content-Length: 11\r\n\r\n"), |
| 4352 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4353 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4354 | }; |
| 4355 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4356 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4358 | |
| 4359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4360 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4363 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4364 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4365 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4366 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4367 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4369 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4370 | |
| 4371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4372 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4373 | |
| 4374 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4375 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4376 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4378 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4379 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4380 | |
| 4381 | std::string response_data; |
| 4382 | rv = ReadTransaction(trans.get(), &response_data); |
| 4383 | EXPECT_EQ(OK, rv); |
| 4384 | EXPECT_EQ("hello world", response_data); |
| 4385 | |
| 4386 | // Empty the current queue. This is necessary because idle sockets are |
| 4387 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4388 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4389 | |
| 4390 | // 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] | 4391 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 4395 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4396 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4397 | HttpRequestInfo request; |
| 4398 | request.method = "GET"; |
| 4399 | request.url = GURL("https://www.google.com/"); |
| 4400 | request.load_flags = 0; |
| 4401 | |
| 4402 | MockWrite data_writes[] = { |
| 4403 | MockWrite("GET / HTTP/1.1\r\n" |
| 4404 | "Host: www.google.com\r\n" |
| 4405 | "Connection: keep-alive\r\n\r\n"), |
| 4406 | MockWrite("GET / HTTP/1.1\r\n" |
| 4407 | "Host: www.google.com\r\n" |
| 4408 | "Connection: keep-alive\r\n\r\n"), |
| 4409 | }; |
| 4410 | |
| 4411 | MockRead data_reads[] = { |
| 4412 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4413 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4414 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4415 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4416 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4417 | }; |
| 4418 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4419 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4420 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4423 | |
| 4424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4425 | data_writes, arraysize(data_writes)); |
| 4426 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 4427 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4431 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4432 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4433 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4434 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4437 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4438 | |
| 4439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4440 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4441 | |
| 4442 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4443 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4444 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4445 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4446 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4447 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4448 | |
| 4449 | std::string response_data; |
| 4450 | rv = ReadTransaction(trans.get(), &response_data); |
| 4451 | EXPECT_EQ(OK, rv); |
| 4452 | EXPECT_EQ("hello world", response_data); |
| 4453 | |
| 4454 | // Empty the current queue. This is necessary because idle sockets are |
| 4455 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4456 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4457 | |
| 4458 | // 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] | 4459 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4460 | |
| 4461 | // Now start the second transaction, which should reuse the previous socket. |
| 4462 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4463 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4465 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4466 | |
| 4467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4468 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4469 | |
| 4470 | response = trans->GetResponseInfo(); |
| 4471 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4472 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4473 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4474 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4475 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4476 | |
| 4477 | rv = ReadTransaction(trans.get(), &response_data); |
| 4478 | EXPECT_EQ(OK, rv); |
| 4479 | EXPECT_EQ("hello world", response_data); |
| 4480 | |
| 4481 | // Empty the current queue. This is necessary because idle sockets are |
| 4482 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4483 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4484 | |
| 4485 | // 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] | 4486 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4487 | } |
| 4488 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4489 | // Make sure that we recycle a socket after a zero-length response. |
| 4490 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4491 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4492 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4493 | request.method = "GET"; |
| 4494 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 4495 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 4496 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 4497 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 4498 | request.load_flags = 0; |
| 4499 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4500 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4501 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4502 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4503 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4504 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4505 | MockRead data_reads[] = { |
| 4506 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 4507 | "Content-Length: 0\r\n" |
| 4508 | "Content-Type: text/html\r\n\r\n"), |
| 4509 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4510 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4511 | }; |
| 4512 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4513 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4514 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4516 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4518 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4519 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4520 | |
| 4521 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4522 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4523 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4525 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4526 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4527 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4528 | std::string status_line = response->headers->GetStatusLine(); |
| 4529 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 4530 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4531 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4532 | |
| 4533 | std::string response_data; |
| 4534 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4535 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4536 | EXPECT_EQ("", response_data); |
| 4537 | |
| 4538 | // Empty the current queue. This is necessary because idle sockets are |
| 4539 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4540 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4541 | |
| 4542 | // 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] | 4543 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4544 | } |
| 4545 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4546 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 4547 | ScopedVector<UploadElementReader> element_readers; |
| 4548 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 4549 | UploadDataStream upload_data_stream(&element_readers, 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 4550 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4551 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4552 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 4553 | // after use. |
| 4554 | request[0].method = "GET"; |
| 4555 | request[0].url = GURL("http://www.google.com/"); |
| 4556 | request[0].load_flags = 0; |
| 4557 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 4558 | // transaction 1. The first attempts fails when writing the POST data. |
| 4559 | // This causes the transaction to retry with a new socket. The second |
| 4560 | // attempt succeeds. |
| 4561 | request[1].method = "POST"; |
| 4562 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 4563 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4564 | request[1].load_flags = 0; |
| 4565 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4566 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4567 | |
| 4568 | // The first socket is used for transaction 1 and the first attempt of |
| 4569 | // transaction 2. |
| 4570 | |
| 4571 | // The response of transaction 1. |
| 4572 | MockRead data_reads1[] = { |
| 4573 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 4574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4575 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4576 | }; |
| 4577 | // The mock write results of transaction 1 and the first attempt of |
| 4578 | // transaction 2. |
| 4579 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4580 | MockWrite(SYNCHRONOUS, 64), // GET |
| 4581 | MockWrite(SYNCHRONOUS, 93), // POST |
| 4582 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4583 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4584 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4585 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4586 | |
| 4587 | // The second socket is used for the second attempt of transaction 2. |
| 4588 | |
| 4589 | // The response of transaction 2. |
| 4590 | MockRead data_reads2[] = { |
| 4591 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 4592 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4593 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4594 | }; |
| 4595 | // The mock write results of the second attempt of transaction 2. |
| 4596 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4597 | MockWrite(SYNCHRONOUS, 93), // POST |
| 4598 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4599 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4600 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4601 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4602 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4603 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4604 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4605 | |
| 4606 | const char* kExpectedResponseData[] = { |
| 4607 | "hello world", "welcome" |
| 4608 | }; |
| 4609 | |
| 4610 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4611 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4612 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4614 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4616 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4617 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4618 | |
| 4619 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4620 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4621 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4622 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4623 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4624 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4625 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4626 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4627 | |
| 4628 | std::string response_data; |
| 4629 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4630 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4631 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 4632 | } |
| 4633 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4634 | |
| 4635 | // Test the request-challenge-retry sequence for basic auth when there is |
| 4636 | // 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] | 4637 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4638 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4639 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4640 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4641 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 4642 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4643 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4644 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4645 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4646 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4647 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4648 | // The password contains an escaped character -- for this test to pass it |
| 4649 | // will need to be unescaped by HttpNetworkTransaction. |
| 4650 | EXPECT_EQ("b%40r", request.url.password()); |
| 4651 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4652 | MockWrite data_writes1[] = { |
| 4653 | MockWrite("GET / HTTP/1.1\r\n" |
| 4654 | "Host: www.google.com\r\n" |
| 4655 | "Connection: keep-alive\r\n\r\n"), |
| 4656 | }; |
| 4657 | |
| 4658 | MockRead data_reads1[] = { |
| 4659 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4660 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4661 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4662 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4663 | }; |
| 4664 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4665 | // After the challenge above, the transaction will be restarted using the |
| 4666 | // identity from the url (foo, b@r) to answer the challenge. |
| 4667 | MockWrite data_writes2[] = { |
| 4668 | MockWrite("GET / HTTP/1.1\r\n" |
| 4669 | "Host: www.google.com\r\n" |
| 4670 | "Connection: keep-alive\r\n" |
| 4671 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 4672 | }; |
| 4673 | |
| 4674 | MockRead data_reads2[] = { |
| 4675 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4676 | MockRead("Content-Length: 100\r\n\r\n"), |
| 4677 | MockRead(SYNCHRONOUS, OK), |
| 4678 | }; |
| 4679 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4680 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4681 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4682 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4683 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4685 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4687 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4688 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4689 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4690 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4691 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4692 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4693 | |
| 4694 | TestCompletionCallback callback2; |
| 4695 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 4696 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4697 | rv = callback2.WaitForResult(); |
| 4698 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4699 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4700 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4701 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4702 | ASSERT_TRUE(response != NULL); |
| 4703 | |
| 4704 | // There is no challenge info, since the identity in URL worked. |
| 4705 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4706 | |
| 4707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4708 | |
| 4709 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4710 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 4714 | // incorrect identity in the URL. The identity from the URL should be used only |
| 4715 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4716 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4717 | HttpRequestInfo request; |
| 4718 | request.method = "GET"; |
| 4719 | // Note: the URL has a username:password in it. The password "baz" is |
| 4720 | // wrong (should be "bar"). |
| 4721 | request.url = GURL("http://foo:[email protected]/"); |
| 4722 | |
| 4723 | request.load_flags = LOAD_NORMAL; |
| 4724 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4725 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4726 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4727 | CreateSession(&session_deps_))); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4728 | |
| 4729 | MockWrite data_writes1[] = { |
| 4730 | MockWrite("GET / HTTP/1.1\r\n" |
| 4731 | "Host: www.google.com\r\n" |
| 4732 | "Connection: keep-alive\r\n\r\n"), |
| 4733 | }; |
| 4734 | |
| 4735 | MockRead data_reads1[] = { |
| 4736 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4737 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4738 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4739 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 4740 | }; |
| 4741 | |
| 4742 | // After the challenge above, the transaction will be restarted using the |
| 4743 | // identity from the url (foo, baz) to answer the challenge. |
| 4744 | MockWrite data_writes2[] = { |
| 4745 | MockWrite("GET / HTTP/1.1\r\n" |
| 4746 | "Host: www.google.com\r\n" |
| 4747 | "Connection: keep-alive\r\n" |
| 4748 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 4749 | }; |
| 4750 | |
| 4751 | MockRead data_reads2[] = { |
| 4752 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4753 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4754 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4755 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 4756 | }; |
| 4757 | |
| 4758 | // After the challenge above, the transaction will be restarted using the |
| 4759 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 4760 | MockWrite data_writes3[] = { |
| 4761 | MockWrite("GET / HTTP/1.1\r\n" |
| 4762 | "Host: www.google.com\r\n" |
| 4763 | "Connection: keep-alive\r\n" |
| 4764 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4765 | }; |
| 4766 | |
| 4767 | MockRead data_reads3[] = { |
| 4768 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4769 | MockRead("Content-Length: 100\r\n\r\n"), |
| 4770 | MockRead(SYNCHRONOUS, OK), |
| 4771 | }; |
| 4772 | |
| 4773 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4774 | data_writes1, arraysize(data_writes1)); |
| 4775 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4776 | data_writes2, arraysize(data_writes2)); |
| 4777 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4778 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4779 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4780 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4781 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4782 | |
| 4783 | TestCompletionCallback callback1; |
| 4784 | |
| 4785 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 4786 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4787 | |
| 4788 | rv = callback1.WaitForResult(); |
| 4789 | EXPECT_EQ(OK, rv); |
| 4790 | |
| 4791 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4792 | TestCompletionCallback callback2; |
| 4793 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 4794 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4795 | rv = callback2.WaitForResult(); |
| 4796 | EXPECT_EQ(OK, rv); |
| 4797 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4798 | |
| 4799 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4800 | ASSERT_TRUE(response != NULL); |
| 4801 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 4802 | |
| 4803 | TestCompletionCallback callback3; |
| 4804 | rv = trans->RestartWithAuth( |
| 4805 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 4806 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4807 | rv = callback3.WaitForResult(); |
| 4808 | EXPECT_EQ(OK, rv); |
| 4809 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4810 | |
| 4811 | response = trans->GetResponseInfo(); |
| 4812 | ASSERT_TRUE(response != NULL); |
| 4813 | |
| 4814 | // There is no challenge info, since the identity worked. |
| 4815 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4816 | |
| 4817 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4818 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4819 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4820 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4821 | } |
| 4822 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4823 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4824 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4825 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4826 | |
| 4827 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 4828 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4829 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4830 | request.method = "GET"; |
| 4831 | request.url = GURL("http://www.google.com/x/y/z"); |
| 4832 | request.load_flags = 0; |
| 4833 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4834 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4835 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4836 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4837 | MockWrite data_writes1[] = { |
| 4838 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 4839 | "Host: www.google.com\r\n" |
| 4840 | "Connection: keep-alive\r\n\r\n"), |
| 4841 | }; |
| 4842 | |
| 4843 | MockRead data_reads1[] = { |
| 4844 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4845 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4846 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4847 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4848 | }; |
| 4849 | |
| 4850 | // Resend with authorization (username=foo, password=bar) |
| 4851 | MockWrite data_writes2[] = { |
| 4852 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 4853 | "Host: www.google.com\r\n" |
| 4854 | "Connection: keep-alive\r\n" |
| 4855 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4856 | }; |
| 4857 | |
| 4858 | // Sever accepts the authorization. |
| 4859 | MockRead data_reads2[] = { |
| 4860 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4861 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4862 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4863 | }; |
| 4864 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4865 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4866 | data_writes1, arraysize(data_writes1)); |
| 4867 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4868 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4870 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4872 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4874 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4876 | |
| 4877 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4878 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4879 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4881 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4882 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4884 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4886 | rv = trans->RestartWithAuth( |
| 4887 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4889 | |
| 4890 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4891 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4892 | |
| 4893 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4894 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4895 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4896 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4897 | } |
| 4898 | |
| 4899 | // ------------------------------------------------------------------------ |
| 4900 | |
| 4901 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 4902 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4903 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4904 | request.method = "GET"; |
| 4905 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 4906 | // protection space as MyRealm1. |
| 4907 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 4908 | request.load_flags = 0; |
| 4909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4910 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4912 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4913 | MockWrite data_writes1[] = { |
| 4914 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 4915 | "Host: www.google.com\r\n" |
| 4916 | "Connection: keep-alive\r\n" |
| 4917 | // Send preemptive authorization for MyRealm1 |
| 4918 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4919 | }; |
| 4920 | |
| 4921 | // The server didn't like the preemptive authorization, and |
| 4922 | // challenges us for a different realm (MyRealm2). |
| 4923 | MockRead data_reads1[] = { |
| 4924 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4925 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 4926 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4927 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4928 | }; |
| 4929 | |
| 4930 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 4931 | MockWrite data_writes2[] = { |
| 4932 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 4933 | "Host: www.google.com\r\n" |
| 4934 | "Connection: keep-alive\r\n" |
| 4935 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4936 | }; |
| 4937 | |
| 4938 | // Sever accepts the authorization. |
| 4939 | MockRead data_reads2[] = { |
| 4940 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4941 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4942 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4943 | }; |
| 4944 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4945 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4946 | data_writes1, arraysize(data_writes1)); |
| 4947 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4948 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4950 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4952 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4954 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4956 | |
| 4957 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4958 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4959 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4960 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4961 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4962 | ASSERT_TRUE(response->auth_challenge.get()); |
| 4963 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4964 | EXPECT_EQ("www.google.com:80", |
| 4965 | response->auth_challenge->challenger.ToString()); |
| 4966 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 4967 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4969 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4971 | rv = trans->RestartWithAuth( |
| 4972 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4973 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4974 | |
| 4975 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4976 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4977 | |
| 4978 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4979 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4980 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4981 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4982 | } |
| 4983 | |
| 4984 | // ------------------------------------------------------------------------ |
| 4985 | |
| 4986 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 4987 | // succeed with preemptive authorization. |
| 4988 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4989 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4990 | request.method = "GET"; |
| 4991 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 4992 | request.load_flags = 0; |
| 4993 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4996 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4997 | MockWrite data_writes1[] = { |
| 4998 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 4999 | "Host: www.google.com\r\n" |
| 5000 | "Connection: keep-alive\r\n" |
| 5001 | // The authorization for MyRealm1 gets sent preemptively |
| 5002 | // (since the url is in the same protection space) |
| 5003 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5004 | }; |
| 5005 | |
| 5006 | // Sever accepts the preemptive authorization |
| 5007 | MockRead data_reads1[] = { |
| 5008 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5009 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5010 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5011 | }; |
| 5012 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5013 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5014 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5015 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5017 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5019 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5020 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5021 | |
| 5022 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5023 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5024 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5025 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5026 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5027 | |
| 5028 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5029 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5030 | } |
| 5031 | |
| 5032 | // ------------------------------------------------------------------------ |
| 5033 | |
| 5034 | // Transaction 4: request another URL in MyRealm (however the |
| 5035 | // url is not known to belong to the protection space, so no pre-auth). |
| 5036 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5037 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5038 | request.method = "GET"; |
| 5039 | request.url = GURL("http://www.google.com/x/1"); |
| 5040 | request.load_flags = 0; |
| 5041 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5042 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5043 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5044 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5045 | MockWrite data_writes1[] = { |
| 5046 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5047 | "Host: www.google.com\r\n" |
| 5048 | "Connection: keep-alive\r\n\r\n"), |
| 5049 | }; |
| 5050 | |
| 5051 | MockRead data_reads1[] = { |
| 5052 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5053 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5054 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5055 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5056 | }; |
| 5057 | |
| 5058 | // Resend with authorization from MyRealm's cache. |
| 5059 | MockWrite data_writes2[] = { |
| 5060 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5061 | "Host: www.google.com\r\n" |
| 5062 | "Connection: keep-alive\r\n" |
| 5063 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5064 | }; |
| 5065 | |
| 5066 | // Sever accepts the authorization. |
| 5067 | MockRead data_reads2[] = { |
| 5068 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5069 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5070 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5071 | }; |
| 5072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5073 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5074 | data_writes1, arraysize(data_writes1)); |
| 5075 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5076 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5077 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5080 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5082 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5084 | |
| 5085 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5086 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5087 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5088 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5089 | TestCompletionCallback callback2; |
| 5090 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5092 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5093 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5094 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5095 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5097 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5098 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5099 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5100 | } |
| 5101 | |
| 5102 | // ------------------------------------------------------------------------ |
| 5103 | |
| 5104 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5105 | // cached identity. Should invalidate and re-prompt. |
| 5106 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5107 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5108 | request.method = "GET"; |
| 5109 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5110 | request.load_flags = 0; |
| 5111 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5112 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5114 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5115 | MockWrite data_writes1[] = { |
| 5116 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5117 | "Host: www.google.com\r\n" |
| 5118 | "Connection: keep-alive\r\n\r\n"), |
| 5119 | }; |
| 5120 | |
| 5121 | MockRead data_reads1[] = { |
| 5122 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5123 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5124 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5125 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5126 | }; |
| 5127 | |
| 5128 | // Resend with authorization from cache for MyRealm. |
| 5129 | MockWrite data_writes2[] = { |
| 5130 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5131 | "Host: www.google.com\r\n" |
| 5132 | "Connection: keep-alive\r\n" |
| 5133 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5134 | }; |
| 5135 | |
| 5136 | // Sever rejects the authorization. |
| 5137 | MockRead data_reads2[] = { |
| 5138 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5139 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5140 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5141 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5142 | }; |
| 5143 | |
| 5144 | // At this point we should prompt for new credentials for MyRealm. |
| 5145 | // Restart with username=foo3, password=foo4. |
| 5146 | MockWrite data_writes3[] = { |
| 5147 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5148 | "Host: www.google.com\r\n" |
| 5149 | "Connection: keep-alive\r\n" |
| 5150 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 5151 | }; |
| 5152 | |
| 5153 | // Sever accepts the authorization. |
| 5154 | MockRead data_reads3[] = { |
| 5155 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5156 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5157 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5158 | }; |
| 5159 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5160 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5161 | data_writes1, arraysize(data_writes1)); |
| 5162 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5163 | data_writes2, arraysize(data_writes2)); |
| 5164 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5165 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5167 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5168 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5170 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5172 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5174 | |
| 5175 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5176 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5177 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5178 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5179 | TestCompletionCallback callback2; |
| 5180 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5182 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5183 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5184 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5185 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5187 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5188 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5190 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5191 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5192 | rv = trans->RestartWithAuth( |
| 5193 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5195 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5196 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5197 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5198 | |
| 5199 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5200 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5201 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5202 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5203 | } |
| 5204 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5205 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5206 | // Tests that nonce count increments when multiple auth attempts |
| 5207 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5208 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 5209 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 5210 | new HttpAuthHandlerDigest::Factory(); |
| 5211 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 5212 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 5213 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5214 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 5215 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5216 | |
| 5217 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5218 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5219 | HttpRequestInfo request; |
| 5220 | request.method = "GET"; |
| 5221 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5222 | request.load_flags = 0; |
| 5223 | |
[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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5226 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5227 | MockWrite data_writes1[] = { |
| 5228 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5229 | "Host: www.google.com\r\n" |
| 5230 | "Connection: keep-alive\r\n\r\n"), |
| 5231 | }; |
| 5232 | |
| 5233 | MockRead data_reads1[] = { |
| 5234 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5235 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 5236 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5237 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5238 | }; |
| 5239 | |
| 5240 | // Resend with authorization (username=foo, password=bar) |
| 5241 | MockWrite data_writes2[] = { |
| 5242 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5243 | "Host: www.google.com\r\n" |
| 5244 | "Connection: keep-alive\r\n" |
| 5245 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5246 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 5247 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 5248 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5249 | }; |
| 5250 | |
| 5251 | // Sever accepts the authorization. |
| 5252 | MockRead data_reads2[] = { |
| 5253 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5254 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5255 | }; |
| 5256 | |
| 5257 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5258 | data_writes1, arraysize(data_writes1)); |
| 5259 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5260 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5262 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5264 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5266 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5268 | |
| 5269 | rv = callback1.WaitForResult(); |
| 5270 | EXPECT_EQ(OK, rv); |
| 5271 | |
| 5272 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5273 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5274 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5276 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5278 | rv = trans->RestartWithAuth( |
| 5279 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5281 | |
| 5282 | rv = callback2.WaitForResult(); |
| 5283 | EXPECT_EQ(OK, rv); |
| 5284 | |
| 5285 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5286 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5287 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5288 | } |
| 5289 | |
| 5290 | // ------------------------------------------------------------------------ |
| 5291 | |
| 5292 | // Transaction 2: Request another resource in digestive's protection space. |
| 5293 | // This will preemptively add an Authorization header which should have an |
| 5294 | // "nc" value of 2 (as compared to 1 in the first use. |
| 5295 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5296 | HttpRequestInfo request; |
| 5297 | request.method = "GET"; |
| 5298 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5299 | // protection space as digest. |
| 5300 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5301 | request.load_flags = 0; |
| 5302 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5303 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5304 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5305 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5306 | MockWrite data_writes1[] = { |
| 5307 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5308 | "Host: www.google.com\r\n" |
| 5309 | "Connection: keep-alive\r\n" |
| 5310 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5311 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 5312 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 5313 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5314 | }; |
| 5315 | |
| 5316 | // Sever accepts the authorization. |
| 5317 | MockRead data_reads1[] = { |
| 5318 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5319 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5320 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5321 | }; |
| 5322 | |
| 5323 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5324 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5327 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5329 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5330 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5331 | |
| 5332 | rv = callback1.WaitForResult(); |
| 5333 | EXPECT_EQ(OK, rv); |
| 5334 | |
| 5335 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5336 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5337 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5338 | } |
| 5339 | } |
| 5340 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5341 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5342 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5343 | // Create a transaction (the dependencies aren't important). |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5344 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5346 | CreateSession(&session_deps_))); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5347 | |
| 5348 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5349 | trans->read_buf_ = new IOBuffer(15); |
| 5350 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5351 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5352 | |
| 5353 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 5354 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5355 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5356 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5357 | response->response_time = base::Time::Now(); |
| 5358 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5359 | |
| 5360 | { // Setup state for response_.vary_data |
| 5361 | HttpRequestInfo request; |
| 5362 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 5363 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 5364 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 5365 | request.extra_headers.SetHeader("Foo", "1"); |
| 5366 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5367 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | // Cause the above state to be reset. |
| 5371 | trans->ResetStateForRestart(); |
| 5372 | |
| 5373 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 5374 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5375 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5376 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5377 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5378 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 5379 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5380 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5381 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5382 | } |
| 5383 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5384 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5385 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5386 | HttpRequestInfo request; |
| 5387 | request.method = "GET"; |
| 5388 | request.url = GURL("https://www.google.com/"); |
| 5389 | request.load_flags = 0; |
| 5390 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5391 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5392 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5393 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5394 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5395 | MockWrite data_writes[] = { |
| 5396 | MockWrite("GET / HTTP/1.1\r\n" |
| 5397 | "Host: www.google.com\r\n" |
| 5398 | "Connection: keep-alive\r\n\r\n"), |
| 5399 | }; |
| 5400 | |
| 5401 | MockRead data_reads[] = { |
| 5402 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5403 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5404 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5405 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5406 | }; |
| 5407 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 5408 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5409 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5410 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5411 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5412 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5413 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5414 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5419 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5421 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5423 | |
| 5424 | rv = callback.WaitForResult(); |
| 5425 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5427 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5428 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5429 | |
| 5430 | rv = callback.WaitForResult(); |
| 5431 | EXPECT_EQ(OK, rv); |
| 5432 | |
| 5433 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5434 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5435 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5436 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5437 | } |
| 5438 | |
| 5439 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 5440 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5441 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5442 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5443 | |
| 5444 | HttpRequestInfo request; |
| 5445 | request.method = "GET"; |
| 5446 | request.url = GURL("https://www.google.com/"); |
| 5447 | request.load_flags = 0; |
| 5448 | |
| 5449 | MockWrite proxy_writes[] = { |
| 5450 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5451 | "Host: www.google.com\r\n" |
| 5452 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5453 | }; |
| 5454 | |
| 5455 | MockRead proxy_reads[] = { |
| 5456 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5457 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5458 | }; |
| 5459 | |
| 5460 | MockWrite data_writes[] = { |
| 5461 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5462 | "Host: www.google.com\r\n" |
| 5463 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5464 | MockWrite("GET / HTTP/1.1\r\n" |
| 5465 | "Host: www.google.com\r\n" |
| 5466 | "Connection: keep-alive\r\n\r\n"), |
| 5467 | }; |
| 5468 | |
| 5469 | MockRead data_reads[] = { |
| 5470 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 5471 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5472 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5473 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5474 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5475 | }; |
| 5476 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5477 | StaticSocketDataProvider ssl_bad_certificate( |
| 5478 | proxy_reads, arraysize(proxy_reads), |
| 5479 | proxy_writes, arraysize(proxy_writes)); |
| 5480 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5481 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5482 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5483 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5484 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5485 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5490 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5491 | |
| 5492 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5493 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5494 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5495 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5496 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5497 | CreateSession(&session_deps_))); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5499 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5501 | |
| 5502 | rv = callback.WaitForResult(); |
| 5503 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5505 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5507 | |
| 5508 | rv = callback.WaitForResult(); |
| 5509 | EXPECT_EQ(OK, rv); |
| 5510 | |
| 5511 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5512 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5513 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5514 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5515 | } |
| 5516 | } |
| 5517 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5518 | |
| 5519 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5520 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5521 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5522 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 5523 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5524 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5525 | |
| 5526 | HttpRequestInfo request; |
| 5527 | request.method = "GET"; |
| 5528 | request.url = GURL("https://www.google.com/"); |
| 5529 | request.load_flags = 0; |
| 5530 | |
| 5531 | MockWrite data_writes[] = { |
| 5532 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5533 | "Host: www.google.com\r\n" |
| 5534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5535 | MockWrite("GET / HTTP/1.1\r\n" |
| 5536 | "Host: www.google.com\r\n" |
| 5537 | "Connection: keep-alive\r\n\r\n"), |
| 5538 | }; |
| 5539 | |
| 5540 | MockRead data_reads[] = { |
| 5541 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 5542 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5543 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5544 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5545 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5546 | }; |
| 5547 | |
| 5548 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5549 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5550 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 5551 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5552 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5553 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5554 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 5555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5557 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5558 | |
| 5559 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5560 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5561 | CreateSession(&session_deps_))); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5563 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5565 | |
| 5566 | rv = callback.WaitForResult(); |
| 5567 | EXPECT_EQ(OK, rv); |
| 5568 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5569 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5570 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5571 | |
| 5572 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5573 | EXPECT_EQ(200, response->headers->response_code()); |
| 5574 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5575 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5576 | |
| 5577 | LoadTimingInfo load_timing_info; |
| 5578 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5579 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5580 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5581 | } |
| 5582 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5583 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5584 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5585 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5586 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 5587 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5588 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5589 | |
| 5590 | HttpRequestInfo request; |
| 5591 | request.method = "GET"; |
| 5592 | request.url = GURL("https://www.google.com/"); |
| 5593 | request.load_flags = 0; |
| 5594 | |
| 5595 | MockWrite data_writes[] = { |
| 5596 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5597 | "Host: www.google.com\r\n" |
| 5598 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5599 | }; |
| 5600 | |
| 5601 | MockRead data_reads[] = { |
| 5602 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 5603 | MockRead("Location: http://login.example.com/\r\n"), |
| 5604 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5606 | }; |
| 5607 | |
| 5608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5609 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5610 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5611 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5612 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5615 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5616 | |
| 5617 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5618 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5619 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5621 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5622 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5623 | |
| 5624 | rv = callback.WaitForResult(); |
| 5625 | EXPECT_EQ(OK, rv); |
| 5626 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5627 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5628 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5629 | |
| 5630 | EXPECT_EQ(302, response->headers->response_code()); |
| 5631 | std::string url; |
| 5632 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 5633 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5634 | |
| 5635 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 5636 | // timing for the proxy connection instead of the connection to the host, |
| 5637 | // and no send / receive times. |
| 5638 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 5639 | LoadTimingInfo load_timing_info; |
| 5640 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5641 | |
| 5642 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 5643 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 5644 | |
| 5645 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 5646 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 5647 | load_timing_info.proxy_resolve_end); |
| 5648 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 5649 | load_timing_info.connect_timing.connect_start); |
| 5650 | ExpectConnectTimingHasTimes( |
| 5651 | load_timing_info.connect_timing, |
| 5652 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5653 | |
| 5654 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 5655 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 5656 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5660 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5661 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5662 | ProxyService::CreateFixed("https://proxy:70")); |
| 5663 | |
| 5664 | HttpRequestInfo request; |
| 5665 | request.method = "GET"; |
| 5666 | request.url = GURL("https://www.google.com/"); |
| 5667 | request.load_flags = 0; |
| 5668 | |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 5669 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5670 | scoped_ptr<SpdyFrame> goaway( |
| 5671 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5672 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5673 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 5674 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5675 | }; |
| 5676 | |
| 5677 | static const char* const kExtraHeaders[] = { |
| 5678 | "location", |
| 5679 | "http://login.example.com/", |
| 5680 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5681 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5682 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5683 | arraysize(kExtraHeaders)/2, 1)); |
| 5684 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5685 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 5686 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5687 | }; |
| 5688 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5689 | DelayedSocketData data( |
| 5690 | 1, // wait for one write to finish before reading. |
| 5691 | data_reads, arraysize(data_reads), |
| 5692 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5693 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5694 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5695 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5696 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5697 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5698 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5699 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5700 | |
| 5701 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5702 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5703 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5704 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5705 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5706 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5707 | |
| 5708 | rv = callback.WaitForResult(); |
| 5709 | EXPECT_EQ(OK, rv); |
| 5710 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5711 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5712 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5713 | |
| 5714 | EXPECT_EQ(302, response->headers->response_code()); |
| 5715 | std::string url; |
| 5716 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 5717 | EXPECT_EQ("http://login.example.com/", url); |
| 5718 | } |
| 5719 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5720 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5721 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5722 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5723 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5724 | ProxyService::CreateFixed("https://proxy:70")); |
| 5725 | |
| 5726 | HttpRequestInfo request; |
| 5727 | request.method = "GET"; |
| 5728 | request.url = GURL("https://www.google.com/"); |
| 5729 | request.load_flags = 0; |
| 5730 | |
| 5731 | MockWrite data_writes[] = { |
| 5732 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5733 | "Host: www.google.com\r\n" |
| 5734 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5735 | }; |
| 5736 | |
| 5737 | MockRead data_reads[] = { |
| 5738 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5739 | MockRead("Content-Length: 23\r\n\r\n"), |
| 5740 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5741 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5742 | }; |
| 5743 | |
| 5744 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5745 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5746 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5747 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5751 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5752 | |
| 5753 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5754 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5755 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5757 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5758 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5759 | |
| 5760 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5761 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5762 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5763 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5764 | } |
| 5765 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5766 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5767 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5768 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5769 | session_deps_.proxy_service.reset( |
| 5770 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5771 | |
| 5772 | HttpRequestInfo request; |
| 5773 | request.method = "GET"; |
| 5774 | request.url = GURL("https://www.google.com/"); |
| 5775 | request.load_flags = 0; |
| 5776 | |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 5777 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5778 | scoped_ptr<SpdyFrame> rst( |
| 5779 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5780 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5781 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5782 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5783 | }; |
| 5784 | |
| 5785 | static const char* const kExtraHeaders[] = { |
| 5786 | "location", |
| 5787 | "http://login.example.com/", |
| 5788 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5789 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5790 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5791 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5792 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5793 | spdy_util_.ConstructSpdyBodyFrame( |
| 5794 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5795 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5796 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 5797 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5798 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5799 | }; |
| 5800 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5801 | DelayedSocketData data( |
| 5802 | 1, // wait for one write to finish before reading. |
| 5803 | data_reads, arraysize(data_reads), |
| 5804 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5806 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5811 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5812 | |
| 5813 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5814 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5815 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5819 | |
| 5820 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5821 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5822 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5823 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5824 | } |
| 5825 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5826 | // Test the request-challenge-retry sequence for basic auth, through |
| 5827 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5828 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5829 | HttpRequestInfo request; |
| 5830 | request.method = "GET"; |
| 5831 | request.url = GURL("https://www.google.com/"); |
| 5832 | // when the no authentication data flag is set. |
| 5833 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 5834 | |
| 5835 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5836 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5837 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 5838 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5839 | session_deps_.net_log = log.bound().net_log(); |
| 5840 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5841 | |
| 5842 | // Since we have proxy, should try to establish tunnel. |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 5843 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5844 | scoped_ptr<SpdyFrame> rst( |
| 5845 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5846 | |
| 5847 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5848 | // be issuing -- the final header line contains the credentials. |
| 5849 | const char* const kAuthCredentials[] = { |
| 5850 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 5851 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 5852 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
| 5853 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5854 | // fetch https://www.google.com/ via HTTP |
| 5855 | const char get[] = "GET / HTTP/1.1\r\n" |
| 5856 | "Host: www.google.com\r\n" |
| 5857 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5858 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5859 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5860 | |
| 5861 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5862 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5863 | CreateMockWrite(*rst, 4, ASYNC), |
| 5864 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5865 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5866 | }; |
| 5867 | |
| 5868 | // The proxy responds to the connect with a 407, using a persistent |
| 5869 | // connection. |
| 5870 | const char* const kAuthChallenge[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5871 | spdy_util_.GetStatusKey(), "407 Proxy Authentication Required", |
| 5872 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5873 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 5874 | }; |
| 5875 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5876 | scoped_ptr<SpdyFrame> conn_auth_resp( |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5877 | spdy_util_.ConstructSpdyControlFrame(NULL, |
| 5878 | 0, |
| 5879 | false, |
| 5880 | 1, |
| 5881 | LOWEST, |
| 5882 | SYN_REPLY, |
| 5883 | CONTROL_FLAG_NONE, |
| 5884 | kAuthChallenge, |
| 5885 | arraysize(kAuthChallenge), |
| 5886 | 0)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5887 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5888 | scoped_ptr<SpdyFrame> conn_resp( |
| 5889 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5890 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5891 | "Content-Length: 5\r\n\r\n"; |
| 5892 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5893 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5894 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5895 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5896 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5897 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5898 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 5899 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 5900 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 5901 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 5902 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5903 | }; |
| 5904 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5905 | OrderedSocketData spdy_data( |
| 5906 | spdy_reads, arraysize(spdy_reads), |
| 5907 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5908 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5909 | // Negotiate SPDY to the proxy |
| 5910 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5911 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5913 | // Vanilla SSL to the server |
| 5914 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5916 | |
| 5917 | TestCompletionCallback callback1; |
| 5918 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5919 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5920 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5921 | |
| 5922 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 5923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5924 | |
| 5925 | rv = callback1.WaitForResult(); |
| 5926 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 5927 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5928 | log.GetEntries(&entries); |
| 5929 | size_t pos = ExpectLogContainsSomewhere( |
| 5930 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 5931 | NetLog::PHASE_NONE); |
| 5932 | ExpectLogContainsSomewhere( |
| 5933 | entries, pos, |
| 5934 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 5935 | NetLog::PHASE_NONE); |
| 5936 | |
| 5937 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5938 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5939 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5940 | EXPECT_EQ(407, response->headers->response_code()); |
| 5941 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5942 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 5943 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5944 | |
| 5945 | TestCompletionCallback callback2; |
| 5946 | |
| 5947 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 5948 | callback2.callback()); |
| 5949 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5950 | |
| 5951 | rv = callback2.WaitForResult(); |
| 5952 | EXPECT_EQ(OK, rv); |
| 5953 | |
| 5954 | response = trans->GetResponseInfo(); |
| 5955 | ASSERT_TRUE(response != NULL); |
| 5956 | |
| 5957 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5958 | EXPECT_EQ(200, response->headers->response_code()); |
| 5959 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 5960 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5961 | |
| 5962 | // The password prompt info should not be set. |
| 5963 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5964 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5965 | LoadTimingInfo load_timing_info; |
| 5966 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5967 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5968 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5969 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5970 | trans.reset(); |
| 5971 | session->CloseAllConnections(); |
| 5972 | } |
| 5973 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5974 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 5975 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5976 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5977 | HttpRequestInfo request; |
| 5978 | HttpRequestInfo push_request; |
| 5979 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5980 | request.method = "GET"; |
| 5981 | request.url = GURL("http://www.google.com/"); |
| 5982 | push_request.method = "GET"; |
| 5983 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 5984 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5985 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5986 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5987 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 5988 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5989 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5990 | |
| 5991 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5992 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5993 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5994 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5995 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5996 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5997 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5998 | |
| 5999 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6000 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6001 | }; |
| 6002 | |
| 6003 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6004 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6005 | |
| 6006 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6007 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6008 | |
| 6009 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6010 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6011 | 0, |
| 6012 | 2, |
| 6013 | 1, |
| 6014 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6015 | const char kPushedData[] = "pushed"; |
| 6016 | scoped_ptr<SpdyFrame> stream2_body( |
| 6017 | spdy_util_.ConstructSpdyBodyFrame( |
| 6018 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6019 | |
| 6020 | MockRead spdy_reads[] = { |
| 6021 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6022 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6023 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6024 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6025 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6026 | }; |
| 6027 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6028 | OrderedSocketData spdy_data( |
| 6029 | spdy_reads, arraysize(spdy_reads), |
| 6030 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6031 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6032 | // Negotiate SPDY to the proxy |
| 6033 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6034 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6036 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6037 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6038 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6039 | TestCompletionCallback callback; |
| 6040 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6042 | |
| 6043 | rv = callback.WaitForResult(); |
| 6044 | EXPECT_EQ(OK, rv); |
| 6045 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6046 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6047 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6049 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6050 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6051 | |
| 6052 | rv = callback.WaitForResult(); |
| 6053 | EXPECT_EQ(OK, rv); |
| 6054 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6055 | |
| 6056 | ASSERT_TRUE(response != NULL); |
| 6057 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6058 | |
| 6059 | EXPECT_EQ(200, response->headers->response_code()); |
| 6060 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6061 | |
| 6062 | std::string response_data; |
| 6063 | rv = ReadTransaction(trans.get(), &response_data); |
| 6064 | EXPECT_EQ(OK, rv); |
| 6065 | EXPECT_EQ("hello!", response_data); |
| 6066 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6067 | LoadTimingInfo load_timing_info; |
| 6068 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6069 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6070 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6071 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6072 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6073 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6074 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6075 | |
| 6076 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6077 | EXPECT_EQ(OK, rv); |
| 6078 | EXPECT_EQ("pushed", response_data); |
| 6079 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6080 | LoadTimingInfo push_load_timing_info; |
| 6081 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6082 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6083 | // The transactions should share a socket ID, despite being for different |
| 6084 | // origins. |
| 6085 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6086 | push_load_timing_info.socket_log_id); |
| 6087 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6088 | trans.reset(); |
| 6089 | push_trans.reset(); |
| 6090 | session->CloseAllConnections(); |
| 6091 | } |
| 6092 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6093 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6094 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6095 | HttpRequestInfo request; |
| 6096 | |
| 6097 | request.method = "GET"; |
| 6098 | request.url = GURL("http://www.google.com/"); |
| 6099 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6100 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6101 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6102 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6103 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6104 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6105 | |
| 6106 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6107 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6108 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6109 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6110 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6111 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6112 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6113 | |
| 6114 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6115 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6116 | |
| 6117 | MockWrite spdy_writes[] = { |
| 6118 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6119 | CreateMockWrite(*push_rst, 4), |
| 6120 | }; |
| 6121 | |
| 6122 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6123 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6124 | |
| 6125 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6126 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6127 | |
| 6128 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6129 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6130 | 0, |
| 6131 | 2, |
| 6132 | 1, |
| 6133 | "https://www.another-origin.com/foo.dat")); |
| 6134 | |
| 6135 | MockRead spdy_reads[] = { |
| 6136 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6137 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6138 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6139 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6140 | }; |
| 6141 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6142 | OrderedSocketData spdy_data( |
| 6143 | spdy_reads, arraysize(spdy_reads), |
| 6144 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6145 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6146 | // Negotiate SPDY to the proxy |
| 6147 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6148 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6150 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6151 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6153 | TestCompletionCallback callback; |
| 6154 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6155 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6156 | |
| 6157 | rv = callback.WaitForResult(); |
| 6158 | EXPECT_EQ(OK, rv); |
| 6159 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6160 | |
| 6161 | ASSERT_TRUE(response != NULL); |
| 6162 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6163 | |
| 6164 | EXPECT_EQ(200, response->headers->response_code()); |
| 6165 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6166 | |
| 6167 | std::string response_data; |
| 6168 | rv = ReadTransaction(trans.get(), &response_data); |
| 6169 | EXPECT_EQ(OK, rv); |
| 6170 | EXPECT_EQ("hello!", response_data); |
| 6171 | |
| 6172 | trans.reset(); |
| 6173 | session->CloseAllConnections(); |
| 6174 | } |
| 6175 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6176 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 6177 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6178 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6179 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 6180 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6181 | |
| 6182 | HttpRequestInfo request; |
| 6183 | request.method = "GET"; |
| 6184 | request.url = GURL("https://www.google.com/"); |
| 6185 | request.load_flags = 0; |
| 6186 | |
| 6187 | // Attempt to fetch the URL from a server with a bad cert |
| 6188 | MockWrite bad_cert_writes[] = { |
| 6189 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6190 | "Host: www.google.com\r\n" |
| 6191 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6192 | }; |
| 6193 | |
| 6194 | MockRead bad_cert_reads[] = { |
| 6195 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6196 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6197 | }; |
| 6198 | |
| 6199 | // Attempt to fetch the URL with a good cert |
| 6200 | MockWrite good_data_writes[] = { |
| 6201 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6202 | "Host: www.google.com\r\n" |
| 6203 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6204 | MockWrite("GET / HTTP/1.1\r\n" |
| 6205 | "Host: www.google.com\r\n" |
| 6206 | "Connection: keep-alive\r\n\r\n"), |
| 6207 | }; |
| 6208 | |
| 6209 | MockRead good_cert_reads[] = { |
| 6210 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6211 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6212 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6213 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6214 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6215 | }; |
| 6216 | |
| 6217 | StaticSocketDataProvider ssl_bad_certificate( |
| 6218 | bad_cert_reads, arraysize(bad_cert_reads), |
| 6219 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 6220 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 6221 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6222 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6223 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6224 | |
| 6225 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6227 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6228 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6229 | |
| 6230 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6232 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6235 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6236 | |
| 6237 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6239 | CreateSession(&session_deps_))); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6241 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6243 | |
| 6244 | rv = callback.WaitForResult(); |
| 6245 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6247 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6249 | |
| 6250 | rv = callback.WaitForResult(); |
| 6251 | EXPECT_EQ(OK, rv); |
| 6252 | |
| 6253 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6254 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6255 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6256 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6257 | } |
| 6258 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6259 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6260 | HttpRequestInfo request; |
| 6261 | request.method = "GET"; |
| 6262 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6263 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6264 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6265 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6266 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6267 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6268 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6269 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6270 | MockWrite data_writes[] = { |
| 6271 | MockWrite("GET / HTTP/1.1\r\n" |
| 6272 | "Host: www.google.com\r\n" |
| 6273 | "Connection: keep-alive\r\n" |
| 6274 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6275 | }; |
| 6276 | |
| 6277 | // Lastly, the server responds with the actual content. |
| 6278 | MockRead data_reads[] = { |
| 6279 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6281 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6282 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6283 | }; |
| 6284 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6286 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6289 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6293 | |
| 6294 | rv = callback.WaitForResult(); |
| 6295 | EXPECT_EQ(OK, rv); |
| 6296 | } |
| 6297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6298 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6299 | HttpRequestInfo request; |
| 6300 | request.method = "GET"; |
| 6301 | request.url = GURL("https://www.google.com/"); |
| 6302 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6303 | "Chromium Ultra Awesome X Edition"); |
| 6304 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6305 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6306 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6308 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6309 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6310 | MockWrite data_writes[] = { |
| 6311 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6312 | "Host: www.google.com\r\n" |
| 6313 | "Proxy-Connection: keep-alive\r\n" |
| 6314 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6315 | }; |
| 6316 | MockRead data_reads[] = { |
| 6317 | // Return an error, so the transaction stops here (this test isn't |
| 6318 | // interested in the rest). |
| 6319 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6320 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6321 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 6322 | }; |
| 6323 | |
| 6324 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6325 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6326 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6328 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6330 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6331 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6332 | |
| 6333 | rv = callback.WaitForResult(); |
| 6334 | EXPECT_EQ(OK, rv); |
| 6335 | } |
| 6336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6337 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6338 | HttpRequestInfo request; |
| 6339 | request.method = "GET"; |
| 6340 | request.url = GURL("http://www.google.com/"); |
| 6341 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6342 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 6343 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6344 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6345 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6346 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6347 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6348 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6349 | MockWrite data_writes[] = { |
| 6350 | MockWrite("GET / HTTP/1.1\r\n" |
| 6351 | "Host: www.google.com\r\n" |
| 6352 | "Connection: keep-alive\r\n" |
| 6353 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 6354 | }; |
| 6355 | |
| 6356 | // Lastly, the server responds with the actual content. |
| 6357 | MockRead data_reads[] = { |
| 6358 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6359 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6360 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6361 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6362 | }; |
| 6363 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6364 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6365 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6368 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6370 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6372 | |
| 6373 | rv = callback.WaitForResult(); |
| 6374 | EXPECT_EQ(OK, rv); |
| 6375 | } |
| 6376 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6377 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6378 | HttpRequestInfo request; |
| 6379 | request.method = "POST"; |
| 6380 | request.url = GURL("http://www.google.com/"); |
| 6381 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6382 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6384 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6385 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6386 | MockWrite data_writes[] = { |
| 6387 | MockWrite("POST / HTTP/1.1\r\n" |
| 6388 | "Host: www.google.com\r\n" |
| 6389 | "Connection: keep-alive\r\n" |
| 6390 | "Content-Length: 0\r\n\r\n"), |
| 6391 | }; |
| 6392 | |
| 6393 | // Lastly, the server responds with the actual content. |
| 6394 | MockRead data_reads[] = { |
| 6395 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6396 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6397 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6398 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6399 | }; |
| 6400 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6402 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6405 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6407 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6409 | |
| 6410 | rv = callback.WaitForResult(); |
| 6411 | EXPECT_EQ(OK, rv); |
| 6412 | } |
| 6413 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6414 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6415 | HttpRequestInfo request; |
| 6416 | request.method = "PUT"; |
| 6417 | request.url = GURL("http://www.google.com/"); |
| 6418 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6419 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6421 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6422 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6423 | MockWrite data_writes[] = { |
| 6424 | MockWrite("PUT / HTTP/1.1\r\n" |
| 6425 | "Host: www.google.com\r\n" |
| 6426 | "Connection: keep-alive\r\n" |
| 6427 | "Content-Length: 0\r\n\r\n"), |
| 6428 | }; |
| 6429 | |
| 6430 | // Lastly, the server responds with the actual content. |
| 6431 | MockRead data_reads[] = { |
| 6432 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6433 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6434 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6435 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6436 | }; |
| 6437 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6438 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6439 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6442 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6446 | |
| 6447 | rv = callback.WaitForResult(); |
| 6448 | EXPECT_EQ(OK, rv); |
| 6449 | } |
| 6450 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6451 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6452 | HttpRequestInfo request; |
| 6453 | request.method = "HEAD"; |
| 6454 | request.url = GURL("http://www.google.com/"); |
| 6455 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6456 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6457 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6458 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6459 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6460 | MockWrite data_writes[] = { |
| 6461 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 6462 | "Host: www.google.com\r\n" |
| 6463 | "Connection: keep-alive\r\n" |
| 6464 | "Content-Length: 0\r\n\r\n"), |
| 6465 | }; |
| 6466 | |
| 6467 | // Lastly, the server responds with the actual content. |
| 6468 | MockRead data_reads[] = { |
| 6469 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6470 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6471 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6472 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6473 | }; |
| 6474 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6475 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6476 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6477 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6479 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6481 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6482 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6483 | |
| 6484 | rv = callback.WaitForResult(); |
| 6485 | EXPECT_EQ(OK, rv); |
| 6486 | } |
| 6487 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6488 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6489 | HttpRequestInfo request; |
| 6490 | request.method = "GET"; |
| 6491 | request.url = GURL("http://www.google.com/"); |
| 6492 | request.load_flags = LOAD_BYPASS_CACHE; |
| 6493 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6494 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6495 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6496 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6497 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6498 | MockWrite data_writes[] = { |
| 6499 | MockWrite("GET / HTTP/1.1\r\n" |
| 6500 | "Host: www.google.com\r\n" |
| 6501 | "Connection: keep-alive\r\n" |
| 6502 | "Pragma: no-cache\r\n" |
| 6503 | "Cache-Control: no-cache\r\n\r\n"), |
| 6504 | }; |
| 6505 | |
| 6506 | // Lastly, the server responds with the actual content. |
| 6507 | MockRead data_reads[] = { |
| 6508 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6509 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6510 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6511 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6512 | }; |
| 6513 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6514 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6515 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6516 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6518 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6520 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6521 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6522 | |
| 6523 | rv = callback.WaitForResult(); |
| 6524 | EXPECT_EQ(OK, rv); |
| 6525 | } |
| 6526 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6527 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6528 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6529 | HttpRequestInfo request; |
| 6530 | request.method = "GET"; |
| 6531 | request.url = GURL("http://www.google.com/"); |
| 6532 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 6533 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6534 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6536 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6537 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6538 | MockWrite data_writes[] = { |
| 6539 | MockWrite("GET / HTTP/1.1\r\n" |
| 6540 | "Host: www.google.com\r\n" |
| 6541 | "Connection: keep-alive\r\n" |
| 6542 | "Cache-Control: max-age=0\r\n\r\n"), |
| 6543 | }; |
| 6544 | |
| 6545 | // Lastly, the server responds with the actual content. |
| 6546 | MockRead data_reads[] = { |
| 6547 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6548 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6549 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6550 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6551 | }; |
| 6552 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6553 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6554 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6557 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6559 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6560 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6561 | |
| 6562 | rv = callback.WaitForResult(); |
| 6563 | EXPECT_EQ(OK, rv); |
| 6564 | } |
| 6565 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6566 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6567 | HttpRequestInfo request; |
| 6568 | request.method = "GET"; |
| 6569 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6570 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6571 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6572 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6573 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6574 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6575 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6576 | MockWrite data_writes[] = { |
| 6577 | MockWrite("GET / HTTP/1.1\r\n" |
| 6578 | "Host: www.google.com\r\n" |
| 6579 | "Connection: keep-alive\r\n" |
| 6580 | "FooHeader: Bar\r\n\r\n"), |
| 6581 | }; |
| 6582 | |
| 6583 | // Lastly, the server responds with the actual content. |
| 6584 | MockRead data_reads[] = { |
| 6585 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6586 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6587 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6588 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6589 | }; |
| 6590 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6591 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6592 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6595 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6597 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6599 | |
| 6600 | rv = callback.WaitForResult(); |
| 6601 | EXPECT_EQ(OK, rv); |
| 6602 | } |
| 6603 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6604 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6605 | HttpRequestInfo request; |
| 6606 | request.method = "GET"; |
| 6607 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6608 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 6609 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 6610 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6611 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6612 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6613 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6614 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6615 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6616 | MockWrite data_writes[] = { |
| 6617 | MockWrite("GET / HTTP/1.1\r\n" |
| 6618 | "Host: www.google.com\r\n" |
| 6619 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6620 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6621 | "hEllo: Kitty\r\n" |
| 6622 | "FoO: bar\r\n\r\n"), |
| 6623 | }; |
| 6624 | |
| 6625 | // Lastly, the server responds with the actual content. |
| 6626 | MockRead data_reads[] = { |
| 6627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6629 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6630 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6631 | }; |
| 6632 | |
| 6633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6634 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6637 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6639 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6641 | |
| 6642 | rv = callback.WaitForResult(); |
| 6643 | EXPECT_EQ(OK, rv); |
| 6644 | } |
| 6645 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6646 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6647 | HttpRequestInfo request; |
| 6648 | request.method = "GET"; |
| 6649 | request.url = GURL("http://www.google.com/"); |
| 6650 | request.load_flags = 0; |
| 6651 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6652 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6653 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 6654 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6655 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6656 | |
| 6657 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6659 | CreateSession(&session_deps_))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6660 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6661 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 6662 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6663 | |
| 6664 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6665 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6666 | MockWrite("GET / HTTP/1.1\r\n" |
| 6667 | "Host: www.google.com\r\n" |
| 6668 | "Connection: keep-alive\r\n\r\n") |
| 6669 | }; |
| 6670 | |
| 6671 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6672 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6673 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6674 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6675 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6676 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6677 | }; |
| 6678 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6680 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6683 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6685 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6687 | |
| 6688 | rv = callback.WaitForResult(); |
| 6689 | EXPECT_EQ(OK, rv); |
| 6690 | |
| 6691 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6692 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6693 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6694 | LoadTimingInfo load_timing_info; |
| 6695 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6696 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6697 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6698 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6699 | std::string response_text; |
| 6700 | rv = ReadTransaction(trans.get(), &response_text); |
| 6701 | EXPECT_EQ(OK, rv); |
| 6702 | EXPECT_EQ("Payload", response_text); |
| 6703 | } |
| 6704 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6705 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6706 | HttpRequestInfo request; |
| 6707 | request.method = "GET"; |
| 6708 | request.url = GURL("https://www.google.com/"); |
| 6709 | request.load_flags = 0; |
| 6710 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6711 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6712 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 6713 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6714 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6715 | |
| 6716 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6718 | CreateSession(&session_deps_))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6719 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6720 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 6721 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6722 | |
| 6723 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6724 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6725 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6726 | MockWrite("GET / HTTP/1.1\r\n" |
| 6727 | "Host: www.google.com\r\n" |
| 6728 | "Connection: keep-alive\r\n\r\n") |
| 6729 | }; |
| 6730 | |
| 6731 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6732 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 6733 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6734 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6735 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6736 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6737 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6738 | }; |
| 6739 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6740 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6741 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6743 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6744 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6745 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6747 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6749 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6750 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6751 | |
| 6752 | rv = callback.WaitForResult(); |
| 6753 | EXPECT_EQ(OK, rv); |
| 6754 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6755 | LoadTimingInfo load_timing_info; |
| 6756 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6757 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6758 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6759 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6760 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6761 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6762 | |
| 6763 | std::string response_text; |
| 6764 | rv = ReadTransaction(trans.get(), &response_text); |
| 6765 | EXPECT_EQ(OK, rv); |
| 6766 | EXPECT_EQ("Payload", response_text); |
| 6767 | } |
| 6768 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6769 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6770 | HttpRequestInfo request; |
| 6771 | request.method = "GET"; |
| 6772 | request.url = GURL("http://www.google.com/"); |
| 6773 | request.load_flags = 0; |
| 6774 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6775 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6776 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 6777 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6778 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6779 | |
| 6780 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6782 | CreateSession(&session_deps_))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6783 | |
| 6784 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 6785 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6786 | |
| 6787 | MockWrite data_writes[] = { |
| 6788 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 6789 | MockWrite("GET / HTTP/1.1\r\n" |
| 6790 | "Host: www.google.com\r\n" |
| 6791 | "Connection: keep-alive\r\n\r\n") |
| 6792 | }; |
| 6793 | |
| 6794 | MockRead data_reads[] = { |
| 6795 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 6796 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6797 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6798 | MockRead("Payload"), |
| 6799 | MockRead(SYNCHRONOUS, OK) |
| 6800 | }; |
| 6801 | |
| 6802 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6803 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6805 | |
| 6806 | TestCompletionCallback callback; |
| 6807 | |
| 6808 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6810 | |
| 6811 | rv = callback.WaitForResult(); |
| 6812 | EXPECT_EQ(OK, rv); |
| 6813 | |
| 6814 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6815 | ASSERT_TRUE(response != NULL); |
| 6816 | |
| 6817 | LoadTimingInfo load_timing_info; |
| 6818 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6819 | TestLoadTimingNotReused(load_timing_info, |
| 6820 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6821 | |
| 6822 | std::string response_text; |
| 6823 | rv = ReadTransaction(trans.get(), &response_text); |
| 6824 | EXPECT_EQ(OK, rv); |
| 6825 | EXPECT_EQ("Payload", response_text); |
| 6826 | } |
| 6827 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6828 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6829 | HttpRequestInfo request; |
| 6830 | request.method = "GET"; |
| 6831 | request.url = GURL("http://www.google.com/"); |
| 6832 | request.load_flags = 0; |
| 6833 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6834 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6835 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 6836 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6837 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6838 | |
| 6839 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6841 | CreateSession(&session_deps_))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6842 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6843 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 6844 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 6845 | const char kSOCKS5OkRequest[] = { |
| 6846 | 0x05, // Version |
| 6847 | 0x01, // Command (CONNECT) |
| 6848 | 0x00, // Reserved. |
| 6849 | 0x03, // Address type (DOMAINNAME). |
| 6850 | 0x0E, // Length of domain (14) |
| 6851 | // Domain string: |
| 6852 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 6853 | 0x00, 0x50, // 16-bit port (80) |
| 6854 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6855 | const char kSOCKS5OkResponse[] = |
| 6856 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 6857 | |
| 6858 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6859 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 6860 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6861 | MockWrite("GET / HTTP/1.1\r\n" |
| 6862 | "Host: www.google.com\r\n" |
| 6863 | "Connection: keep-alive\r\n\r\n") |
| 6864 | }; |
| 6865 | |
| 6866 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6867 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 6868 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6869 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6870 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6871 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6872 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6873 | }; |
| 6874 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6875 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6876 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6879 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6881 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6882 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6883 | |
| 6884 | rv = callback.WaitForResult(); |
| 6885 | EXPECT_EQ(OK, rv); |
| 6886 | |
| 6887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6888 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6889 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6890 | LoadTimingInfo load_timing_info; |
| 6891 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6892 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6893 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6894 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6895 | std::string response_text; |
| 6896 | rv = ReadTransaction(trans.get(), &response_text); |
| 6897 | EXPECT_EQ(OK, rv); |
| 6898 | EXPECT_EQ("Payload", response_text); |
| 6899 | } |
| 6900 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6901 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6902 | HttpRequestInfo request; |
| 6903 | request.method = "GET"; |
| 6904 | request.url = GURL("https://www.google.com/"); |
| 6905 | request.load_flags = 0; |
| 6906 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6907 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6908 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 6909 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6910 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6911 | |
| 6912 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6914 | CreateSession(&session_deps_))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6915 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6916 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 6917 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 6918 | const unsigned char kSOCKS5OkRequest[] = { |
| 6919 | 0x05, // Version |
| 6920 | 0x01, // Command (CONNECT) |
| 6921 | 0x00, // Reserved. |
| 6922 | 0x03, // Address type (DOMAINNAME). |
| 6923 | 0x0E, // Length of domain (14) |
| 6924 | // Domain string: |
| 6925 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 6926 | 0x01, 0xBB, // 16-bit port (443) |
| 6927 | }; |
| 6928 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6929 | const char kSOCKS5OkResponse[] = |
| 6930 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 6931 | |
| 6932 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6933 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 6934 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6935 | arraysize(kSOCKS5OkRequest)), |
| 6936 | MockWrite("GET / HTTP/1.1\r\n" |
| 6937 | "Host: www.google.com\r\n" |
| 6938 | "Connection: keep-alive\r\n\r\n") |
| 6939 | }; |
| 6940 | |
| 6941 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6942 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 6943 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6944 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6945 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6946 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6947 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6948 | }; |
| 6949 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6950 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6951 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6952 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6953 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6954 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6957 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6959 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6961 | |
| 6962 | rv = callback.WaitForResult(); |
| 6963 | EXPECT_EQ(OK, rv); |
| 6964 | |
| 6965 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6966 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6967 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6968 | LoadTimingInfo load_timing_info; |
| 6969 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6970 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6971 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6972 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6973 | std::string response_text; |
| 6974 | rv = ReadTransaction(trans.get(), &response_text); |
| 6975 | EXPECT_EQ(OK, rv); |
| 6976 | EXPECT_EQ("Payload", response_text); |
| 6977 | } |
| 6978 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6979 | namespace { |
| 6980 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 6981 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 6982 | |
| 6983 | struct GroupNameTest { |
| 6984 | std::string proxy_server; |
| 6985 | std::string url; |
| 6986 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 6987 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 6988 | }; |
| 6989 | |
| 6990 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6991 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6992 | SpdySessionDependencies* session_deps_) { |
| 6993 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 6994 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 6995 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 6996 | session->http_server_properties(); |
| 6997 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 6998 | HostPortPair("host.with.alternate", 80), 443, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6999 | AlternateProtocolFromNextProto(next_proto)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7000 | |
| 7001 | return session; |
| 7002 | } |
| 7003 | |
| 7004 | int GroupNameTransactionHelper( |
| 7005 | const std::string& url, |
| 7006 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7007 | HttpRequestInfo request; |
| 7008 | request.method = "GET"; |
| 7009 | request.url = GURL(url); |
| 7010 | request.load_flags = 0; |
| 7011 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7012 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7013 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7015 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7016 | |
| 7017 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7018 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7019 | } |
| 7020 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7021 | } // namespace |
| 7022 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7023 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7024 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7025 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7026 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7027 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7028 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7029 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7030 | }, |
| 7031 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7032 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7033 | "http://[2001:1418:13:1::25]/direct", |
| 7034 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7035 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7036 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7037 | |
| 7038 | // SSL Tests |
| 7039 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7040 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7041 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7042 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7043 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7044 | }, |
| 7045 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7046 | "", // unused |
| 7047 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7048 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7049 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7050 | }, |
| 7051 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7052 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7053 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7054 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7055 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7056 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7057 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7058 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7059 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7060 | |
| 7061 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7062 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7063 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7064 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7065 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7066 | |
| 7067 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7068 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7069 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7070 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7071 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7072 | MockClientSocketPoolManager* mock_pool_manager = |
| 7073 | new MockClientSocketPoolManager; |
| 7074 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7075 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
| 7076 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7077 | |
| 7078 | EXPECT_EQ(ERR_IO_PENDING, |
| 7079 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7080 | if (tests[i].ssl) |
| 7081 | EXPECT_EQ(tests[i].expected_group_name, |
| 7082 | ssl_conn_pool->last_group_name_received()); |
| 7083 | else |
| 7084 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7085 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7086 | } |
| 7087 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7088 | } |
| 7089 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7090 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7091 | const GroupNameTest tests[] = { |
| 7092 | { |
| 7093 | "http_proxy", |
| 7094 | "http://www.google.com/http_proxy_normal", |
| 7095 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7096 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7097 | }, |
| 7098 | |
| 7099 | // SSL Tests |
| 7100 | { |
| 7101 | "http_proxy", |
| 7102 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7103 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7104 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7105 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7106 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7107 | { |
| 7108 | "http_proxy", |
| 7109 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7110 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7111 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7112 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7113 | |
| 7114 | { |
| 7115 | "http_proxy", |
| 7116 | "ftp://ftp.google.com/http_proxy_normal", |
| 7117 | "ftp/ftp.google.com:21", |
| 7118 | false, |
| 7119 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7120 | }; |
| 7121 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7122 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7123 | |
| 7124 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7125 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7126 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7127 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7128 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7129 | |
| 7130 | HttpNetworkSessionPeer peer(session); |
| 7131 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7132 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7133 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7134 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7135 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7136 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7137 | |
| 7138 | MockClientSocketPoolManager* mock_pool_manager = |
| 7139 | new MockClientSocketPoolManager; |
| 7140 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7141 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
| 7142 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7143 | |
| 7144 | EXPECT_EQ(ERR_IO_PENDING, |
| 7145 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7146 | if (tests[i].ssl) |
| 7147 | EXPECT_EQ(tests[i].expected_group_name, |
| 7148 | ssl_conn_pool->last_group_name_received()); |
| 7149 | else |
| 7150 | EXPECT_EQ(tests[i].expected_group_name, |
| 7151 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7152 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7153 | } |
| 7154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7155 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7156 | const GroupNameTest tests[] = { |
| 7157 | { |
| 7158 | "socks4://socks_proxy:1080", |
| 7159 | "http://www.google.com/socks4_direct", |
| 7160 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7161 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7162 | }, |
| 7163 | { |
| 7164 | "socks5://socks_proxy:1080", |
| 7165 | "http://www.google.com/socks5_direct", |
| 7166 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7167 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7168 | }, |
| 7169 | |
| 7170 | // SSL Tests |
| 7171 | { |
| 7172 | "socks4://socks_proxy:1080", |
| 7173 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7174 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7175 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7176 | }, |
| 7177 | { |
| 7178 | "socks5://socks_proxy:1080", |
| 7179 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7180 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7181 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7182 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7183 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7184 | { |
| 7185 | "socks4://socks_proxy:1080", |
| 7186 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7187 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7188 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7189 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7190 | }; |
| 7191 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7192 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7193 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7194 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7195 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7196 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7197 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7198 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7199 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7200 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7201 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7202 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7203 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7204 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7205 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7206 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7207 | |
| 7208 | MockClientSocketPoolManager* mock_pool_manager = |
| 7209 | new MockClientSocketPoolManager; |
| 7210 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 7211 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
| 7212 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7213 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7214 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7216 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7217 | EXPECT_EQ(ERR_IO_PENDING, |
| 7218 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7219 | if (tests[i].ssl) |
| 7220 | EXPECT_EQ(tests[i].expected_group_name, |
| 7221 | ssl_conn_pool->last_group_name_received()); |
| 7222 | else |
| 7223 | EXPECT_EQ(tests[i].expected_group_name, |
| 7224 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7225 | } |
| 7226 | } |
| 7227 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7228 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7229 | HttpRequestInfo request; |
| 7230 | request.method = "GET"; |
| 7231 | request.url = GURL("http://www.google.com/"); |
| 7232 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7233 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 7234 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7235 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 7236 | // This simulates failure resolving all hostnames; that means we will fail |
| 7237 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7238 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7239 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7240 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7242 | CreateSession(&session_deps_))); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7244 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7246 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7247 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7248 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7249 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 7250 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7251 | } |
| 7252 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7253 | // Base test to make sure that when the load flags for a request specify to |
| 7254 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7255 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7256 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7257 | // Issue a request, asking to bypass the cache(s). |
| 7258 | HttpRequestInfo request; |
| 7259 | request.method = "GET"; |
| 7260 | request.load_flags = load_flags; |
| 7261 | request.url = GURL("http://www.google.com/"); |
| 7262 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 7263 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7264 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7265 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7266 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7267 | CreateSession(&session_deps_))); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7268 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7269 | // Warm up the host cache so it has an entry for "www.google.com". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7270 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7271 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7272 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 930cc74 | 2010-09-15 22:54:10 | [diff] [blame] | 7273 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), &addrlist, |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7274 | callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7276 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7277 | EXPECT_EQ(OK, rv); |
| 7278 | |
| 7279 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 7280 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7281 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 930cc74 | 2010-09-15 22:54:10 | [diff] [blame] | 7282 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), &addrlist, |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7283 | callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7284 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7285 | |
| 7286 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 7287 | // we can tell if the next lookup hit the cache, or the "network". |
| 7288 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7289 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7290 | |
| 7291 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 7292 | // 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] | 7293 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7294 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7296 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7297 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7298 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7299 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7300 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7301 | |
| 7302 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 7303 | // "www.google.com". |
| 7304 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 7305 | } |
| 7306 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7307 | // There are multiple load flags that should trigger the host cache bypass. |
| 7308 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7309 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7310 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 7311 | } |
| 7312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7313 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7314 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 7315 | } |
| 7316 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7317 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7318 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 7319 | } |
| 7320 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7321 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7322 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7323 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7324 | |
| 7325 | HttpRequestInfo request; |
| 7326 | request.method = "GET"; |
| 7327 | request.url = GURL("http://www.foo.com/"); |
| 7328 | request.load_flags = 0; |
| 7329 | |
| 7330 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7331 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7332 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7333 | StaticSocketDataProvider data(NULL, 0, |
| 7334 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7337 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7338 | |
| 7339 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7340 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7341 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7343 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7344 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7345 | |
| 7346 | rv = callback.WaitForResult(); |
| 7347 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 7348 | } |
| 7349 | |
| 7350 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7351 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7352 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7353 | |
| 7354 | HttpRequestInfo request; |
| 7355 | request.method = "GET"; |
| 7356 | request.url = GURL("http://www.foo.com/"); |
| 7357 | request.load_flags = 0; |
| 7358 | |
| 7359 | MockRead data_reads[] = { |
| 7360 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7361 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7362 | }; |
| 7363 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7364 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7365 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7367 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7368 | |
| 7369 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7370 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7371 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [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] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7375 | |
| 7376 | rv = callback.WaitForResult(); |
| 7377 | EXPECT_EQ(OK, rv); |
| 7378 | |
| 7379 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7380 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7381 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7382 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7383 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7384 | |
| 7385 | std::string response_data; |
| 7386 | rv = ReadTransaction(trans.get(), &response_data); |
| 7387 | EXPECT_EQ(OK, rv); |
| 7388 | EXPECT_EQ("", response_data); |
| 7389 | } |
| 7390 | |
| 7391 | // Make sure that a dropped connection while draining the body for auth |
| 7392 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7393 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7394 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7395 | |
| 7396 | HttpRequestInfo request; |
| 7397 | request.method = "GET"; |
| 7398 | request.url = GURL("http://www.google.com/"); |
| 7399 | request.load_flags = 0; |
| 7400 | |
| 7401 | MockWrite data_writes1[] = { |
| 7402 | MockWrite("GET / HTTP/1.1\r\n" |
| 7403 | "Host: www.google.com\r\n" |
| 7404 | "Connection: keep-alive\r\n\r\n"), |
| 7405 | }; |
| 7406 | |
| 7407 | MockRead data_reads1[] = { |
| 7408 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7409 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7410 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7411 | MockRead("Content-Length: 14\r\n\r\n"), |
| 7412 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7413 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7414 | }; |
| 7415 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7416 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7417 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7418 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7419 | |
| 7420 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7421 | // be issuing -- the final header line contains the credentials. |
| 7422 | MockWrite data_writes2[] = { |
| 7423 | MockWrite("GET / HTTP/1.1\r\n" |
| 7424 | "Host: www.google.com\r\n" |
| 7425 | "Connection: keep-alive\r\n" |
| 7426 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 7427 | }; |
| 7428 | |
| 7429 | // Lastly, the server responds with the actual content. |
| 7430 | MockRead data_reads2[] = { |
| 7431 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7433 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7435 | }; |
| 7436 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7437 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7438 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7439 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7441 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7442 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7443 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7446 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7447 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7448 | |
| 7449 | rv = callback1.WaitForResult(); |
| 7450 | EXPECT_EQ(OK, rv); |
| 7451 | |
| 7452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7453 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7454 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7456 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7458 | rv = trans->RestartWithAuth( |
| 7459 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7460 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7461 | |
| 7462 | rv = callback2.WaitForResult(); |
| 7463 | EXPECT_EQ(OK, rv); |
| 7464 | |
| 7465 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7466 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7467 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7468 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7469 | } |
| 7470 | |
| 7471 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7472 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7473 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7474 | |
| 7475 | HttpRequestInfo request; |
| 7476 | request.method = "GET"; |
| 7477 | request.url = GURL("https://www.google.com/"); |
| 7478 | request.load_flags = 0; |
| 7479 | |
| 7480 | MockRead proxy_reads[] = { |
| 7481 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7482 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7483 | }; |
| 7484 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7485 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7486 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7487 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7491 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7492 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7493 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7494 | |
| 7495 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7496 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7497 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7499 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7501 | |
| 7502 | rv = callback.WaitForResult(); |
| 7503 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 7504 | } |
| 7505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7506 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7507 | HttpRequestInfo request; |
| 7508 | request.method = "GET"; |
| 7509 | request.url = GURL("http://www.google.com/"); |
| 7510 | request.load_flags = 0; |
| 7511 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7512 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7514 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7515 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7516 | MockRead data_reads[] = { |
| 7517 | 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] | 7518 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7519 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7520 | |
| 7521 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7524 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7526 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7527 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7528 | |
| 7529 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 7530 | |
| 7531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7532 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7533 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7534 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7535 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7536 | |
| 7537 | std::string response_data; |
| 7538 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 7539 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7540 | } |
| 7541 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7542 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7543 | base::FilePath temp_file_path; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7544 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); |
| 7545 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 7546 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 7547 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7548 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7549 | ScopedVector<UploadElementReader> element_readers; |
| 7550 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7551 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7552 | temp_file_path, |
| 7553 | 0, |
| 7554 | kuint64max, |
| 7555 | base::Time())); |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7556 | UploadDataStream upload_data_stream(&element_readers, 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7557 | |
| 7558 | HttpRequestInfo request; |
| 7559 | request.method = "POST"; |
| 7560 | request.url = GURL("http://www.google.com/upload"); |
| 7561 | request.upload_data_stream = &upload_data_stream; |
| 7562 | request.load_flags = 0; |
| 7563 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7564 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7565 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7566 | CreateSession(&session_deps_))); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7567 | |
| 7568 | MockRead data_reads[] = { |
| 7569 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 7570 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7571 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7572 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7576 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7578 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7579 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7580 | |
| 7581 | rv = callback.WaitForResult(); |
| 7582 | EXPECT_EQ(OK, rv); |
| 7583 | |
| 7584 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7585 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7586 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7587 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7588 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7589 | |
| 7590 | std::string response_data; |
| 7591 | rv = ReadTransaction(trans.get(), &response_data); |
| 7592 | EXPECT_EQ(OK, rv); |
| 7593 | EXPECT_EQ("hello world", response_data); |
| 7594 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7595 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7596 | } |
| 7597 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7598 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7599 | base::FilePath temp_file; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7600 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
| 7601 | std::string temp_file_content("Unreadable file."); |
| 7602 | ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), |
| 7603 | temp_file_content.length())); |
| 7604 | ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
| 7605 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7606 | ScopedVector<UploadElementReader> element_readers; |
| 7607 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7608 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7609 | temp_file, |
| 7610 | 0, |
| 7611 | kuint64max, |
| 7612 | base::Time())); |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7613 | UploadDataStream upload_data_stream(&element_readers, 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7614 | |
| 7615 | HttpRequestInfo request; |
| 7616 | request.method = "POST"; |
| 7617 | request.url = GURL("http://www.google.com/upload"); |
| 7618 | request.upload_data_stream = &upload_data_stream; |
| 7619 | request.load_flags = 0; |
| 7620 | |
| 7621 | // If we try to upload an unreadable file, the network stack should report |
| 7622 | // the file size as zero and upload zero bytes for that file. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7623 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7624 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7625 | CreateSession(&session_deps_))); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7626 | |
| 7627 | MockRead data_reads[] = { |
| 7628 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7630 | }; |
| 7631 | MockWrite data_writes[] = { |
| 7632 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7633 | "Host: www.google.com\r\n" |
| 7634 | "Connection: keep-alive\r\n" |
| 7635 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7636 | MockWrite(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7637 | }; |
| 7638 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7639 | arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7642 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7644 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7646 | |
| 7647 | rv = callback.WaitForResult(); |
| 7648 | EXPECT_EQ(OK, rv); |
| 7649 | |
| 7650 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7651 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7652 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7653 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7654 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7655 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7656 | } |
| 7657 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7658 | TEST_P(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7659 | base::FilePath temp_file; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7660 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
| 7661 | std::string temp_file_contents("Unreadable file."); |
| 7662 | std::string unreadable_contents(temp_file_contents.length(), '\0'); |
| 7663 | ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), |
| 7664 | temp_file_contents.length())); |
| 7665 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7666 | ScopedVector<UploadElementReader> element_readers; |
| 7667 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7668 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7669 | temp_file, |
| 7670 | 0, |
| 7671 | kuint64max, |
| 7672 | base::Time())); |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7673 | UploadDataStream upload_data_stream(&element_readers, 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7674 | |
| 7675 | HttpRequestInfo request; |
| 7676 | request.method = "POST"; |
| 7677 | request.url = GURL("http://www.google.com/upload"); |
| 7678 | request.upload_data_stream = &upload_data_stream; |
| 7679 | request.load_flags = 0; |
| 7680 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7681 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7683 | CreateSession(&session_deps_))); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7684 | |
| 7685 | MockRead data_reads[] = { |
| 7686 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7687 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7688 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
| 7689 | |
| 7690 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7691 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7692 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7693 | }; |
| 7694 | MockWrite data_writes[] = { |
| 7695 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7696 | "Host: www.google.com\r\n" |
| 7697 | "Connection: keep-alive\r\n" |
| 7698 | "Content-Length: 16\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7699 | MockWrite(SYNCHRONOUS, temp_file_contents.c_str()), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7700 | |
| 7701 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7702 | "Host: www.google.com\r\n" |
| 7703 | "Connection: keep-alive\r\n" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 7704 | "Content-Length: 0\r\n" |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7705 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7706 | MockWrite(SYNCHRONOUS, unreadable_contents.c_str(), |
| 7707 | temp_file_contents.length()), |
| 7708 | MockWrite(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7709 | }; |
| 7710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7711 | arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7714 | TestCompletionCallback callback1; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7716 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7718 | |
| 7719 | rv = callback1.WaitForResult(); |
| 7720 | EXPECT_EQ(OK, rv); |
| 7721 | |
| 7722 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7723 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7724 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7725 | EXPECT_EQ("HTTP/1.1 401 Unauthorized", response->headers->GetStatusLine()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7726 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7727 | |
| 7728 | // Now make the file unreadable and try again. |
| 7729 | ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
| 7730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7731 | TestCompletionCallback callback2; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7733 | rv = trans->RestartWithAuth( |
| 7734 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7735 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7736 | |
| 7737 | rv = callback2.WaitForResult(); |
| 7738 | EXPECT_EQ(OK, rv); |
| 7739 | |
| 7740 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7741 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7742 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7743 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7744 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7745 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7746 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7747 | } |
| 7748 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7749 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7750 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7751 | |
| 7752 | HttpRequestInfo request; |
| 7753 | request.method = "GET"; |
| 7754 | request.url = GURL("http://www.google.com/"); |
| 7755 | request.load_flags = 0; |
| 7756 | |
| 7757 | // First transaction will request a resource and receive a Basic challenge |
| 7758 | // with realm="first_realm". |
| 7759 | MockWrite data_writes1[] = { |
| 7760 | MockWrite("GET / HTTP/1.1\r\n" |
| 7761 | "Host: www.google.com\r\n" |
| 7762 | "Connection: keep-alive\r\n" |
| 7763 | "\r\n"), |
| 7764 | }; |
| 7765 | MockRead data_reads1[] = { |
| 7766 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7767 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 7768 | "\r\n"), |
| 7769 | }; |
| 7770 | |
| 7771 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 7772 | // for first_realm. The server will reject and provide a challenge with |
| 7773 | // second_realm. |
| 7774 | MockWrite data_writes2[] = { |
| 7775 | MockWrite("GET / HTTP/1.1\r\n" |
| 7776 | "Host: www.google.com\r\n" |
| 7777 | "Connection: keep-alive\r\n" |
| 7778 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 7779 | "\r\n"), |
| 7780 | }; |
| 7781 | MockRead data_reads2[] = { |
| 7782 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7783 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 7784 | "\r\n"), |
| 7785 | }; |
| 7786 | |
| 7787 | // This again fails, and goes back to first_realm. Make sure that the |
| 7788 | // entry is removed from cache. |
| 7789 | MockWrite data_writes3[] = { |
| 7790 | MockWrite("GET / HTTP/1.1\r\n" |
| 7791 | "Host: www.google.com\r\n" |
| 7792 | "Connection: keep-alive\r\n" |
| 7793 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 7794 | "\r\n"), |
| 7795 | }; |
| 7796 | MockRead data_reads3[] = { |
| 7797 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7798 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 7799 | "\r\n"), |
| 7800 | }; |
| 7801 | |
| 7802 | // Try one last time (with the correct password) and get the resource. |
| 7803 | MockWrite data_writes4[] = { |
| 7804 | MockWrite("GET / HTTP/1.1\r\n" |
| 7805 | "Host: www.google.com\r\n" |
| 7806 | "Connection: keep-alive\r\n" |
| 7807 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 7808 | "\r\n"), |
| 7809 | }; |
| 7810 | MockRead data_reads4[] = { |
| 7811 | MockRead("HTTP/1.1 200 OK\r\n" |
| 7812 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7813 | "Content-Length: 5\r\n" |
| 7814 | "\r\n" |
| 7815 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7816 | }; |
| 7817 | |
| 7818 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7819 | data_writes1, arraysize(data_writes1)); |
| 7820 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7821 | data_writes2, arraysize(data_writes2)); |
| 7822 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7823 | data_writes3, arraysize(data_writes3)); |
| 7824 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 7825 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7826 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7827 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7828 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7829 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7831 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7832 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7833 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7835 | CreateSession(&session_deps_))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7836 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7837 | // Issue the first request with Authorize headers. There should be a |
| 7838 | // password prompt for first_realm waiting to be filled in after the |
| 7839 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7840 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7841 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7842 | rv = callback1.WaitForResult(); |
| 7843 | EXPECT_EQ(OK, rv); |
| 7844 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7845 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7846 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 7847 | ASSERT_FALSE(challenge == NULL); |
| 7848 | EXPECT_FALSE(challenge->is_proxy); |
| 7849 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7850 | EXPECT_EQ("first_realm", challenge->realm); |
| 7851 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7852 | |
| 7853 | // Issue the second request with an incorrect password. There should be a |
| 7854 | // password prompt for second_realm waiting to be filled in after the |
| 7855 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7856 | TestCompletionCallback callback2; |
| 7857 | rv = trans->RestartWithAuth( |
| 7858 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7860 | rv = callback2.WaitForResult(); |
| 7861 | EXPECT_EQ(OK, rv); |
| 7862 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7863 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7864 | challenge = response->auth_challenge.get(); |
| 7865 | ASSERT_FALSE(challenge == NULL); |
| 7866 | EXPECT_FALSE(challenge->is_proxy); |
| 7867 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7868 | EXPECT_EQ("second_realm", challenge->realm); |
| 7869 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7870 | |
| 7871 | // Issue the third request with another incorrect password. There should be |
| 7872 | // a password prompt for first_realm waiting to be filled in. If the password |
| 7873 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 7874 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7875 | TestCompletionCallback callback3; |
| 7876 | rv = trans->RestartWithAuth( |
| 7877 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7879 | rv = callback3.WaitForResult(); |
| 7880 | EXPECT_EQ(OK, rv); |
| 7881 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7882 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7883 | challenge = response->auth_challenge.get(); |
| 7884 | ASSERT_FALSE(challenge == NULL); |
| 7885 | EXPECT_FALSE(challenge->is_proxy); |
| 7886 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7887 | EXPECT_EQ("first_realm", challenge->realm); |
| 7888 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7889 | |
| 7890 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7891 | TestCompletionCallback callback4; |
| 7892 | rv = trans->RestartWithAuth( |
| 7893 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7895 | rv = callback4.WaitForResult(); |
| 7896 | EXPECT_EQ(OK, rv); |
| 7897 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7898 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7899 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7900 | } |
| 7901 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7902 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 7903 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7904 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 7905 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7906 | std::string alternate_protocol_http_header = |
| 7907 | GetAlternateProtocolHttpHeader(); |
| 7908 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7909 | MockRead data_reads[] = { |
| 7910 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7911 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7912 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7913 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7914 | }; |
| 7915 | |
| 7916 | HttpRequestInfo request; |
| 7917 | request.method = "GET"; |
| 7918 | request.url = GURL("http://www.google.com/"); |
| 7919 | request.load_flags = 0; |
| 7920 | |
| 7921 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7922 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7923 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7925 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7926 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7927 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7928 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7931 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7932 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 7933 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 7934 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7935 | const HttpServerProperties& http_server_properties = |
| 7936 | *session->http_server_properties(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7937 | EXPECT_FALSE( |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7938 | http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7939 | |
| 7940 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 7941 | |
| 7942 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7943 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7944 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7945 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 7946 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 7947 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7948 | |
| 7949 | std::string response_data; |
| 7950 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 7951 | EXPECT_EQ("hello world", response_data); |
| 7952 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7953 | ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
| 7954 | const PortAlternateProtocolPair alternate = |
| 7955 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 7956 | PortAlternateProtocolPair expected_alternate; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7957 | expected_alternate.port = 443; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7958 | expected_alternate.protocol = AlternateProtocolFromNextProto(GetParam()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7959 | EXPECT_TRUE(expected_alternate.Equals(alternate)); |
| 7960 | } |
| 7961 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7962 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7963 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7964 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7965 | |
| 7966 | HttpRequestInfo request; |
| 7967 | request.method = "GET"; |
| 7968 | request.url = GURL("http://www.google.com/"); |
| 7969 | request.load_flags = 0; |
| 7970 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 7971 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7972 | StaticSocketDataProvider first_data; |
| 7973 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7974 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7975 | |
| 7976 | MockRead data_reads[] = { |
| 7977 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 7978 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7979 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7980 | }; |
| 7981 | StaticSocketDataProvider second_data( |
| 7982 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7983 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7984 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7985 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7986 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7987 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7988 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7989 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 7990 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7991 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7992 | HostPortPair::FromURL(request.url), |
| 7993 | 666 /* port is ignored by MockConnect anyway */, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7994 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7995 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7996 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7998 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8000 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8002 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8003 | |
| 8004 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8005 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8006 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8007 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8008 | |
| 8009 | std::string response_data; |
| 8010 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8011 | EXPECT_EQ("hello world", response_data); |
| 8012 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8013 | ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8014 | HostPortPair::FromURL(request.url))); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8015 | const PortAlternateProtocolPair alternate = |
| 8016 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8017 | HostPortPair::FromURL(request.url)); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8018 | EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8019 | } |
| 8020 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8021 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8022 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8023 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8024 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8025 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8026 | // other cases. |
| 8027 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8028 | |
| 8029 | HttpRequestInfo restricted_port_request; |
| 8030 | restricted_port_request.method = "GET"; |
| 8031 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8032 | restricted_port_request.load_flags = 0; |
| 8033 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8034 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8035 | StaticSocketDataProvider first_data; |
| 8036 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8037 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8038 | |
| 8039 | MockRead data_reads[] = { |
| 8040 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8041 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8042 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8043 | }; |
| 8044 | StaticSocketDataProvider second_data( |
| 8045 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8046 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8047 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8048 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8049 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8050 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8051 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8052 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8053 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8054 | HostPortPair::FromURL(restricted_port_request.url), |
| 8055 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8056 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8057 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8058 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8060 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8062 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8063 | &restricted_port_request, |
| 8064 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8065 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8066 | // Invalid change to unrestricted port should fail. |
| 8067 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8068 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8069 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8070 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8071 | AlternateProtocolPortRestrictedPermitted) { |
| 8072 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8073 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8074 | // on a restricted port (port < 1024) if we set |
| 8075 | // enable_user_alternate_protocol_ports. |
| 8076 | |
| 8077 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8078 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8079 | |
| 8080 | HttpRequestInfo restricted_port_request; |
| 8081 | restricted_port_request.method = "GET"; |
| 8082 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8083 | restricted_port_request.load_flags = 0; |
| 8084 | |
| 8085 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8086 | StaticSocketDataProvider first_data; |
| 8087 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8088 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8089 | |
| 8090 | MockRead data_reads[] = { |
| 8091 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8092 | MockRead("hello world"), |
| 8093 | MockRead(ASYNC, OK), |
| 8094 | }; |
| 8095 | StaticSocketDataProvider second_data( |
| 8096 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8097 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8098 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8099 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8100 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8101 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8102 | session->http_server_properties(); |
| 8103 | const int kUnrestrictedAlternatePort = 1024; |
| 8104 | http_server_properties->SetAlternateProtocol( |
| 8105 | HostPortPair::FromURL(restricted_port_request.url), |
| 8106 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8107 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [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] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8111 | TestCompletionCallback callback; |
| 8112 | |
| 8113 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8114 | &restricted_port_request, |
| 8115 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8116 | // Change to unrestricted port should succeed. |
| 8117 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8118 | } |
| 8119 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8120 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8121 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8122 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8123 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8124 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8125 | // other cases. |
| 8126 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8127 | |
| 8128 | HttpRequestInfo restricted_port_request; |
| 8129 | restricted_port_request.method = "GET"; |
| 8130 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8131 | restricted_port_request.load_flags = 0; |
| 8132 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8133 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8134 | StaticSocketDataProvider first_data; |
| 8135 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8136 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8137 | |
| 8138 | MockRead data_reads[] = { |
| 8139 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8140 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8141 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8142 | }; |
| 8143 | StaticSocketDataProvider second_data( |
| 8144 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8145 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8146 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8147 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8148 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8149 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8150 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8151 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8152 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8153 | HostPortPair::FromURL(restricted_port_request.url), |
| 8154 | kRestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8155 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8156 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8157 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8158 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8159 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8161 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8162 | &restricted_port_request, |
| 8163 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8165 | // Valid change to restricted port should pass. |
| 8166 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8167 | } |
| 8168 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8169 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8170 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8171 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8172 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8173 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8174 | // other cases. |
| 8175 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8176 | |
| 8177 | HttpRequestInfo unrestricted_port_request; |
| 8178 | unrestricted_port_request.method = "GET"; |
| 8179 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8180 | unrestricted_port_request.load_flags = 0; |
| 8181 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8182 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8183 | StaticSocketDataProvider first_data; |
| 8184 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8185 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8186 | |
| 8187 | MockRead data_reads[] = { |
| 8188 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8189 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8190 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8191 | }; |
| 8192 | StaticSocketDataProvider second_data( |
| 8193 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8194 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8195 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8196 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8197 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8198 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8199 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8200 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8201 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8202 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8203 | kRestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8204 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8205 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8206 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8208 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8210 | int rv = trans->Start( |
| 8211 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8212 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8213 | // Valid change to restricted port should pass. |
| 8214 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8215 | } |
| 8216 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8217 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8218 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8219 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8220 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8221 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8222 | // other cases. |
| 8223 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8224 | |
| 8225 | HttpRequestInfo unrestricted_port_request; |
| 8226 | unrestricted_port_request.method = "GET"; |
| 8227 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8228 | unrestricted_port_request.load_flags = 0; |
| 8229 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8230 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8231 | StaticSocketDataProvider first_data; |
| 8232 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8233 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8234 | |
| 8235 | MockRead data_reads[] = { |
| 8236 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8237 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8238 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8239 | }; |
| 8240 | StaticSocketDataProvider second_data( |
| 8241 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8242 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8243 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8244 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8245 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8246 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8247 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8248 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8249 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8250 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8251 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8252 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8253 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8254 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8255 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8256 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8258 | int rv = trans->Start( |
| 8259 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8261 | // Valid change to an unrestricted port should pass. |
| 8262 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8263 | } |
| 8264 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8265 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8266 | AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8267 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8268 | // protocol to an unsafe port, and that we resume the second |
| 8269 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
| 8270 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8271 | |
| 8272 | HttpRequestInfo request; |
| 8273 | request.method = "GET"; |
| 8274 | request.url = GURL("http://www.google.com/"); |
| 8275 | request.load_flags = 0; |
| 8276 | |
| 8277 | // The alternate protocol request will error out before we attempt to connect, |
| 8278 | // so only the standard HTTP request will try to connect. |
| 8279 | MockRead data_reads[] = { |
| 8280 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8281 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8282 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8283 | }; |
| 8284 | StaticSocketDataProvider data( |
| 8285 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8287 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8288 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8289 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8290 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8291 | session->http_server_properties(); |
| 8292 | const int kUnsafePort = 7; |
| 8293 | http_server_properties->SetAlternateProtocol( |
| 8294 | HostPortPair::FromURL(request.url), |
| 8295 | kUnsafePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8296 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8297 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8298 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8300 | TestCompletionCallback callback; |
| 8301 | |
| 8302 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8303 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8304 | // The HTTP request should succeed. |
| 8305 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8306 | |
| 8307 | // Disable alternate protocol before the asserts. |
| 8308 | HttpStreamFactory::set_use_alternate_protocols(false); |
| 8309 | |
| 8310 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8311 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8312 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8313 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8314 | |
| 8315 | std::string response_data; |
| 8316 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8317 | EXPECT_EQ("hello world", response_data); |
| 8318 | } |
| 8319 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8320 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8321 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8322 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8323 | |
| 8324 | HttpRequestInfo request; |
| 8325 | request.method = "GET"; |
| 8326 | request.url = GURL("http://www.google.com/"); |
| 8327 | request.load_flags = 0; |
| 8328 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8329 | std::string alternate_protocol_http_header = |
| 8330 | GetAlternateProtocolHttpHeader(); |
| 8331 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8332 | MockRead data_reads[] = { |
| 8333 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8334 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8335 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8336 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 8337 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8338 | }; |
| 8339 | |
| 8340 | StaticSocketDataProvider first_transaction( |
| 8341 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8342 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8343 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8344 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8345 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8347 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8348 | scoped_ptr<SpdyFrame> req( |
| 8349 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8350 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8351 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8352 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8353 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8354 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8355 | CreateMockRead(*resp), |
| 8356 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8357 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8358 | }; |
| 8359 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8360 | DelayedSocketData spdy_data( |
| 8361 | 1, // wait for one write to finish before reading. |
| 8362 | spdy_reads, arraysize(spdy_reads), |
| 8363 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8365 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8366 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8367 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8368 | NULL, 0, NULL, 0); |
| 8369 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8370 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8371 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8372 | &hanging_non_alternate_protocol_socket); |
| 8373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8374 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8375 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8376 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8377 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8380 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8381 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8382 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8383 | |
| 8384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8385 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8386 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8387 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8388 | |
| 8389 | std::string response_data; |
| 8390 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8391 | EXPECT_EQ("hello world", response_data); |
| 8392 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8393 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8395 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8396 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8397 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8398 | |
| 8399 | response = trans->GetResponseInfo(); |
| 8400 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8401 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8402 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8403 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8404 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8405 | |
| 8406 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8407 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8408 | } |
| 8409 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8410 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8411 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8412 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8413 | |
| 8414 | HttpRequestInfo request; |
| 8415 | request.method = "GET"; |
| 8416 | request.url = GURL("http://www.google.com/"); |
| 8417 | request.load_flags = 0; |
| 8418 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8419 | std::string alternate_protocol_http_header = |
| 8420 | GetAlternateProtocolHttpHeader(); |
| 8421 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8422 | MockRead data_reads[] = { |
| 8423 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8424 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8425 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8426 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8427 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8428 | }; |
| 8429 | |
| 8430 | StaticSocketDataProvider first_transaction( |
| 8431 | data_reads, arraysize(data_reads), NULL, 0); |
| 8432 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8433 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8434 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8435 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8436 | StaticSocketDataProvider hanging_socket( |
| 8437 | NULL, 0, NULL, 0); |
| 8438 | hanging_socket.set_connect_data(never_finishing_connect); |
| 8439 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 8440 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8441 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 8442 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8443 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8445 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8447 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8448 | scoped_ptr<SpdyFrame> req1( |
| 8449 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 8450 | scoped_ptr<SpdyFrame> req2( |
| 8451 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8452 | MockWrite spdy_writes[] = { |
| 8453 | CreateMockWrite(*req1), |
| 8454 | CreateMockWrite(*req2), |
| 8455 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8456 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8457 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8458 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 8459 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8460 | MockRead spdy_reads[] = { |
| 8461 | CreateMockRead(*resp1), |
| 8462 | CreateMockRead(*data1), |
| 8463 | CreateMockRead(*resp2), |
| 8464 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8465 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8466 | }; |
| 8467 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8468 | DelayedSocketData spdy_data( |
| 8469 | 2, // wait for writes to finish before reading. |
| 8470 | spdy_reads, arraysize(spdy_reads), |
| 8471 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8472 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8474 | |
| 8475 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8476 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8477 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8478 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8479 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8480 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8482 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8484 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 8485 | |
| 8486 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 8487 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8488 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8489 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8490 | |
| 8491 | std::string response_data; |
| 8492 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 8493 | EXPECT_EQ("hello world", response_data); |
| 8494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8495 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8496 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8497 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8500 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8501 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8502 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8503 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8504 | |
| 8505 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 8506 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 8507 | |
| 8508 | response = trans2.GetResponseInfo(); |
| 8509 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8510 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8511 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8512 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8513 | EXPECT_TRUE(response->was_npn_negotiated); |
| 8514 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 8515 | EXPECT_EQ("hello!", response_data); |
| 8516 | |
| 8517 | response = trans3.GetResponseInfo(); |
| 8518 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8519 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8520 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8521 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8522 | EXPECT_TRUE(response->was_npn_negotiated); |
| 8523 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 8524 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8525 | } |
| 8526 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8527 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8528 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8529 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8530 | |
| 8531 | HttpRequestInfo request; |
| 8532 | request.method = "GET"; |
| 8533 | request.url = GURL("http://www.google.com/"); |
| 8534 | request.load_flags = 0; |
| 8535 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8536 | std::string alternate_protocol_http_header = |
| 8537 | GetAlternateProtocolHttpHeader(); |
| 8538 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8539 | MockRead data_reads[] = { |
| 8540 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8541 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8542 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8543 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8544 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8545 | }; |
| 8546 | |
| 8547 | StaticSocketDataProvider first_transaction( |
| 8548 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8549 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8550 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8551 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8552 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8553 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8554 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8555 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8556 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 8557 | NULL, 0, NULL, 0); |
| 8558 | hanging_alternate_protocol_socket.set_connect_data( |
| 8559 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8560 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8561 | &hanging_alternate_protocol_socket); |
| 8562 | |
| 8563 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8564 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8566 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8567 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8568 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8572 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8574 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8575 | |
| 8576 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8577 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8578 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8579 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8580 | |
| 8581 | std::string response_data; |
| 8582 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8583 | EXPECT_EQ("hello world", response_data); |
| 8584 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8585 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8587 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8588 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8589 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8590 | |
| 8591 | response = trans->GetResponseInfo(); |
| 8592 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8593 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8594 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8595 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8596 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8597 | |
| 8598 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8599 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8600 | } |
| 8601 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8602 | class CapturingProxyResolver : public ProxyResolver { |
| 8603 | public: |
| 8604 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
| 8605 | virtual ~CapturingProxyResolver() {} |
| 8606 | |
| 8607 | virtual int GetProxyForURL(const GURL& url, |
| 8608 | ProxyInfo* results, |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 8609 | const CompletionCallback& callback, |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8610 | RequestHandle* request, |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8611 | const BoundNetLog& net_log) OVERRIDE { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 8612 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 8613 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8614 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8615 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8616 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8617 | } |
| 8618 | |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8619 | virtual void CancelRequest(RequestHandle request) OVERRIDE { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8620 | NOTREACHED(); |
| 8621 | } |
| 8622 | |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 8623 | virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 8624 | NOTREACHED(); |
| 8625 | return LOAD_STATE_IDLE; |
| 8626 | } |
| 8627 | |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8628 | virtual void CancelSetPacScript() OVERRIDE { |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 8629 | NOTREACHED(); |
| 8630 | } |
| 8631 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 8632 | virtual int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8633 | const CompletionCallback& /*callback*/) OVERRIDE { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8634 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8635 | } |
| 8636 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 8637 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 8638 | |
| 8639 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8640 | std::vector<GURL> resolved_; |
| 8641 | |
| 8642 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 8643 | }; |
| 8644 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8645 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8646 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8647 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8648 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8649 | |
| 8650 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8651 | proxy_config.set_auto_detect(true); |
| 8652 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 8653 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8654 | CapturingProxyResolver* capturing_proxy_resolver = |
| 8655 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8656 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 8657 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 8658 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8659 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8660 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8661 | |
| 8662 | HttpRequestInfo request; |
| 8663 | request.method = "GET"; |
| 8664 | request.url = GURL("http://www.google.com/"); |
| 8665 | request.load_flags = 0; |
| 8666 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8667 | std::string alternate_protocol_http_header = |
| 8668 | GetAlternateProtocolHttpHeader(); |
| 8669 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8670 | MockRead data_reads[] = { |
| 8671 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8672 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8673 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8674 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8675 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8676 | }; |
| 8677 | |
| 8678 | StaticSocketDataProvider first_transaction( |
| 8679 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8680 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8681 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8682 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8683 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8685 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8686 | scoped_ptr<SpdyFrame> req( |
| 8687 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8688 | MockWrite spdy_writes[] = { |
| 8689 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 8690 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8691 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8692 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8693 | }; |
| 8694 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8695 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 8696 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8697 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8698 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8699 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8700 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8701 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 8702 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8703 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8704 | }; |
| 8705 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8706 | OrderedSocketData spdy_data( |
| 8707 | spdy_reads, arraysize(spdy_reads), |
| 8708 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8709 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8710 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8711 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8712 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8713 | NULL, 0, NULL, 0); |
| 8714 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8715 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8716 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8717 | &hanging_non_alternate_protocol_socket); |
| 8718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8719 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8720 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8721 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8722 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8723 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8725 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8726 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8727 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8728 | |
| 8729 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8730 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8731 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8732 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8733 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8734 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8735 | |
| 8736 | std::string response_data; |
| 8737 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8738 | EXPECT_EQ("hello world", response_data); |
| 8739 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8740 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8742 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8744 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8745 | |
| 8746 | response = trans->GetResponseInfo(); |
| 8747 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8748 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8749 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8750 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8751 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8752 | |
| 8753 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8754 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8755 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8756 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8757 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8758 | EXPECT_EQ("https://www.google.com/", |
| 8759 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8760 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8761 | LoadTimingInfo load_timing_info; |
| 8762 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8763 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8764 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8765 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8766 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8767 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8768 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8769 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8770 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8771 | |
| 8772 | HttpRequestInfo request; |
| 8773 | request.method = "GET"; |
| 8774 | request.url = GURL("http://www.google.com/"); |
| 8775 | request.load_flags = 0; |
| 8776 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8777 | std::string alternate_protocol_http_header = |
| 8778 | GetAlternateProtocolHttpHeader(); |
| 8779 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8780 | MockRead data_reads[] = { |
| 8781 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8782 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8783 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8784 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8785 | }; |
| 8786 | |
| 8787 | StaticSocketDataProvider first_transaction( |
| 8788 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8789 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8790 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8791 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8792 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8794 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8795 | scoped_ptr<SpdyFrame> req( |
| 8796 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8797 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8798 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8799 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8800 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8801 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8802 | CreateMockRead(*resp), |
| 8803 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8804 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8805 | }; |
| 8806 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8807 | DelayedSocketData spdy_data( |
| 8808 | 1, // wait for one write to finish before reading. |
| 8809 | spdy_reads, arraysize(spdy_reads), |
| 8810 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8811 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8812 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 8813 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8814 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8815 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8816 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8817 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8820 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8822 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8823 | |
| 8824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8825 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8826 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8827 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8828 | |
| 8829 | std::string response_data; |
| 8830 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8831 | EXPECT_EQ("hello world", response_data); |
| 8832 | |
| 8833 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 8834 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 8835 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 8836 | kPrivacyModeDisabled); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 8837 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 8838 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 8839 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8840 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8842 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8844 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8845 | |
| 8846 | response = trans->GetResponseInfo(); |
| 8847 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8848 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8850 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8851 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8852 | |
| 8853 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8854 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8855 | } |
| 8856 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8857 | // GenerateAuthToken is a mighty big test. |
| 8858 | // It tests all permutation of GenerateAuthToken behavior: |
| 8859 | // - Synchronous and Asynchronous completion. |
| 8860 | // - OK or error on completion. |
| 8861 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 8862 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 8863 | // - Non-authenticating and authenticating backend. |
| 8864 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 8865 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8866 | // problems generating an auth token for an authenticating proxy, we don't |
| 8867 | // need to test all permutations of the backend server). |
| 8868 | // |
| 8869 | // The test proceeds by going over each of the configuration cases, and |
| 8870 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 8871 | // specifies both the configuration for the test as well as the expectations |
| 8872 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8873 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8874 | static const char kServer[] = "http://www.example.com"; |
| 8875 | static const char kSecureServer[] = "https://www.example.com"; |
| 8876 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8877 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 8878 | |
| 8879 | enum AuthTiming { |
| 8880 | AUTH_NONE, |
| 8881 | AUTH_SYNC, |
| 8882 | AUTH_ASYNC, |
| 8883 | }; |
| 8884 | |
| 8885 | const MockWrite kGet( |
| 8886 | "GET / HTTP/1.1\r\n" |
| 8887 | "Host: www.example.com\r\n" |
| 8888 | "Connection: keep-alive\r\n\r\n"); |
| 8889 | const MockWrite kGetProxy( |
| 8890 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8891 | "Host: www.example.com\r\n" |
| 8892 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 8893 | const MockWrite kGetAuth( |
| 8894 | "GET / HTTP/1.1\r\n" |
| 8895 | "Host: www.example.com\r\n" |
| 8896 | "Connection: keep-alive\r\n" |
| 8897 | "Authorization: auth_token\r\n\r\n"); |
| 8898 | const MockWrite kGetProxyAuth( |
| 8899 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8900 | "Host: www.example.com\r\n" |
| 8901 | "Proxy-Connection: keep-alive\r\n" |
| 8902 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 8903 | const MockWrite kGetAuthThroughProxy( |
| 8904 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8905 | "Host: www.example.com\r\n" |
| 8906 | "Proxy-Connection: keep-alive\r\n" |
| 8907 | "Authorization: auth_token\r\n\r\n"); |
| 8908 | const MockWrite kGetAuthWithProxyAuth( |
| 8909 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8910 | "Host: www.example.com\r\n" |
| 8911 | "Proxy-Connection: keep-alive\r\n" |
| 8912 | "Proxy-Authorization: auth_token\r\n" |
| 8913 | "Authorization: auth_token\r\n\r\n"); |
| 8914 | const MockWrite kConnect( |
| 8915 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 8916 | "Host: www.example.com\r\n" |
| 8917 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 8918 | const MockWrite kConnectProxyAuth( |
| 8919 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 8920 | "Host: www.example.com\r\n" |
| 8921 | "Proxy-Connection: keep-alive\r\n" |
| 8922 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 8923 | |
| 8924 | const MockRead kSuccess( |
| 8925 | "HTTP/1.1 200 OK\r\n" |
| 8926 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 8927 | "Content-Length: 3\r\n\r\n" |
| 8928 | "Yes"); |
| 8929 | const MockRead kFailure( |
| 8930 | "Should not be called."); |
| 8931 | const MockRead kServerChallenge( |
| 8932 | "HTTP/1.1 401 Unauthorized\r\n" |
| 8933 | "WWW-Authenticate: Mock realm=server\r\n" |
| 8934 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 8935 | "Content-Length: 14\r\n\r\n" |
| 8936 | "Unauthorized\r\n"); |
| 8937 | const MockRead kProxyChallenge( |
| 8938 | "HTTP/1.1 407 Unauthorized\r\n" |
| 8939 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 8940 | "Proxy-Connection: close\r\n" |
| 8941 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 8942 | "Content-Length: 14\r\n\r\n" |
| 8943 | "Unauthorized\r\n"); |
| 8944 | const MockRead kProxyConnected( |
| 8945 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 8946 | |
| 8947 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 8948 | // no constructors, but the C++ compiler on Windows warns about |
| 8949 | // unspecified data in compound literals. So, moved to using constructors, |
| 8950 | // and TestRound's created with the default constructor should not be used. |
| 8951 | struct TestRound { |
| 8952 | TestRound() |
| 8953 | : expected_rv(ERR_UNEXPECTED), |
| 8954 | extra_write(NULL), |
| 8955 | extra_read(NULL) { |
| 8956 | } |
| 8957 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 8958 | int expected_rv_arg) |
| 8959 | : write(write_arg), |
| 8960 | read(read_arg), |
| 8961 | expected_rv(expected_rv_arg), |
| 8962 | extra_write(NULL), |
| 8963 | extra_read(NULL) { |
| 8964 | } |
| 8965 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 8966 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8967 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8968 | : write(write_arg), |
| 8969 | read(read_arg), |
| 8970 | expected_rv(expected_rv_arg), |
| 8971 | extra_write(extra_write_arg), |
| 8972 | extra_read(extra_read_arg) { |
| 8973 | } |
| 8974 | MockWrite write; |
| 8975 | MockRead read; |
| 8976 | int expected_rv; |
| 8977 | const MockWrite* extra_write; |
| 8978 | const MockRead* extra_read; |
| 8979 | }; |
| 8980 | |
| 8981 | static const int kNoSSL = 500; |
| 8982 | |
| 8983 | struct TestConfig { |
| 8984 | const char* proxy_url; |
| 8985 | AuthTiming proxy_auth_timing; |
| 8986 | int proxy_auth_rv; |
| 8987 | const char* server_url; |
| 8988 | AuthTiming server_auth_timing; |
| 8989 | int server_auth_rv; |
| 8990 | int num_auth_rounds; |
| 8991 | int first_ssl_round; |
| 8992 | TestRound rounds[3]; |
| 8993 | } test_configs[] = { |
| 8994 | // Non-authenticating HTTP server with a direct connection. |
| 8995 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 8996 | { TestRound(kGet, kSuccess, OK)}}, |
| 8997 | // Authenticating HTTP server with a direct connection. |
| 8998 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 8999 | { TestRound(kGet, kServerChallenge, OK), |
| 9000 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9001 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9002 | { TestRound(kGet, kServerChallenge, OK), |
| 9003 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9004 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9005 | { TestRound(kGet, kServerChallenge, OK), |
| 9006 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9007 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9008 | { TestRound(kGet, kServerChallenge, OK), |
| 9009 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9010 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9011 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9012 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9013 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9014 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9015 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9016 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9017 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9018 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9019 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9020 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9021 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9022 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9023 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9024 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9025 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9026 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9027 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9028 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9029 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9030 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9031 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9032 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9033 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9034 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9035 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9036 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9037 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9038 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9039 | // Authenticating HTTP server through an authenticating proxy. |
| 9040 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9041 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9042 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9043 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9044 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9045 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9046 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9047 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9048 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9049 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9050 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9051 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9052 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9053 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9054 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9055 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9056 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9057 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9058 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9059 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9060 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9061 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9062 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9063 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9064 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9065 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9066 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9067 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9068 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9069 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9070 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9071 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9072 | // Non-authenticating HTTPS server with a direct connection. |
| 9073 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9074 | { TestRound(kGet, kSuccess, OK)}}, |
| 9075 | // Authenticating HTTPS server with a direct connection. |
| 9076 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9077 | { TestRound(kGet, kServerChallenge, OK), |
| 9078 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9079 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9080 | { TestRound(kGet, kServerChallenge, OK), |
| 9081 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9082 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9083 | { TestRound(kGet, kServerChallenge, OK), |
| 9084 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9085 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9086 | { TestRound(kGet, kServerChallenge, OK), |
| 9087 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9088 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9089 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9090 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9091 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9092 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9093 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9094 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9095 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9096 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9097 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9098 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9099 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9100 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9101 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9102 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9103 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9104 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9105 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9106 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9107 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9108 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9109 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9110 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9111 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9112 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9113 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9114 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9115 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9116 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9117 | // Authenticating HTTPS server through an authenticating proxy. |
| 9118 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9119 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9120 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9121 | &kGet, &kServerChallenge), |
| 9122 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9123 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9124 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9125 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9126 | &kGet, &kServerChallenge), |
| 9127 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9128 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9129 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9130 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9131 | &kGet, &kServerChallenge), |
| 9132 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9133 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9134 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9135 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9136 | &kGet, &kServerChallenge), |
| 9137 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9138 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9139 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9140 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9141 | &kGet, &kServerChallenge), |
| 9142 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9143 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9144 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9145 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9146 | &kGet, &kServerChallenge), |
| 9147 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9148 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9149 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9150 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9151 | &kGet, &kServerChallenge), |
| 9152 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9153 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9154 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9155 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9156 | &kGet, &kServerChallenge), |
| 9157 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9158 | }; |
| 9159 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9160 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9161 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9162 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9163 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9164 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9165 | |
| 9166 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9167 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9168 | for (int n = 0; n < 2; n++) { |
| 9169 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9170 | std::string auth_challenge = "Mock realm=proxy"; |
| 9171 | GURL origin(test_config.proxy_url); |
| 9172 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9173 | auth_challenge.end()); |
| 9174 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9175 | origin, BoundNetLog()); |
| 9176 | auth_handler->SetGenerateExpectation( |
| 9177 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9178 | test_config.proxy_auth_rv); |
| 9179 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9180 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9181 | } |
| 9182 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9183 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9184 | std::string auth_challenge = "Mock realm=server"; |
| 9185 | GURL origin(test_config.server_url); |
| 9186 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9187 | auth_challenge.end()); |
| 9188 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9189 | origin, BoundNetLog()); |
| 9190 | auth_handler->SetGenerateExpectation( |
| 9191 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9192 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9193 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9194 | } |
| 9195 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9196 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9197 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9198 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9199 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | HttpRequestInfo request; |
| 9203 | request.method = "GET"; |
| 9204 | request.url = GURL(test_config.server_url); |
| 9205 | request.load_flags = 0; |
| 9206 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9207 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9208 | HttpNetworkTransaction trans( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9209 | DEFAULT_PRIORITY, CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9210 | |
| 9211 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 9212 | const TestRound& read_write_round = test_config.rounds[round]; |
| 9213 | |
| 9214 | // Set up expected reads and writes. |
| 9215 | MockRead reads[2]; |
| 9216 | reads[0] = read_write_round.read; |
| 9217 | size_t length_reads = 1; |
| 9218 | if (read_write_round.extra_read) { |
| 9219 | reads[1] = *read_write_round.extra_read; |
| 9220 | length_reads = 2; |
| 9221 | } |
| 9222 | |
| 9223 | MockWrite writes[2]; |
| 9224 | writes[0] = read_write_round.write; |
| 9225 | size_t length_writes = 1; |
| 9226 | if (read_write_round.extra_write) { |
| 9227 | writes[1] = *read_write_round.extra_write; |
| 9228 | length_writes = 2; |
| 9229 | } |
| 9230 | StaticSocketDataProvider data_provider( |
| 9231 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9232 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9233 | |
| 9234 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9235 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9236 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9237 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9238 | &ssl_socket_data_provider); |
| 9239 | |
| 9240 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9241 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9242 | int rv; |
| 9243 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9244 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9245 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9246 | rv = trans.RestartWithAuth( |
| 9247 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9248 | } |
| 9249 | if (rv == ERR_IO_PENDING) |
| 9250 | rv = callback.WaitForResult(); |
| 9251 | |
| 9252 | // Compare results with expected data. |
| 9253 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9254 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9255 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9256 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9257 | } else { |
| 9258 | EXPECT_TRUE(response == NULL); |
| 9259 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 9260 | continue; |
| 9261 | } |
| 9262 | if (round + 1 < test_config.num_auth_rounds) { |
| 9263 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 9264 | } else { |
| 9265 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9266 | } |
| 9267 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 9268 | } |
| 9269 | } |
| 9270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9271 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9272 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9273 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9274 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9275 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9276 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 9277 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 9278 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9279 | |
| 9280 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9281 | auth_handler->set_connection_based(true); |
| 9282 | std::string auth_challenge = "Mock realm=server"; |
| 9283 | GURL origin("http://www.example.com"); |
| 9284 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9285 | auth_challenge.end()); |
| 9286 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9287 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9288 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9289 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9290 | int rv = OK; |
| 9291 | const HttpResponseInfo* response = NULL; |
| 9292 | HttpRequestInfo request; |
| 9293 | request.method = "GET"; |
| 9294 | request.url = origin; |
| 9295 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9296 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9297 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9298 | |
| 9299 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 9300 | // to validate that the TCP socket is not released to the pool between |
| 9301 | // each round of multi-round authentication. |
| 9302 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9303 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 9304 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9305 | 50, // Max sockets for pool |
| 9306 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9307 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9308 | session_deps_.host_resolver.get(), |
| 9309 | session_deps_.socket_factory.get(), |
| 9310 | session_deps_.net_log); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9311 | MockClientSocketPoolManager* mock_pool_manager = |
| 9312 | new MockClientSocketPoolManager; |
| 9313 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
| 9314 | session_peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9315 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9316 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9318 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9319 | |
| 9320 | const MockWrite kGet( |
| 9321 | "GET / HTTP/1.1\r\n" |
| 9322 | "Host: www.example.com\r\n" |
| 9323 | "Connection: keep-alive\r\n\r\n"); |
| 9324 | const MockWrite kGetAuth( |
| 9325 | "GET / HTTP/1.1\r\n" |
| 9326 | "Host: www.example.com\r\n" |
| 9327 | "Connection: keep-alive\r\n" |
| 9328 | "Authorization: auth_token\r\n\r\n"); |
| 9329 | |
| 9330 | const MockRead kServerChallenge( |
| 9331 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9332 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9333 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9334 | "Content-Length: 14\r\n\r\n" |
| 9335 | "Unauthorized\r\n"); |
| 9336 | const MockRead kSuccess( |
| 9337 | "HTTP/1.1 200 OK\r\n" |
| 9338 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9339 | "Content-Length: 3\r\n\r\n" |
| 9340 | "Yes"); |
| 9341 | |
| 9342 | MockWrite writes[] = { |
| 9343 | // First round |
| 9344 | kGet, |
| 9345 | // Second round |
| 9346 | kGetAuth, |
| 9347 | // Third round |
| 9348 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9349 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9350 | kGetAuth, |
| 9351 | // Competing request |
| 9352 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9353 | }; |
| 9354 | MockRead reads[] = { |
| 9355 | // First round |
| 9356 | kServerChallenge, |
| 9357 | // Second round |
| 9358 | kServerChallenge, |
| 9359 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9360 | kServerChallenge, |
| 9361 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9362 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9363 | // Competing response |
| 9364 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9365 | }; |
| 9366 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 9367 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9368 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9369 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9370 | const char* const kSocketGroup = "www.example.com:80"; |
| 9371 | |
| 9372 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9373 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9374 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9375 | if (rv == ERR_IO_PENDING) |
| 9376 | rv = callback.WaitForResult(); |
| 9377 | EXPECT_EQ(OK, rv); |
| 9378 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9379 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9380 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9381 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9382 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9383 | // In between rounds, another request comes in for the same domain. |
| 9384 | // It should not be able to grab the TCP socket that trans has already |
| 9385 | // claimed. |
| 9386 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9387 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9388 | TestCompletionCallback callback_compete; |
| 9389 | rv = trans_compete->Start( |
| 9390 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9392 | // callback_compete.WaitForResult at this point would stall forever, |
| 9393 | // since the HttpNetworkTransaction does not release the request back to |
| 9394 | // the pool until after authentication completes. |
| 9395 | |
| 9396 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9397 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9398 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9399 | if (rv == ERR_IO_PENDING) |
| 9400 | rv = callback.WaitForResult(); |
| 9401 | EXPECT_EQ(OK, rv); |
| 9402 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9403 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9404 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9405 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9406 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9407 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9408 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9409 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9410 | if (rv == ERR_IO_PENDING) |
| 9411 | rv = callback.WaitForResult(); |
| 9412 | EXPECT_EQ(OK, rv); |
| 9413 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9414 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9415 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9416 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9417 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9418 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9419 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9420 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9421 | if (rv == ERR_IO_PENDING) |
| 9422 | rv = callback.WaitForResult(); |
| 9423 | EXPECT_EQ(OK, rv); |
| 9424 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9425 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9426 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9427 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9428 | |
| 9429 | // Read the body since the fourth round was successful. This will also |
| 9430 | // release the socket back to the pool. |
| 9431 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9432 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9433 | if (rv == ERR_IO_PENDING) |
| 9434 | rv = callback.WaitForResult(); |
| 9435 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9436 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9437 | EXPECT_EQ(0, rv); |
| 9438 | // There are still 0 idle sockets, since the trans_compete transaction |
| 9439 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9440 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9441 | |
| 9442 | // The competing request can now finish. Wait for the headers and then |
| 9443 | // read the body. |
| 9444 | rv = callback_compete.WaitForResult(); |
| 9445 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9446 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9447 | if (rv == ERR_IO_PENDING) |
| 9448 | rv = callback.WaitForResult(); |
| 9449 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9450 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9451 | EXPECT_EQ(0, rv); |
| 9452 | |
| 9453 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9454 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9455 | } |
| 9456 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9457 | // This tests the case that a request is issued via http instead of spdy after |
| 9458 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9459 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9460 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame^] | 9461 | std::vector<NextProto> next_protos; |
| 9462 | next_protos.push_back(kProtoHTTP11); |
| 9463 | HttpStreamFactory::SetNextProtos(next_protos); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9464 | HttpRequestInfo request; |
| 9465 | request.method = "GET"; |
| 9466 | request.url = GURL("https://www.google.com/"); |
| 9467 | request.load_flags = 0; |
| 9468 | |
| 9469 | MockWrite data_writes[] = { |
| 9470 | MockWrite("GET / HTTP/1.1\r\n" |
| 9471 | "Host: www.google.com\r\n" |
| 9472 | "Connection: keep-alive\r\n\r\n"), |
| 9473 | }; |
| 9474 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9475 | std::string alternate_protocol_http_header = |
| 9476 | GetAlternateProtocolHttpHeader(); |
| 9477 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9478 | MockRead data_reads[] = { |
| 9479 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9480 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9481 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9482 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9483 | }; |
| 9484 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9485 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9486 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 9487 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 9488 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9489 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9491 | |
| 9492 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9493 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9496 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9497 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9498 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9499 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9502 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9503 | |
| 9504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9505 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9506 | |
| 9507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9508 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9509 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9510 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9511 | |
| 9512 | std::string response_data; |
| 9513 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9514 | EXPECT_EQ("hello world", response_data); |
| 9515 | |
| 9516 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9517 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9518 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9519 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9520 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9521 | // Simulate the SSL handshake completing with an NPN negotiation |
| 9522 | // followed by an immediate server closing of the socket. |
| 9523 | // Fix crash: http://crbug.com/46369 |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9524 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 9525 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9526 | |
| 9527 | HttpRequestInfo request; |
| 9528 | request.method = "GET"; |
| 9529 | request.url = GURL("https://www.google.com/"); |
| 9530 | request.load_flags = 0; |
| 9531 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9532 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9533 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9535 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9536 | scoped_ptr<SpdyFrame> req( |
| 9537 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9538 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9539 | |
| 9540 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9541 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9542 | }; |
| 9543 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9544 | DelayedSocketData spdy_data( |
| 9545 | 0, // don't wait in this case, immediate hangup. |
| 9546 | spdy_reads, arraysize(spdy_reads), |
| 9547 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9548 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9549 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9550 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9551 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9552 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9553 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9554 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9556 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9557 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9558 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9559 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9560 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9561 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 9562 | // it gets it. This is needed since the auth handler may get destroyed |
| 9563 | // before we get a chance to query it. |
| 9564 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 9565 | public: |
| 9566 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 9567 | |
| 9568 | virtual ~UrlRecordingHttpAuthHandlerMock() {} |
| 9569 | |
| 9570 | protected: |
| 9571 | virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 9572 | const HttpRequestInfo* request, |
| 9573 | const CompletionCallback& callback, |
| 9574 | std::string* auth_token) OVERRIDE { |
| 9575 | *url_ = request->url; |
| 9576 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 9577 | credentials, request, callback, auth_token); |
| 9578 | } |
| 9579 | |
| 9580 | private: |
| 9581 | GURL* url_; |
| 9582 | }; |
| 9583 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9584 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9585 | // This test ensures that the URL passed into the proxy is upgraded |
| 9586 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9587 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9588 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9589 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9590 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9591 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 9592 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9593 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9594 | GURL request_url; |
| 9595 | { |
| 9596 | HttpAuthHandlerMock::Factory* auth_factory = |
| 9597 | new HttpAuthHandlerMock::Factory(); |
| 9598 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 9599 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 9600 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9601 | auth_factory->set_do_init_from_challenge(true); |
| 9602 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9603 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9604 | |
| 9605 | HttpRequestInfo request; |
| 9606 | request.method = "GET"; |
| 9607 | request.url = GURL("http://www.google.com"); |
| 9608 | request.load_flags = 0; |
| 9609 | |
| 9610 | // First round goes unauthenticated through the proxy. |
| 9611 | MockWrite data_writes_1[] = { |
| 9612 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 9613 | "Host: www.google.com\r\n" |
| 9614 | "Proxy-Connection: keep-alive\r\n" |
| 9615 | "\r\n"), |
| 9616 | }; |
| 9617 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9618 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9619 | MockRead("HTTP/1.1 200 OK\r\n" |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9620 | "Alternate-Protocol: 443:npn-spdy/2\r\n" |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9621 | "Proxy-Connection: close\r\n" |
| 9622 | "\r\n"), |
| 9623 | }; |
| 9624 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 9625 | data_writes_1, arraysize(data_writes_1)); |
| 9626 | |
| 9627 | // Second round tries to tunnel to www.google.com due to the |
| 9628 | // Alternate-Protocol announcement in the first round. It fails due |
| 9629 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9630 | // After the failure, a tunnel is established to www.google.com using |
| 9631 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 9632 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9633 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 9634 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 9635 | // does a Disconnect and Connect on the same socket, rather than trying |
| 9636 | // to obtain a new one. |
| 9637 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9638 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 9639 | // simply returned another 407 so the unit test could skip the SSL connection |
| 9640 | // establishment and SPDY framing issues. Alas, the |
| 9641 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9642 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9643 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9644 | scoped_ptr<SpdyFrame> req( |
| 9645 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9646 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9647 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9648 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9649 | MockWrite data_writes_2[] = { |
| 9650 | // First connection attempt without Proxy-Authorization. |
| 9651 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9652 | "Host: www.google.com\r\n" |
| 9653 | "Proxy-Connection: keep-alive\r\n" |
| 9654 | "\r\n"), |
| 9655 | |
| 9656 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9657 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9658 | "Host: www.google.com\r\n" |
| 9659 | "Proxy-Connection: keep-alive\r\n" |
| 9660 | "Proxy-Authorization: auth_token\r\n" |
| 9661 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9662 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9663 | // SPDY request |
| 9664 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9665 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9666 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 9667 | "Proxy-Authenticate: Mock\r\n" |
| 9668 | "Proxy-Connection: close\r\n" |
| 9669 | "\r\n"); |
| 9670 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9671 | MockRead data_reads_2[] = { |
| 9672 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9673 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 9674 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9675 | arraysize(kRejectConnectResponse) - 1, 1), |
| 9676 | |
| 9677 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9678 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9679 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9680 | |
| 9681 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9682 | CreateMockRead(*resp.get(), 6), |
| 9683 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9684 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9685 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9686 | OrderedSocketData data_2( |
| 9687 | data_reads_2, arraysize(data_reads_2), |
| 9688 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9689 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9690 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9691 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9692 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9693 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9694 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9695 | NULL, 0, NULL, 0); |
| 9696 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9697 | never_finishing_connect); |
| 9698 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9699 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 9700 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 9701 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9702 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9703 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9704 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9705 | |
| 9706 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9707 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9708 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9709 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9710 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9712 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 9713 | |
| 9714 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9715 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9716 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9718 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9719 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9720 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 9721 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9722 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9723 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 9724 | |
| 9725 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9726 | TestCompletionCallback callback_3; |
| 9727 | rv = trans_2->RestartWithAuth( |
| 9728 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9730 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 9731 | |
| 9732 | // After all that work, these two lines (or actually, just the scheme) are |
| 9733 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9734 | EXPECT_EQ("https", request_url.scheme()); |
| 9735 | EXPECT_EQ("www.google.com", request_url.host()); |
| 9736 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9737 | LoadTimingInfo load_timing_info; |
| 9738 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 9739 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9740 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9741 | } |
| 9742 | |
| 9743 | // Test that if we cancel the transaction as the connection is completing, that |
| 9744 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9745 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9746 | // Setup everything about the connection to complete synchronously, so that |
| 9747 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 9748 | // for is the callback from the HttpStreamRequest. |
| 9749 | // Then cancel the transaction. |
| 9750 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9751 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9752 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9753 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 9754 | MockRead(SYNCHRONOUS, "hello world"), |
| 9755 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9756 | }; |
| 9757 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9758 | HttpRequestInfo request; |
| 9759 | request.method = "GET"; |
| 9760 | request.url = GURL("http://www.google.com/"); |
| 9761 | request.load_flags = 0; |
| 9762 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9766 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9767 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9768 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9769 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9770 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9772 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9773 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9774 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9775 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9776 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9777 | trans.reset(); // Cancel the transaction here. |
| 9778 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 9779 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9780 | } |
| 9781 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9782 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9783 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9784 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9785 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9786 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9787 | session_deps_.net_log = log.bound().net_log(); |
| 9788 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9789 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9790 | HttpRequestInfo request; |
| 9791 | request.method = "GET"; |
| 9792 | request.url = GURL("http://www.google.com/"); |
| 9793 | |
| 9794 | MockWrite data_writes1[] = { |
| 9795 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 9796 | "Host: www.google.com\r\n" |
| 9797 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9798 | }; |
| 9799 | |
| 9800 | MockRead data_reads1[] = { |
| 9801 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9802 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9803 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9805 | }; |
| 9806 | |
| 9807 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9808 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9811 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9812 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9813 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9814 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9816 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9817 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9818 | |
| 9819 | rv = callback1.WaitForResult(); |
| 9820 | EXPECT_EQ(OK, rv); |
| 9821 | |
| 9822 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9823 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9824 | |
| 9825 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9826 | EXPECT_EQ(200, response->headers->response_code()); |
| 9827 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9828 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 9829 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9830 | |
| 9831 | LoadTimingInfo load_timing_info; |
| 9832 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9833 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9834 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9835 | } |
| 9836 | |
| 9837 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9838 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9839 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9840 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9841 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9842 | session_deps_.net_log = log.bound().net_log(); |
| 9843 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9844 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9845 | HttpRequestInfo request; |
| 9846 | request.method = "GET"; |
| 9847 | request.url = GURL("https://www.google.com/"); |
| 9848 | |
| 9849 | // Since we have proxy, should try to establish tunnel. |
| 9850 | MockWrite data_writes1[] = { |
| 9851 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9852 | "Host: www.google.com\r\n" |
| 9853 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9854 | |
| 9855 | MockWrite("GET / HTTP/1.1\r\n" |
| 9856 | "Host: www.google.com\r\n" |
| 9857 | "Connection: keep-alive\r\n\r\n"), |
| 9858 | }; |
| 9859 | |
| 9860 | MockRead data_reads1[] = { |
| 9861 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 9862 | |
| 9863 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9864 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9865 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9866 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9867 | }; |
| 9868 | |
| 9869 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9870 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9871 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9872 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9875 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9876 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9877 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9878 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9880 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9881 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9882 | |
| 9883 | rv = callback1.WaitForResult(); |
| 9884 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 9885 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9886 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9887 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9888 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9889 | NetLog::PHASE_NONE); |
| 9890 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9891 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9892 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9893 | NetLog::PHASE_NONE); |
| 9894 | |
| 9895 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9896 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9897 | |
| 9898 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9899 | EXPECT_EQ(200, response->headers->response_code()); |
| 9900 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9901 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9902 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9903 | |
| 9904 | LoadTimingInfo load_timing_info; |
| 9905 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9906 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9907 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9908 | } |
| 9909 | |
| 9910 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 9911 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9912 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9913 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9914 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9915 | session_deps_.net_log = log.bound().net_log(); |
| 9916 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9917 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9918 | HttpRequestInfo request; |
| 9919 | request.method = "GET"; |
| 9920 | request.url = GURL("https://www.google.com/"); |
| 9921 | |
| 9922 | // Since we have proxy, should try to establish tunnel. |
| 9923 | MockWrite data_writes1[] = { |
| 9924 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9925 | "Host: www.google.com\r\n" |
| 9926 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9927 | |
| 9928 | MockWrite("GET / HTTP/1.1\r\n" |
| 9929 | "Host: www.google.com\r\n" |
| 9930 | "Connection: keep-alive\r\n\r\n"), |
| 9931 | }; |
| 9932 | |
| 9933 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9934 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9935 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9936 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9937 | }; |
| 9938 | |
| 9939 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9940 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9942 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9943 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9945 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9946 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9947 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9948 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9950 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9952 | |
| 9953 | rv = callback1.WaitForResult(); |
| 9954 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 9955 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9956 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9957 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9958 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9959 | NetLog::PHASE_NONE); |
| 9960 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9961 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9962 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9963 | NetLog::PHASE_NONE); |
| 9964 | } |
| 9965 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9966 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9967 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9968 | scoped_ptr<SpdyFrame> req( |
| 9969 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9970 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 9971 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9972 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9973 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9974 | MockRead spdy_reads[] = { |
| 9975 | CreateMockRead(*resp), |
| 9976 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9977 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9978 | }; |
| 9979 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9980 | DelayedSocketData spdy_data( |
| 9981 | 1, // wait for one write to finish before reading. |
| 9982 | spdy_reads, arraysize(spdy_reads), |
| 9983 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9984 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9985 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9986 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9987 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9989 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9990 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9991 | |
| 9992 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9993 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9994 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 9995 | kPrivacyModeDisabled); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9996 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9997 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 9998 | |
| 9999 | HttpRequestInfo request; |
| 10000 | request.method = "GET"; |
| 10001 | request.url = GURL("https://www.google.com/"); |
| 10002 | request.load_flags = 0; |
| 10003 | |
| 10004 | // This is the important line that marks this as a preconnect. |
| 10005 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10006 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10007 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10008 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10009 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10010 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10011 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10012 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10013 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10014 | } |
| 10015 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10016 | // Given a net error, cause that error to be returned from the first Write() |
| 10017 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10018 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10020 | net::HttpRequestInfo request_info; |
| 10021 | request_info.url = GURL("https://www.example.com/"); |
| 10022 | request_info.method = "GET"; |
| 10023 | request_info.load_flags = net::LOAD_NORMAL; |
| 10024 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10025 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10026 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10027 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10028 | }; |
| 10029 | net::StaticSocketDataProvider data(NULL, 0, |
| 10030 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10033 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10034 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10035 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10038 | TestCompletionCallback callback; |
| 10039 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10040 | if (rv == net::ERR_IO_PENDING) |
| 10041 | rv = callback.WaitForResult(); |
| 10042 | ASSERT_EQ(error, rv); |
| 10043 | } |
| 10044 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10045 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10046 | // Just check a grab bag of cert errors. |
| 10047 | static const int kErrors[] = { |
| 10048 | ERR_CERT_COMMON_NAME_INVALID, |
| 10049 | ERR_CERT_AUTHORITY_INVALID, |
| 10050 | ERR_CERT_DATE_INVALID, |
| 10051 | }; |
| 10052 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10053 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10054 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10055 | } |
| 10056 | } |
| 10057 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10058 | // Ensure that a client certificate is removed from the SSL client auth |
| 10059 | // cache when: |
| 10060 | // 1) No proxy is involved. |
| 10061 | // 2) TLS False Start is disabled. |
| 10062 | // 3) The initial TLS handshake requests a client certificate. |
| 10063 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10064 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10065 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10066 | net::HttpRequestInfo request_info; |
| 10067 | request_info.url = GURL("https://www.example.com/"); |
| 10068 | request_info.method = "GET"; |
| 10069 | request_info.load_flags = net::LOAD_NORMAL; |
| 10070 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10071 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10072 | cert_request->host_and_port = "www.example.com:443"; |
| 10073 | |
| 10074 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10075 | // CertificateRequest is received for the first time, the handshake will |
| 10076 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10077 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10078 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10080 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10081 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10082 | |
| 10083 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10084 | // False Start is not being used, the result of the SSL handshake will be |
| 10085 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10086 | // matches the result of a server sending a handshake_failure alert, |
| 10087 | // rather than a Finished message, because it requires a client |
| 10088 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10089 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10090 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10092 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10093 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10094 | |
| 10095 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10096 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10097 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10098 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10099 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10100 | // requiring a client certificate, this fallback handshake should also |
| 10101 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10102 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10103 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10104 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10105 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10106 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10107 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10108 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10109 | // connection to a server fails during an SSL handshake, |
| 10110 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10111 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10112 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10113 | // requiring a client certificate, this fallback handshake should also |
| 10114 | // fail. |
| 10115 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10116 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10118 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10119 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10120 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10121 | // Need one more if TLSv1.2 is enabled. |
| 10122 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10123 | ssl_data5.cert_request_info = cert_request.get(); |
| 10124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10125 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10126 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10127 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10128 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10129 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10131 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10132 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10133 | TestCompletionCallback callback; |
| 10134 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10135 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10136 | |
| 10137 | // Complete the SSL handshake, which should abort due to requiring a |
| 10138 | // client certificate. |
| 10139 | rv = callback.WaitForResult(); |
| 10140 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10141 | |
| 10142 | // Indicate that no certificate should be supplied. From the perspective |
| 10143 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10144 | // certificate, so this is the same as supply a |
| 10145 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10146 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10147 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10148 | |
| 10149 | // Ensure the certificate was added to the client auth cache before |
| 10150 | // allowing the connection to continue restarting. |
| 10151 | scoped_refptr<X509Certificate> client_cert; |
| 10152 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10153 | &client_cert)); |
| 10154 | ASSERT_EQ(NULL, client_cert.get()); |
| 10155 | |
| 10156 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10157 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10158 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10159 | rv = callback.WaitForResult(); |
| 10160 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10161 | |
| 10162 | // Ensure that the client certificate is removed from the cache on a |
| 10163 | // handshake failure. |
| 10164 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10165 | &client_cert)); |
| 10166 | } |
| 10167 | |
| 10168 | // Ensure that a client certificate is removed from the SSL client auth |
| 10169 | // cache when: |
| 10170 | // 1) No proxy is involved. |
| 10171 | // 2) TLS False Start is enabled. |
| 10172 | // 3) The initial TLS handshake requests a client certificate. |
| 10173 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10174 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10175 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10176 | net::HttpRequestInfo request_info; |
| 10177 | request_info.url = GURL("https://www.example.com/"); |
| 10178 | request_info.method = "GET"; |
| 10179 | request_info.load_flags = net::LOAD_NORMAL; |
| 10180 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10181 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10182 | cert_request->host_and_port = "www.example.com:443"; |
| 10183 | |
| 10184 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 10185 | // return successfully after reading up to the peer's Certificate message. |
| 10186 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 10187 | // enqueue application data to be sent in the same packet as the |
| 10188 | // ChangeCipherSpec and Finished messages. |
| 10189 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 10190 | // called, which expects to process the peer's ChangeCipherSpec and |
| 10191 | // Finished messages. If there was an error negotiating with the peer, |
| 10192 | // such as due to the peer requiring a client certificate when none was |
| 10193 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 10194 | // called. |
| 10195 | |
| 10196 | // Like the non-False Start case, when a client certificate is requested by |
| 10197 | // the peer, the handshake is aborted during the Connect() call. |
| 10198 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10199 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10200 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10202 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10203 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10204 | |
| 10205 | // When a client certificate is supplied, Connect() will not be aborted |
| 10206 | // when the peer requests the certificate. Instead, the handshake will |
| 10207 | // artificially succeed, allowing the caller to write the HTTP request to |
| 10208 | // the socket. The handshake messages are not processed until Read() is |
| 10209 | // called, which then detects that the handshake was aborted, due to the |
| 10210 | // peer sending a handshake_failure because it requires a client |
| 10211 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10212 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10213 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10215 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10216 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10217 | }; |
| 10218 | net::StaticSocketDataProvider data2( |
| 10219 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10220 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10221 | |
| 10222 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10223 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 10224 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10225 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10226 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10228 | net::StaticSocketDataProvider data3( |
| 10229 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10230 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10231 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10232 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 10233 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 10234 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 10235 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10237 | net::StaticSocketDataProvider data4( |
| 10238 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10239 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10240 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10241 | // Need one more if TLSv1.2 is enabled. |
| 10242 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 10243 | ssl_data5.cert_request_info = cert_request.get(); |
| 10244 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10245 | net::StaticSocketDataProvider data5( |
| 10246 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 10247 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10248 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10249 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10250 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10252 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10253 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10254 | TestCompletionCallback callback; |
| 10255 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10256 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10257 | |
| 10258 | // Complete the SSL handshake, which should abort due to requiring a |
| 10259 | // client certificate. |
| 10260 | rv = callback.WaitForResult(); |
| 10261 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10262 | |
| 10263 | // Indicate that no certificate should be supplied. From the perspective |
| 10264 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10265 | // certificate, so this is the same as supply a |
| 10266 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10267 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10268 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10269 | |
| 10270 | // Ensure the certificate was added to the client auth cache before |
| 10271 | // allowing the connection to continue restarting. |
| 10272 | scoped_refptr<X509Certificate> client_cert; |
| 10273 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10274 | &client_cert)); |
| 10275 | ASSERT_EQ(NULL, client_cert.get()); |
| 10276 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10277 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10278 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10279 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10280 | rv = callback.WaitForResult(); |
| 10281 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10282 | |
| 10283 | // Ensure that the client certificate is removed from the cache on a |
| 10284 | // handshake failure. |
| 10285 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10286 | &client_cert)); |
| 10287 | } |
| 10288 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10289 | // Ensure that a client certificate is removed from the SSL client auth |
| 10290 | // cache when: |
| 10291 | // 1) An HTTPS proxy is involved. |
| 10292 | // 3) The HTTPS proxy requests a client certificate. |
| 10293 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 10294 | // proxy. |
| 10295 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 10296 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10297 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10298 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10299 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10300 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10301 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10302 | |
| 10303 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10304 | cert_request->host_and_port = "proxy:70"; |
| 10305 | |
| 10306 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 10307 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 10308 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 10309 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10310 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10311 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10313 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10315 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10316 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10317 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10319 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10320 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10321 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10322 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 10323 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10324 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10325 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10326 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10327 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10328 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10329 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10330 | |
| 10331 | net::HttpRequestInfo requests[2]; |
| 10332 | requests[0].url = GURL("https://www.example.com/"); |
| 10333 | requests[0].method = "GET"; |
| 10334 | requests[0].load_flags = net::LOAD_NORMAL; |
| 10335 | |
| 10336 | requests[1].url = GURL("http://www.example.com/"); |
| 10337 | requests[1].method = "GET"; |
| 10338 | requests[1].load_flags = net::LOAD_NORMAL; |
| 10339 | |
| 10340 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10341 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 10342 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10343 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10345 | |
| 10346 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10347 | TestCompletionCallback callback; |
| 10348 | int rv = trans->Start( |
| 10349 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10350 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10351 | |
| 10352 | // Complete the SSL handshake, which should abort due to requiring a |
| 10353 | // client certificate. |
| 10354 | rv = callback.WaitForResult(); |
| 10355 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10356 | |
| 10357 | // Indicate that no certificate should be supplied. From the perspective |
| 10358 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10359 | // certificate, so this is the same as supply a |
| 10360 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10361 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10362 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10363 | |
| 10364 | // Ensure the certificate was added to the client auth cache before |
| 10365 | // allowing the connection to continue restarting. |
| 10366 | scoped_refptr<X509Certificate> client_cert; |
| 10367 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("proxy:70", |
| 10368 | &client_cert)); |
| 10369 | ASSERT_EQ(NULL, client_cert.get()); |
| 10370 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 10371 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
| 10372 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10373 | &client_cert)); |
| 10374 | |
| 10375 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 10376 | // then consume ssl_data3, which should also fail. The result code is |
| 10377 | // checked against what ssl_data3 should return. |
| 10378 | rv = callback.WaitForResult(); |
| 10379 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 10380 | |
| 10381 | // Now that the new handshake has failed, ensure that the client |
| 10382 | // certificate was removed from the client auth cache. |
| 10383 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", |
| 10384 | &client_cert)); |
| 10385 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10386 | &client_cert)); |
| 10387 | } |
| 10388 | } |
| 10389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10390 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 10391 | // TEST_P is a macro that expands directly to code that stringizes the |
| 10392 | // arguments. As a result, macros passed as parameters (such as prefix |
| 10393 | // or test_case_name) will not be expanded by the preprocessor. To |
| 10394 | // work around this, indirect the macro for TEST_P, so that the |
| 10395 | // pre-processor will expand macros such as MAYBE_test_name before |
| 10396 | // instantiating the test. |
| 10397 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 10398 | TEST_P(test_case_name, test_name) |
| 10399 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10400 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10401 | #if defined(OS_WIN) |
| 10402 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 10403 | #else |
| 10404 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 10405 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10406 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10407 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 10408 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10409 | |
| 10410 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10411 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10412 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10413 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10414 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10415 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10416 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10417 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10419 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10420 | scoped_ptr<SpdyFrame> host1_req( |
| 10421 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10422 | scoped_ptr<SpdyFrame> host2_req( |
| 10423 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10424 | MockWrite spdy_writes[] = { |
| 10425 | CreateMockWrite(*host1_req, 1), |
| 10426 | CreateMockWrite(*host2_req, 4), |
| 10427 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10428 | scoped_ptr<SpdyFrame> host1_resp( |
| 10429 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10430 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10431 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10432 | scoped_ptr<SpdyFrame> host2_resp( |
| 10433 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10434 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10435 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10436 | MockRead spdy_reads[] = { |
| 10437 | CreateMockRead(*host1_resp, 2), |
| 10438 | CreateMockRead(*host1_resp_body, 3), |
| 10439 | CreateMockRead(*host2_resp, 5), |
| 10440 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10441 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10442 | }; |
| 10443 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10444 | IPAddressNumber ip; |
| 10445 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10446 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10447 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10448 | OrderedSocketData spdy_data( |
| 10449 | connect, |
| 10450 | spdy_reads, arraysize(spdy_reads), |
| 10451 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10452 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10453 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10454 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10455 | HttpRequestInfo request1; |
| 10456 | request1.method = "GET"; |
| 10457 | request1.url = GURL("https://www.google.com/"); |
| 10458 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10459 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10461 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10463 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10464 | |
| 10465 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10466 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10467 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10468 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10469 | |
| 10470 | std::string response_data; |
| 10471 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10472 | EXPECT_EQ("hello!", response_data); |
| 10473 | |
| 10474 | // Preload www.gmail.com into HostCache. |
| 10475 | HostPortPair host_port("www.gmail.com", 443); |
| 10476 | HostResolver::RequestInfo resolve_info(host_port); |
| 10477 | AddressList ignored; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10478 | rv = session_deps_.host_resolver->Resolve(resolve_info, &ignored, |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 10479 | callback.callback(), NULL, |
| 10480 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10482 | rv = callback.WaitForResult(); |
| 10483 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10484 | |
| 10485 | HttpRequestInfo request2; |
| 10486 | request2.method = "GET"; |
| 10487 | request2.url = GURL("https://www.gmail.com/"); |
| 10488 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10489 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10491 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10493 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10494 | |
| 10495 | response = trans2.GetResponseInfo(); |
| 10496 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10497 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10498 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10499 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10500 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10501 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10502 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10503 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10504 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10506 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10507 | HttpStreamFactory::set_use_alternate_protocols(true); |
| 10508 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
| 10509 | |
| 10510 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10512 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10513 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10514 | pool_peer.DisableDomainAuthenticationVerification(); |
| 10515 | |
| 10516 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10517 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10519 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10520 | scoped_ptr<SpdyFrame> host1_req( |
| 10521 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10522 | scoped_ptr<SpdyFrame> host2_req( |
| 10523 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10524 | MockWrite spdy_writes[] = { |
| 10525 | CreateMockWrite(*host1_req, 1), |
| 10526 | CreateMockWrite(*host2_req, 4), |
| 10527 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10528 | scoped_ptr<SpdyFrame> host1_resp( |
| 10529 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10530 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10531 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10532 | scoped_ptr<SpdyFrame> host2_resp( |
| 10533 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10534 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10535 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10536 | MockRead spdy_reads[] = { |
| 10537 | CreateMockRead(*host1_resp, 2), |
| 10538 | CreateMockRead(*host1_resp_body, 3), |
| 10539 | CreateMockRead(*host2_resp, 5), |
| 10540 | CreateMockRead(*host2_resp_body, 6), |
| 10541 | MockRead(ASYNC, 0, 7), |
| 10542 | }; |
| 10543 | |
| 10544 | IPAddressNumber ip; |
| 10545 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10546 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10547 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10548 | OrderedSocketData spdy_data( |
| 10549 | connect, |
| 10550 | spdy_reads, arraysize(spdy_reads), |
| 10551 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10552 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10553 | |
| 10554 | TestCompletionCallback callback; |
| 10555 | HttpRequestInfo request1; |
| 10556 | request1.method = "GET"; |
| 10557 | request1.url = GURL("https://www.google.com/"); |
| 10558 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10559 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10560 | |
| 10561 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 10562 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10563 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10564 | |
| 10565 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10566 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10567 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10568 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10569 | |
| 10570 | std::string response_data; |
| 10571 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10572 | EXPECT_EQ("hello!", response_data); |
| 10573 | |
| 10574 | HttpRequestInfo request2; |
| 10575 | request2.method = "GET"; |
| 10576 | request2.url = GURL("https://www.gmail.com/"); |
| 10577 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10578 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10579 | |
| 10580 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 10581 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10582 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10583 | |
| 10584 | response = trans2.GetResponseInfo(); |
| 10585 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10586 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10587 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10588 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10589 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10590 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10591 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10592 | } |
| 10593 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10594 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 10595 | public: |
| 10596 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 10597 | : host_port_(host_port) {} |
| 10598 | virtual ~OneTimeCachingHostResolver() {} |
| 10599 | |
| 10600 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 10601 | |
| 10602 | // HostResolver methods: |
| 10603 | virtual int Resolve(const RequestInfo& info, |
| 10604 | AddressList* addresses, |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10605 | const CompletionCallback& callback, |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10606 | RequestHandle* out_req, |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10607 | const BoundNetLog& net_log) OVERRIDE { |
| 10608 | return host_resolver_.Resolve( |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10609 | info, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10610 | } |
| 10611 | |
| 10612 | virtual int ResolveFromCache(const RequestInfo& info, |
| 10613 | AddressList* addresses, |
| 10614 | const BoundNetLog& net_log) OVERRIDE { |
| 10615 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 10616 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 10617 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10618 | return rv; |
| 10619 | } |
| 10620 | |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10621 | virtual void CancelRequest(RequestHandle req) OVERRIDE { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10622 | host_resolver_.CancelRequest(req); |
| 10623 | } |
| 10624 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 10625 | MockCachingHostResolver* GetMockHostResolver() { |
| 10626 | return &host_resolver_; |
| 10627 | } |
| 10628 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10629 | private: |
| 10630 | MockCachingHostResolver host_resolver_; |
| 10631 | const HostPortPair host_port_; |
| 10632 | }; |
| 10633 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10634 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10635 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 10637 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10638 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10639 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 10640 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10641 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10642 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 10643 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10644 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 10645 | // prefix doesn't work with parametrized tests). |
| 10646 | #if defined(OS_WIN) |
| 10647 | return; |
| 10648 | #endif |
| 10649 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10650 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 10651 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10652 | |
| 10653 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10654 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 10655 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10656 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10657 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10658 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10659 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10660 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10661 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10662 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10663 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10665 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10666 | scoped_ptr<SpdyFrame> host1_req( |
| 10667 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10668 | scoped_ptr<SpdyFrame> host2_req( |
| 10669 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10670 | MockWrite spdy_writes[] = { |
| 10671 | CreateMockWrite(*host1_req, 1), |
| 10672 | CreateMockWrite(*host2_req, 4), |
| 10673 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10674 | scoped_ptr<SpdyFrame> host1_resp( |
| 10675 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10676 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10677 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10678 | scoped_ptr<SpdyFrame> host2_resp( |
| 10679 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10680 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10681 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10682 | MockRead spdy_reads[] = { |
| 10683 | CreateMockRead(*host1_resp, 2), |
| 10684 | CreateMockRead(*host1_resp_body, 3), |
| 10685 | CreateMockRead(*host2_resp, 5), |
| 10686 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10687 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10688 | }; |
| 10689 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10690 | IPAddressNumber ip; |
| 10691 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10692 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10693 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10694 | OrderedSocketData spdy_data( |
| 10695 | connect, |
| 10696 | spdy_reads, arraysize(spdy_reads), |
| 10697 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10698 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10699 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10700 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10701 | HttpRequestInfo request1; |
| 10702 | request1.method = "GET"; |
| 10703 | request1.url = GURL("https://www.google.com/"); |
| 10704 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10705 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10707 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10708 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10709 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10710 | |
| 10711 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10712 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10713 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10714 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10715 | |
| 10716 | std::string response_data; |
| 10717 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10718 | EXPECT_EQ("hello!", response_data); |
| 10719 | |
| 10720 | // Preload cache entries into HostCache. |
| 10721 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
| 10722 | AddressList ignored; |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 10723 | rv = host_resolver.Resolve(resolve_info, &ignored, callback.callback(), |
| 10724 | NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10725 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10726 | rv = callback.WaitForResult(); |
| 10727 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10728 | |
| 10729 | HttpRequestInfo request2; |
| 10730 | request2.method = "GET"; |
| 10731 | request2.url = GURL("https://www.gmail.com/"); |
| 10732 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10733 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10735 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10736 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10737 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10738 | |
| 10739 | response = trans2.GetResponseInfo(); |
| 10740 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10741 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10742 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10743 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10744 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10745 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10746 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10747 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10748 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10749 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10750 | TEST_P(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10751 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10752 | MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10753 | }; |
| 10754 | MockRead data_reads2[] = { |
| 10755 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10756 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10758 | }; |
| 10759 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); |
| 10760 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); |
| 10761 | StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 10762 | |
| 10763 | SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 10764 | |
| 10765 | EXPECT_EQ(OK, out.rv); |
| 10766 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 10767 | EXPECT_EQ("hello world", out.response_data); |
| 10768 | } |
| 10769 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10770 | TEST_P(HttpNetworkTransactionTest, SendPipelineEvictionFallback) { |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10771 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10772 | MockWrite(SYNCHRONOUS, ERR_PIPELINE_EVICTION), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10773 | }; |
| 10774 | MockWrite data_writes2[] = { |
| 10775 | MockWrite("GET / HTTP/1.1\r\n" |
| 10776 | "Host: www.google.com\r\n" |
| 10777 | "Connection: keep-alive\r\n\r\n"), |
| 10778 | }; |
| 10779 | MockRead data_reads2[] = { |
| 10780 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10781 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10783 | }; |
| 10784 | StaticSocketDataProvider data1(NULL, 0, |
| 10785 | data_writes1, arraysize(data_writes1)); |
| 10786 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10787 | data_writes2, arraysize(data_writes2)); |
| 10788 | StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 10789 | |
| 10790 | SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 10791 | |
| 10792 | EXPECT_EQ(OK, out.rv); |
| 10793 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 10794 | EXPECT_EQ("hello world", out.response_data); |
| 10795 | } |
| 10796 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10797 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10798 | const std::string https_url = "https://www.google.com/"; |
| 10799 | const std::string http_url = "http://www.google.com:443/"; |
| 10800 | |
| 10801 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10802 | scoped_ptr<SpdyFrame> req1( |
| 10803 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10804 | |
| 10805 | MockWrite writes1[] = { |
| 10806 | CreateMockWrite(*req1, 0), |
| 10807 | }; |
| 10808 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10809 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10810 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10811 | MockRead reads1[] = { |
| 10812 | CreateMockRead(*resp1, 1), |
| 10813 | CreateMockRead(*body1, 2), |
| 10814 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 10815 | }; |
| 10816 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10817 | DelayedSocketData data1( |
| 10818 | 1, reads1, arraysize(reads1), |
| 10819 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10820 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10821 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10822 | |
| 10823 | // HTTP GET for the HTTP URL |
| 10824 | MockWrite writes2[] = { |
| 10825 | MockWrite(ASYNC, 4, |
| 10826 | "GET / HTTP/1.1\r\n" |
| 10827 | "Host: www.google.com:443\r\n" |
| 10828 | "Connection: keep-alive\r\n\r\n"), |
| 10829 | }; |
| 10830 | |
| 10831 | MockRead reads2[] = { |
| 10832 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 10833 | MockRead(ASYNC, 6, "hello"), |
| 10834 | MockRead(ASYNC, 7, OK), |
| 10835 | }; |
| 10836 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10837 | DelayedSocketData data2( |
| 10838 | 1, reads2, arraysize(reads2), |
| 10839 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10840 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10841 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10842 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10844 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10845 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10846 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10847 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10848 | |
| 10849 | // Start the first transaction to set up the SpdySession |
| 10850 | HttpRequestInfo request1; |
| 10851 | request1.method = "GET"; |
| 10852 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10853 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10854 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10855 | TestCompletionCallback callback1; |
| 10856 | EXPECT_EQ(ERR_IO_PENDING, |
| 10857 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10858 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10859 | |
| 10860 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10861 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 10862 | |
| 10863 | // Now, start the HTTP request |
| 10864 | HttpRequestInfo request2; |
| 10865 | request2.method = "GET"; |
| 10866 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10867 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10868 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10869 | TestCompletionCallback callback2; |
| 10870 | EXPECT_EQ(ERR_IO_PENDING, |
| 10871 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10872 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10873 | |
| 10874 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10875 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 10876 | } |
| 10877 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10878 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10879 | const std::string https_url = "https://www.google.com/"; |
| 10880 | const std::string http_url = "http://www.google.com:443/"; |
| 10881 | |
| 10882 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 10883 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10884 | scoped_ptr<SpdyFrame> req1( |
| 10885 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10886 | |
| 10887 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10888 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 10889 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10890 | const char* const headers[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10891 | spdy_util_.GetMethodKey(), "GET", |
| 10892 | spdy_util_.GetPathKey(), spdy_util_.is_spdy2() ? http_url.c_str() : "/", |
| 10893 | spdy_util_.GetHostKey(), "www.google.com:443", |
| 10894 | spdy_util_.GetSchemeKey(), "http", |
| 10895 | spdy_util_.GetVersionKey(), "HTTP/1.1" |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10896 | }; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 10897 | scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyControlFrame( |
| 10898 | NULL, 0, false, 3, MEDIUM, SYN_STREAM, CONTROL_FLAG_FIN, |
| 10899 | headers, arraysize(headers), 0)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10900 | |
| 10901 | MockWrite writes1[] = { |
| 10902 | CreateMockWrite(*connect, 0), |
| 10903 | CreateMockWrite(*wrapped_req1, 2), |
| 10904 | CreateMockWrite(*req2, 5), |
| 10905 | }; |
| 10906 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10907 | scoped_ptr<SpdyFrame> conn_resp( |
| 10908 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10909 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10910 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10911 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 10912 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 10913 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 10914 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 10915 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10916 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10917 | MockRead reads1[] = { |
| 10918 | CreateMockRead(*conn_resp, 1), |
| 10919 | CreateMockRead(*wrapped_resp1, 3), |
| 10920 | CreateMockRead(*wrapped_body1, 4), |
| 10921 | CreateMockRead(*resp2, 6), |
| 10922 | CreateMockRead(*body2, 7), |
| 10923 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 10924 | }; |
| 10925 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10926 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 10927 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10928 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10929 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10930 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10931 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 10932 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 10933 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10934 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10935 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10936 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10937 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10938 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10939 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10940 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 10941 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10942 | |
| 10943 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10944 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10945 | |
| 10946 | // Start the first transaction to set up the SpdySession |
| 10947 | HttpRequestInfo request1; |
| 10948 | request1.method = "GET"; |
| 10949 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10950 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10951 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10952 | TestCompletionCallback callback1; |
| 10953 | EXPECT_EQ(ERR_IO_PENDING, |
| 10954 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10955 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10956 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10957 | |
| 10958 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10959 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 10960 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 10961 | LoadTimingInfo load_timing_info1; |
| 10962 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 10963 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 10964 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10965 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10966 | // Now, start the HTTP request |
| 10967 | HttpRequestInfo request2; |
| 10968 | request2.method = "GET"; |
| 10969 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10970 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10971 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10972 | TestCompletionCallback callback2; |
| 10973 | EXPECT_EQ(ERR_IO_PENDING, |
| 10974 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10975 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10976 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10977 | |
| 10978 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10979 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 10980 | |
| 10981 | LoadTimingInfo load_timing_info2; |
| 10982 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 10983 | // The established SPDY sessions is considered reused by the HTTP request. |
| 10984 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 10985 | // HTTP requests over a SPDY session should have a different connection |
| 10986 | // socket_log_id than requests over a tunnel. |
| 10987 | 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] | 10988 | } |
| 10989 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10990 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10991 | HttpStreamFactory::set_force_spdy_always(true); |
| 10992 | const std::string https_url = "https://www.google.com/"; |
| 10993 | const std::string http_url = "http://www.google.com:443/"; |
| 10994 | |
| 10995 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10996 | scoped_ptr<SpdyFrame> req1( |
| 10997 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10998 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10999 | scoped_ptr<SpdyFrame> req2( |
| 11000 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11001 | |
| 11002 | MockWrite writes[] = { |
| 11003 | CreateMockWrite(*req1, 1), |
| 11004 | CreateMockWrite(*req2, 4), |
| 11005 | }; |
| 11006 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11007 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11008 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11009 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11010 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11011 | MockRead reads[] = { |
| 11012 | CreateMockRead(*resp1, 2), |
| 11013 | CreateMockRead(*body1, 3), |
| 11014 | CreateMockRead(*resp2, 5), |
| 11015 | CreateMockRead(*body2, 6), |
| 11016 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11017 | }; |
| 11018 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11019 | OrderedSocketData data(reads, arraysize(reads), |
| 11020 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11021 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11022 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11023 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11025 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11026 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11027 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11028 | |
| 11029 | // Start the first transaction to set up the SpdySession |
| 11030 | HttpRequestInfo request1; |
| 11031 | request1.method = "GET"; |
| 11032 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11033 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11034 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11035 | TestCompletionCallback callback1; |
| 11036 | EXPECT_EQ(ERR_IO_PENDING, |
| 11037 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11038 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11039 | |
| 11040 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11041 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11042 | |
| 11043 | // Now, start the HTTP request |
| 11044 | HttpRequestInfo request2; |
| 11045 | request2.method = "GET"; |
| 11046 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11047 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11048 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11049 | TestCompletionCallback callback2; |
| 11050 | EXPECT_EQ(ERR_IO_PENDING, |
| 11051 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11052 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11053 | |
| 11054 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11055 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11056 | } |
| 11057 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11058 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11059 | // that we do not pool other origins that resolve to the same IP when |
| 11060 | // the certificate does not match the new origin. |
| 11061 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11062 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11063 | const std::string url1 = "http://www.google.com/"; |
| 11064 | const std::string url2 = "https://mail.google.com/"; |
| 11065 | const std::string ip_addr = "1.2.3.4"; |
| 11066 | |
| 11067 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11068 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11069 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 11070 | scoped_ptr<SpdyFrame> req1(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11071 | headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11072 | |
| 11073 | MockWrite writes1[] = { |
| 11074 | CreateMockWrite(*req1, 0), |
| 11075 | }; |
| 11076 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11077 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11078 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11079 | MockRead reads1[] = { |
| 11080 | CreateMockRead(*resp1, 1), |
| 11081 | CreateMockRead(*body1, 2), |
| 11082 | MockRead(ASYNC, OK, 3) // EOF |
| 11083 | }; |
| 11084 | |
| 11085 | scoped_ptr<DeterministicSocketData> data1( |
| 11086 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11087 | writes1, arraysize(writes1))); |
| 11088 | IPAddressNumber ip; |
| 11089 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11090 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11091 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11092 | data1->set_connect_data(connect_data1); |
| 11093 | |
| 11094 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11095 | scoped_ptr<SpdyFrame> req2( |
| 11096 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11097 | |
| 11098 | MockWrite writes2[] = { |
| 11099 | CreateMockWrite(*req2, 0), |
| 11100 | }; |
| 11101 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11102 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11103 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11104 | MockRead reads2[] = { |
| 11105 | CreateMockRead(*resp2, 1), |
| 11106 | CreateMockRead(*body2, 2), |
| 11107 | MockRead(ASYNC, OK, 3) // EOF |
| 11108 | }; |
| 11109 | |
| 11110 | scoped_ptr<DeterministicSocketData> data2( |
| 11111 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11112 | writes2, arraysize(writes2))); |
| 11113 | MockConnect connect_data2(ASYNC, OK); |
| 11114 | data2->set_connect_data(connect_data2); |
| 11115 | |
| 11116 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11117 | // all others direct. |
| 11118 | ProxyConfig proxy_config; |
| 11119 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11120 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11121 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11122 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11123 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11124 | NULL)); |
| 11125 | |
| 11126 | // Load a valid cert. Note, that this does not need to |
| 11127 | // be valid for proxy because the MockSSLClientSocket does |
| 11128 | // not actually verify it. But SpdySession will use this |
| 11129 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11130 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11131 | scoped_refptr<X509Certificate> server_cert( |
| 11132 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
| 11133 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 11134 | |
| 11135 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11136 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11137 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11138 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11139 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11140 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11141 | |
| 11142 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11143 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11144 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11145 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11146 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11147 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11148 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11149 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11150 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11151 | |
| 11152 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11153 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11154 | |
| 11155 | // Start the first transaction to set up the SpdySession |
| 11156 | HttpRequestInfo request1; |
| 11157 | request1.method = "GET"; |
| 11158 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11159 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11160 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11161 | TestCompletionCallback callback1; |
| 11162 | ASSERT_EQ(ERR_IO_PENDING, |
| 11163 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11164 | data1->RunFor(3); |
| 11165 | |
| 11166 | ASSERT_TRUE(callback1.have_result()); |
| 11167 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11168 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11169 | |
| 11170 | // Now, start the HTTP request |
| 11171 | HttpRequestInfo request2; |
| 11172 | request2.method = "GET"; |
| 11173 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11174 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11175 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11176 | TestCompletionCallback callback2; |
| 11177 | EXPECT_EQ(ERR_IO_PENDING, |
| 11178 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11179 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11180 | data2->RunFor(3); |
| 11181 | |
| 11182 | ASSERT_TRUE(callback2.have_result()); |
| 11183 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11184 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11185 | } |
| 11186 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11187 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11188 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11189 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11190 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11191 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11192 | const std::string https_url = "https://www.google.com/"; |
| 11193 | |
| 11194 | MockRead reads1[] = { |
| 11195 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11196 | }; |
| 11197 | |
| 11198 | scoped_ptr<DeterministicSocketData> data1( |
| 11199 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11200 | data1->SetStop(1); |
| 11201 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11202 | scoped_ptr<SpdyFrame> req2( |
| 11203 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11204 | MockWrite writes2[] = { |
| 11205 | CreateMockWrite(*req2, 0), |
| 11206 | }; |
| 11207 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11208 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11209 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11210 | MockRead reads2[] = { |
| 11211 | CreateMockRead(*resp2, 1), |
| 11212 | CreateMockRead(*body2, 2), |
| 11213 | MockRead(ASYNC, OK, 3) // EOF |
| 11214 | }; |
| 11215 | |
| 11216 | scoped_ptr<DeterministicSocketData> data2( |
| 11217 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11218 | writes2, arraysize(writes2))); |
| 11219 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11220 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11221 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11222 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11223 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11224 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11225 | |
| 11226 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11227 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11228 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11229 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11230 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11231 | |
| 11232 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11233 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11234 | |
| 11235 | // Start the first transaction to set up the SpdySession and verify that |
| 11236 | // connection was closed. |
| 11237 | HttpRequestInfo request1; |
| 11238 | request1.method = "GET"; |
| 11239 | request1.url = GURL(https_url); |
| 11240 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11241 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11242 | TestCompletionCallback callback1; |
| 11243 | EXPECT_EQ(ERR_IO_PENDING, |
| 11244 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11245 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11246 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11247 | |
| 11248 | // Now, start the second request and make sure it succeeds. |
| 11249 | HttpRequestInfo request2; |
| 11250 | request2.method = "GET"; |
| 11251 | request2.url = GURL(https_url); |
| 11252 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11253 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11254 | TestCompletionCallback callback2; |
| 11255 | EXPECT_EQ(ERR_IO_PENDING, |
| 11256 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11257 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11258 | data2->RunFor(3); |
| 11259 | |
| 11260 | ASSERT_TRUE(callback2.have_result()); |
| 11261 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11262 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11263 | } |
| 11264 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11265 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11266 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
| 11267 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 11268 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11269 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 11270 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11271 | |
| 11272 | // Use two different hosts with different IPs so they don't get pooled. |
| 11273 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 11274 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 11275 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11276 | |
| 11277 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11278 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11279 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11280 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11283 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11284 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11285 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 11286 | MockWrite spdy1_writes[] = { |
| 11287 | CreateMockWrite(*host1_req, 1), |
| 11288 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11289 | scoped_ptr<SpdyFrame> host1_resp( |
| 11290 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11291 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11292 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11293 | MockRead spdy1_reads[] = { |
| 11294 | CreateMockRead(*host1_resp, 2), |
| 11295 | CreateMockRead(*host1_resp_body, 3), |
| 11296 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11297 | }; |
| 11298 | |
| 11299 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 11300 | new OrderedSocketData( |
| 11301 | spdy1_reads, arraysize(spdy1_reads), |
| 11302 | spdy1_writes, arraysize(spdy1_writes))); |
| 11303 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 11304 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11305 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11306 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 11307 | MockWrite spdy2_writes[] = { |
| 11308 | CreateMockWrite(*host2_req, 1), |
| 11309 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11310 | scoped_ptr<SpdyFrame> host2_resp( |
| 11311 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11312 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11313 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11314 | MockRead spdy2_reads[] = { |
| 11315 | CreateMockRead(*host2_resp, 2), |
| 11316 | CreateMockRead(*host2_resp_body, 3), |
| 11317 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11318 | }; |
| 11319 | |
| 11320 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 11321 | new OrderedSocketData( |
| 11322 | spdy2_reads, arraysize(spdy2_reads), |
| 11323 | spdy2_writes, arraysize(spdy2_writes))); |
| 11324 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 11325 | |
| 11326 | MockWrite http_write[] = { |
| 11327 | MockWrite("GET / HTTP/1.1\r\n" |
| 11328 | "Host: www.a.com\r\n" |
| 11329 | "Connection: keep-alive\r\n\r\n"), |
| 11330 | }; |
| 11331 | |
| 11332 | MockRead http_read[] = { |
| 11333 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11335 | MockRead("Content-Length: 6\r\n\r\n"), |
| 11336 | MockRead("hello!"), |
| 11337 | }; |
| 11338 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 11339 | http_write, arraysize(http_write)); |
| 11340 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11341 | |
| 11342 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11343 | SpdySessionKey spdy_session_key_a( |
| 11344 | host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11345 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11346 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11347 | |
| 11348 | TestCompletionCallback callback; |
| 11349 | HttpRequestInfo request1; |
| 11350 | request1.method = "GET"; |
| 11351 | request1.url = GURL("https://www.a.com/"); |
| 11352 | request1.load_flags = 0; |
| 11353 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11355 | |
| 11356 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 11357 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11358 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11359 | |
| 11360 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11361 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11362 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11363 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11364 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11365 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11366 | |
| 11367 | std::string response_data; |
| 11368 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11369 | EXPECT_EQ("hello!", response_data); |
| 11370 | trans.reset(); |
| 11371 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11372 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11373 | |
| 11374 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11375 | SpdySessionKey spdy_session_key_b( |
| 11376 | host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11377 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11378 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11379 | HttpRequestInfo request2; |
| 11380 | request2.method = "GET"; |
| 11381 | request2.url = GURL("https://www.b.com/"); |
| 11382 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11383 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11384 | |
| 11385 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 11386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11387 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11388 | |
| 11389 | response = trans->GetResponseInfo(); |
| 11390 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11391 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11392 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11393 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11394 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11395 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11396 | EXPECT_EQ("hello!", response_data); |
| 11397 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11398 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11399 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11400 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11401 | |
| 11402 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11403 | SpdySessionKey spdy_session_key_a1( |
| 11404 | host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11405 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11406 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11407 | HttpRequestInfo request3; |
| 11408 | request3.method = "GET"; |
| 11409 | request3.url = GURL("http://www.a.com/"); |
| 11410 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11411 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11412 | |
| 11413 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 11414 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11415 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11416 | |
| 11417 | response = trans->GetResponseInfo(); |
| 11418 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11419 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11420 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11421 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11422 | EXPECT_FALSE(response->was_npn_negotiated); |
| 11423 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11424 | EXPECT_EQ("hello!", response_data); |
| 11425 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11426 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11427 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11428 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11429 | } |
| 11430 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11431 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 11432 | HttpRequestInfo request; |
| 11433 | request.method = "GET"; |
| 11434 | request.url = GURL("http://www.google.com/"); |
| 11435 | request.load_flags = 0; |
| 11436 | |
| 11437 | scoped_ptr<HttpTransaction> trans( |
| 11438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11439 | CreateSession(&session_deps_))); |
| 11440 | |
| 11441 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 11442 | StaticSocketDataProvider data; |
| 11443 | data.set_connect_data(mock_connect); |
| 11444 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11445 | |
| 11446 | TestCompletionCallback callback; |
| 11447 | |
| 11448 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11449 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11450 | |
| 11451 | rv = callback.WaitForResult(); |
| 11452 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11453 | |
| 11454 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11455 | |
| 11456 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11457 | HttpRequestHeaders request_headers; |
| 11458 | trans->GetFullRequestHeaders(&request_headers); |
| 11459 | } |
| 11460 | |
| 11461 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 11462 | HttpRequestInfo request; |
| 11463 | request.method = "GET"; |
| 11464 | request.url = GURL("http://www.google.com/"); |
| 11465 | request.load_flags = 0; |
| 11466 | |
| 11467 | scoped_ptr<HttpTransaction> trans( |
| 11468 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11469 | CreateSession(&session_deps_))); |
| 11470 | |
| 11471 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11472 | StaticSocketDataProvider data; |
| 11473 | data.set_connect_data(mock_connect); |
| 11474 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11475 | |
| 11476 | TestCompletionCallback callback; |
| 11477 | |
| 11478 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11479 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11480 | |
| 11481 | rv = callback.WaitForResult(); |
| 11482 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11483 | |
| 11484 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11485 | |
| 11486 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11487 | HttpRequestHeaders request_headers; |
| 11488 | trans->GetFullRequestHeaders(&request_headers); |
| 11489 | } |
| 11490 | |
| 11491 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 11492 | HttpRequestInfo request; |
| 11493 | request.method = "GET"; |
| 11494 | request.url = GURL("http://www.google.com/"); |
| 11495 | request.load_flags = 0; |
| 11496 | |
| 11497 | scoped_ptr<HttpTransaction> trans( |
| 11498 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11499 | CreateSession(&session_deps_))); |
| 11500 | |
| 11501 | MockWrite data_writes[] = { |
| 11502 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 11503 | }; |
| 11504 | MockRead data_reads[] = { |
| 11505 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 11506 | }; |
| 11507 | |
| 11508 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11509 | data_writes, arraysize(data_writes)); |
| 11510 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11511 | |
| 11512 | TestCompletionCallback callback; |
| 11513 | |
| 11514 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11516 | |
| 11517 | rv = callback.WaitForResult(); |
| 11518 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11519 | |
| 11520 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11521 | |
| 11522 | HttpRequestHeaders request_headers; |
| 11523 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11524 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11525 | } |
| 11526 | |
| 11527 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 11528 | HttpRequestInfo request; |
| 11529 | request.method = "GET"; |
| 11530 | request.url = GURL("http://www.google.com/"); |
| 11531 | request.load_flags = 0; |
| 11532 | |
| 11533 | scoped_ptr<HttpTransaction> trans( |
| 11534 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11535 | CreateSession(&session_deps_))); |
| 11536 | |
| 11537 | MockWrite data_writes[] = { |
| 11538 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 11539 | }; |
| 11540 | MockRead data_reads[] = { |
| 11541 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 11542 | }; |
| 11543 | |
| 11544 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11545 | data_writes, arraysize(data_writes)); |
| 11546 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11547 | |
| 11548 | TestCompletionCallback callback; |
| 11549 | |
| 11550 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11551 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11552 | |
| 11553 | rv = callback.WaitForResult(); |
| 11554 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11555 | |
| 11556 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11557 | |
| 11558 | HttpRequestHeaders request_headers; |
| 11559 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11560 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11561 | } |
| 11562 | |
| 11563 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 11564 | HttpRequestInfo request; |
| 11565 | request.method = "GET"; |
| 11566 | request.url = GURL("http://www.google.com/"); |
| 11567 | request.load_flags = 0; |
| 11568 | |
| 11569 | scoped_ptr<HttpTransaction> trans( |
| 11570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11571 | CreateSession(&session_deps_))); |
| 11572 | |
| 11573 | MockWrite data_writes[] = { |
| 11574 | MockWrite("GET / HTTP/1.1\r\n" |
| 11575 | "Host: www.google.com\r\n" |
| 11576 | "Connection: keep-alive\r\n\r\n"), |
| 11577 | }; |
| 11578 | MockRead data_reads[] = { |
| 11579 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 11580 | }; |
| 11581 | |
| 11582 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11583 | data_writes, arraysize(data_writes)); |
| 11584 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11585 | |
| 11586 | TestCompletionCallback callback; |
| 11587 | |
| 11588 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11589 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11590 | |
| 11591 | rv = callback.WaitForResult(); |
| 11592 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11593 | |
| 11594 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11595 | |
| 11596 | HttpRequestHeaders request_headers; |
| 11597 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11598 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11599 | } |
| 11600 | |
| 11601 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 11602 | HttpRequestInfo request; |
| 11603 | request.method = "GET"; |
| 11604 | request.url = GURL("http://www.google.com/"); |
| 11605 | request.load_flags = 0; |
| 11606 | |
| 11607 | scoped_ptr<HttpTransaction> trans( |
| 11608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11609 | CreateSession(&session_deps_))); |
| 11610 | |
| 11611 | MockWrite data_writes[] = { |
| 11612 | MockWrite("GET / HTTP/1.1\r\n" |
| 11613 | "Host: www.google.com\r\n" |
| 11614 | "Connection: keep-alive\r\n\r\n"), |
| 11615 | }; |
| 11616 | MockRead data_reads[] = { |
| 11617 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 11618 | }; |
| 11619 | |
| 11620 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11621 | data_writes, arraysize(data_writes)); |
| 11622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11623 | |
| 11624 | TestCompletionCallback callback; |
| 11625 | |
| 11626 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11627 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11628 | |
| 11629 | rv = callback.WaitForResult(); |
| 11630 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11631 | |
| 11632 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11633 | |
| 11634 | HttpRequestHeaders request_headers; |
| 11635 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11636 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11637 | } |
| 11638 | |
| 11639 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 11640 | HttpRequestInfo request; |
| 11641 | request.method = "GET"; |
| 11642 | request.url = GURL("http://www.google.com/"); |
| 11643 | request.load_flags = 0; |
| 11644 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 11645 | |
| 11646 | scoped_ptr<HttpTransaction> trans( |
| 11647 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11648 | CreateSession(&session_deps_))); |
| 11649 | |
| 11650 | MockWrite data_writes[] = { |
| 11651 | MockWrite("GET / HTTP/1.1\r\n" |
| 11652 | "Host: www.google.com\r\n" |
| 11653 | "Connection: keep-alive\r\n" |
| 11654 | "X-Foo: bar\r\n\r\n"), |
| 11655 | }; |
| 11656 | MockRead data_reads[] = { |
| 11657 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11658 | "Content-Length: 5\r\n\r\n" |
| 11659 | "hello"), |
| 11660 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 11661 | }; |
| 11662 | |
| 11663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11664 | data_writes, arraysize(data_writes)); |
| 11665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11666 | |
| 11667 | TestCompletionCallback callback; |
| 11668 | |
| 11669 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11671 | |
| 11672 | rv = callback.WaitForResult(); |
| 11673 | EXPECT_EQ(OK, rv); |
| 11674 | |
| 11675 | HttpRequestHeaders request_headers; |
| 11676 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11677 | std::string foo; |
| 11678 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 11679 | EXPECT_EQ("bar", foo); |
| 11680 | } |
| 11681 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 11682 | } // namespace net |