[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] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 18 | #include "base/memory/weak_ptr.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 19 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 21 | #include "base/test/test_file_util.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 22 | #include "net/base/auth.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 23 | #include "net/base/capturing_net_log.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 24 | #include "net/base/completion_callback.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 25 | #include "net/base/load_timing_info.h" |
| 26 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 27 | #include "net/base/net_log.h" |
| 28 | #include "net/base/net_log_unittest.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 29 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 30 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 31 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 32 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 33 | #include "net/base/upload_data_stream.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 34 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 35 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 36 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 37 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 38 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 39 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 40 | #include "net/http/http_auth_handler_ntlm.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 41 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 42 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 43 | #include "net/http/http_network_session_peer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 44 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 45 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 46 | #include "net/http/http_stream_factory.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 47 | #include "net/http/http_transaction_unittest.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 48 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 49 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 50 | #include "net/proxy/proxy_resolver.h" |
| 51 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 52 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 53 | #include "net/socket/client_socket_pool_manager.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 54 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 55 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 56 | #include "net/socket/socket_test_util.h" |
| 57 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 58 | #include "net/spdy/spdy_framer.h" |
| 59 | #include "net/spdy/spdy_session.h" |
| 60 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 61 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 62 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 64 | #include "net/ssl/ssl_config_service_defaults.h" |
| 65 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 66 | #include "net/test/cert_test_util.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 67 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 68 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 69 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 70 | |
| 71 | //----------------------------------------------------------------------------- |
| 72 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 73 | namespace { |
| 74 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 75 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 76 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 77 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 78 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 79 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 80 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 81 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 82 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 83 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 84 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 85 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 86 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 87 | |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 88 | int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { |
| 89 | return session->GetTransportSocketPool( |
| 90 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 91 | } |
| 92 | |
| 93 | int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { |
| 94 | return session->GetSSLSocketPool( |
| 95 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 96 | } |
| 97 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 98 | bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) { |
| 99 | return session->GetTransportSocketPool( |
| 100 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled(); |
| 101 | } |
| 102 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 103 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 104 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 105 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 106 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 107 | if (!params) |
| 108 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 109 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 110 | if (!params->GetList("headers", &header_list)) |
| 111 | return false; |
| 112 | std::string double_quote_headers; |
| 113 | base::JSONWriter::Write(header_list, &double_quote_headers); |
| 114 | ReplaceChars(double_quote_headers, "\"", "'", headers); |
| 115 | return true; |
| 116 | } |
| 117 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 118 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 119 | // used. |
| 120 | void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { |
| 121 | EXPECT_TRUE(load_timing_info.socket_reused); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 122 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 123 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 124 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 125 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 126 | |
| 127 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 128 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 129 | |
| 130 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 131 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 132 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 133 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 134 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 135 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 139 | // used. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 140 | void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, |
| 141 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 142 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 143 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 144 | |
| 145 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 146 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 147 | |
| 148 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 149 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 150 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 151 | load_timing_info.send_start); |
| 152 | |
| 153 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 154 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 157 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 158 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 162 | // used. |
| 163 | void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { |
| 164 | EXPECT_TRUE(load_timing_info.socket_reused); |
| 165 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 166 | |
| 167 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 168 | |
| 169 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 170 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 171 | load_timing_info.proxy_resolve_end); |
| 172 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 173 | load_timing_info.send_start); |
| 174 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 175 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 176 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 178 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 179 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 183 | // used. |
| 184 | void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, |
| 185 | int connect_timing_flags) { |
| 186 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 187 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 188 | |
| 189 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 191 | load_timing_info.proxy_resolve_end); |
| 192 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 193 | load_timing_info.connect_timing.connect_start); |
| 194 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 195 | connect_timing_flags); |
| 196 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 197 | load_timing_info.send_start); |
| 198 | |
| 199 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 201 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 203 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 204 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 207 | } // namespace |
| 208 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 209 | namespace net { |
| 210 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 211 | namespace { |
| 212 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 213 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 214 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 217 | } // namespace |
| 218 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 219 | class HttpNetworkTransactionTest |
| 220 | : public PlatformTest, |
| 221 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 222 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 223 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 224 | // Important to restore the per-pool limit first, since the pool limit must |
| 225 | // always be greater than group limit, and the tests reduce both limits. |
| 226 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 227 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 228 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 229 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 230 | } |
| 231 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 232 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 233 | HttpNetworkTransactionTest() |
| 234 | : spdy_util_(GetParam()), |
| 235 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 236 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 237 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 238 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 239 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 240 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 241 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 242 | struct SimpleGetHelperResult { |
| 243 | int rv; |
| 244 | std::string status_line; |
| 245 | std::string response_data; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 246 | LoadTimingInfo load_timing_info; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 247 | }; |
| 248 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 249 | virtual void SetUp() { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 250 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 251 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 254 | virtual void TearDown() { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 255 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 256 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 257 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 258 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 259 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 260 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 261 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 262 | HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 263 | HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 266 | // This is the expected return from a current server advertising SPDY. |
| 267 | std::string GetAlternateProtocolHttpHeader() { |
| 268 | return |
| 269 | std::string("Alternate-Protocol: 443:") + |
| 270 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())) + |
| 271 | "\r\n\r\n"; |
| 272 | } |
| 273 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 274 | // Either |write_failure| specifies a write failure or |read_failure| |
| 275 | // specifies a read failure when using a reused socket. In either case, the |
| 276 | // failure should cause the network transaction to resend the request, and the |
| 277 | // other argument should be NULL. |
| 278 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 279 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 280 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 281 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 282 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 283 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 284 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 285 | HttpRequestInfo request; |
| 286 | request.method = "GET"; |
| 287 | request.url = GURL("http://www.google.com/"); |
| 288 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 289 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 290 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 291 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 292 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 293 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 294 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 295 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 296 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 297 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 298 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 300 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 301 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 302 | EXPECT_TRUE(log.bound().IsLoggingAllEvents()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 303 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 304 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 305 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 306 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 307 | |
| 308 | // Even in the failure cases that use this function, connections are always |
| 309 | // successfully established before the error. |
| 310 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 311 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 312 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 313 | if (out.rv != OK) |
| 314 | return out; |
| 315 | |
| 316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 317 | // Can't use ASSERT_* inside helper functions like this, so |
| 318 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 319 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 320 | out.rv = ERR_UNEXPECTED; |
| 321 | return out; |
| 322 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | out.status_line = response->headers->GetStatusLine(); |
| 324 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 325 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 326 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 327 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 328 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 329 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 330 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 331 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 332 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 333 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 334 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 335 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 336 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 337 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 338 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 339 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 340 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 341 | std::string line; |
| 342 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 343 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 344 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 345 | HttpRequestHeaders request_headers; |
| 346 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 347 | std::string value; |
| 348 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 349 | EXPECT_EQ("www.google.com", value); |
| 350 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 351 | EXPECT_EQ("keep-alive", value); |
| 352 | |
| 353 | std::string response_headers; |
| 354 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 355 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 356 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 357 | |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 358 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 359 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 360 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 361 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 362 | size_t reads_count) { |
| 363 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 364 | StaticSocketDataProvider* data[] = { &reads }; |
| 365 | return SimpleGetHelperForData(data, 1); |
| 366 | } |
| 367 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 368 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 369 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 370 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 371 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 372 | |
| 373 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 374 | |
| 375 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 376 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 377 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 378 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 379 | |
| 380 | // Original socket limits. Some tests set these. Safest to always restore |
| 381 | // them once each test has been run. |
| 382 | int old_max_group_sockets_; |
| 383 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 384 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 385 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 386 | INSTANTIATE_TEST_CASE_P( |
| 387 | NextProto, |
| 388 | HttpNetworkTransactionTest, |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 389 | testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2, |
| 390 | kProtoHTTP2Draft04)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 391 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 392 | namespace { |
| 393 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 394 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 395 | void FillLargeHeadersString(std::string* str, int size) { |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 396 | const char* row = |
| 397 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 398 | const int sizeof_row = strlen(row); |
| 399 | const int num_rows = static_cast<int>( |
| 400 | ceil(static_cast<float>(size) / sizeof_row)); |
| 401 | const int sizeof_data = num_rows * sizeof_row; |
| 402 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 403 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 404 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 405 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 406 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 409 | // Alternative functions that eliminate randomness and dependency on the local |
| 410 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 411 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 412 | static const uint8 bytes[] = { |
| 413 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 414 | }; |
| 415 | static size_t current_byte = 0; |
| 416 | for (size_t i = 0; i < n; ++i) { |
| 417 | output[i] = bytes[current_byte++]; |
| 418 | current_byte %= arraysize(bytes); |
| 419 | } |
| 420 | } |
| 421 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 422 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 423 | static const uint8 bytes[] = { |
| 424 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 425 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 426 | }; |
| 427 | static size_t current_byte = 0; |
| 428 | for (size_t i = 0; i < n; ++i) { |
| 429 | output[i] = bytes[current_byte++]; |
| 430 | current_byte %= arraysize(bytes); |
| 431 | } |
| 432 | } |
| 433 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 434 | std::string MockGetHostName() { |
| 435 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 438 | template<typename ParentPool> |
| 439 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 440 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 441 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 442 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 443 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 444 | const std::string last_group_name_received() const { |
| 445 | return last_group_name_; |
| 446 | } |
| 447 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 448 | virtual int RequestSocket(const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 449 | const void* socket_params, |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 450 | RequestPriority priority, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 451 | ClientSocketHandle* handle, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 452 | const CompletionCallback& callback, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 453 | const BoundNetLog& net_log) { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 454 | last_group_name_ = group_name; |
| 455 | return ERR_IO_PENDING; |
| 456 | } |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 457 | virtual void CancelRequest(const std::string& group_name, |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 458 | ClientSocketHandle* handle) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 459 | virtual void ReleaseSocket(const std::string& group_name, |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 460 | scoped_ptr<StreamSocket> socket, |
[email protected] | 9f95c69 | 2011-02-11 19:20:19 | [diff] [blame] | 461 | int id) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 462 | virtual void CloseIdleSockets() {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 463 | virtual int IdleSocketCount() const { |
| 464 | return 0; |
| 465 | } |
| 466 | virtual int IdleSocketCountInGroup(const std::string& group_name) const { |
| 467 | return 0; |
| 468 | } |
| 469 | virtual LoadState GetLoadState(const std::string& group_name, |
| 470 | const ClientSocketHandle* handle) const { |
| 471 | return LOAD_STATE_IDLE; |
| 472 | } |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 473 | virtual base::TimeDelta ConnectionTimeout() const { |
| 474 | return base::TimeDelta(); |
| 475 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 476 | |
| 477 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 478 | std::string last_group_name_; |
| 479 | }; |
| 480 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 481 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 482 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 483 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 484 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 485 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 486 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 487 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 488 | CaptureGroupNameSSLSocketPool; |
| 489 | |
| 490 | template<typename ParentPool> |
| 491 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 492 | HostResolver* host_resolver, |
| 493 | CertVerifier* /* cert_verifier */) |
| 494 | : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 495 | |
| 496 | template<> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 497 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 498 | HostResolver* host_resolver, |
| 499 | CertVerifier* /* cert_verifier */) |
| 500 | : HttpProxyClientSocketPool(0, 0, NULL, host_resolver, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 501 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 502 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 503 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 504 | HostResolver* host_resolver, |
| 505 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 506 | : SSLClientSocketPool(0, |
| 507 | 0, |
| 508 | NULL, |
| 509 | host_resolver, |
| 510 | cert_verifier, |
| 511 | NULL, |
| 512 | NULL, |
| 513 | std::string(), |
| 514 | NULL, |
| 515 | NULL, |
| 516 | NULL, |
| 517 | NULL, |
| 518 | NULL, |
| 519 | NULL) {} |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 520 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 521 | //----------------------------------------------------------------------------- |
| 522 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 523 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 524 | // configured for common cases. |
| 525 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 526 | if (!auth_challenge) |
| 527 | return false; |
| 528 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 529 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 530 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 531 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 532 | return true; |
| 533 | } |
| 534 | |
| 535 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 536 | if (!auth_challenge) |
| 537 | return false; |
| 538 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 539 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 540 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 541 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 546 | if (!auth_challenge) |
| 547 | return false; |
| 548 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 549 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 550 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 551 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 552 | return true; |
| 553 | } |
| 554 | |
| 555 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 556 | if (!auth_challenge) |
| 557 | return false; |
| 558 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 559 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 560 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 561 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 562 | return true; |
| 563 | } |
| 564 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 565 | } // namespace |
| 566 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 567 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 568 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 569 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 570 | CreateSession(&session_deps_))); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 571 | } |
| 572 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 573 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 574 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 575 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 576 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 578 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 579 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 580 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 581 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 582 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 583 | EXPECT_EQ("hello world", out.response_data); |
| 584 | } |
| 585 | |
| 586 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 587 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 588 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 589 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 591 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 592 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 593 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 594 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 595 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 596 | EXPECT_EQ("hello world", out.response_data); |
| 597 | } |
| 598 | |
| 599 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 600 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 601 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 602 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 603 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 604 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 605 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 606 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 607 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 608 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 609 | EXPECT_EQ("DATA", out.response_data); |
| 610 | } |
| 611 | |
| 612 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 613 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 614 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 615 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 616 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 617 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 618 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 619 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 620 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 621 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 622 | EXPECT_EQ("DATA", out.response_data); |
| 623 | } |
| 624 | |
| 625 | // 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] | 626 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 627 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 628 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 630 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 631 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 632 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 633 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 634 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 635 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 639 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 640 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 641 | MockRead("\n"), |
| 642 | MockRead("\n"), |
| 643 | MockRead("Q"), |
| 644 | MockRead("J"), |
| 645 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 646 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 647 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 648 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 649 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 650 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 651 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 652 | EXPECT_EQ("DATA", out.response_data); |
| 653 | } |
| 654 | |
| 655 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 656 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 657 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 658 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 659 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 660 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 661 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 662 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 663 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 664 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 665 | EXPECT_EQ("HTT", out.response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 668 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 669 | // persistent connection. The response should still terminate since a 204 |
| 670 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 671 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 672 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 673 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 674 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 675 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 676 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 677 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 678 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 679 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 680 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 681 | EXPECT_EQ("", out.response_data); |
| 682 | } |
| 683 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 684 | // A simple request using chunked encoding with some extra data after. |
| 685 | // (Like might be seen in a pipelined response.) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 686 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 687 | MockRead data_reads[] = { |
| 688 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 689 | MockRead("5\r\nHello\r\n"), |
| 690 | MockRead("1\r\n"), |
| 691 | MockRead(" \r\n"), |
| 692 | MockRead("5\r\nworld\r\n"), |
| 693 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 695 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 696 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 697 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 698 | EXPECT_EQ(OK, out.rv); |
| 699 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 700 | EXPECT_EQ("Hello world", out.response_data); |
| 701 | } |
| 702 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 703 | // Next tests deal with http://crbug.com/56344. |
| 704 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 705 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 706 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 707 | MockRead data_reads[] = { |
| 708 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 709 | MockRead("Content-Length: 10\r\n"), |
| 710 | MockRead("Content-Length: 5\r\n\r\n"), |
| 711 | }; |
| 712 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 713 | arraysize(data_reads)); |
| 714 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 715 | } |
| 716 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 717 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 718 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 719 | MockRead data_reads[] = { |
| 720 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 721 | MockRead("Content-Length: 5\r\n"), |
| 722 | MockRead("Content-Length: 5\r\n\r\n"), |
| 723 | MockRead("Hello"), |
| 724 | }; |
| 725 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 726 | arraysize(data_reads)); |
| 727 | EXPECT_EQ(OK, out.rv); |
| 728 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 729 | EXPECT_EQ("Hello", out.response_data); |
| 730 | } |
| 731 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 732 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 733 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 734 | // More than 2 dupes. |
| 735 | { |
| 736 | MockRead data_reads[] = { |
| 737 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 738 | MockRead("Content-Length: 5\r\n"), |
| 739 | MockRead("Content-Length: 5\r\n"), |
| 740 | MockRead("Content-Length: 5\r\n\r\n"), |
| 741 | MockRead("Hello"), |
| 742 | }; |
| 743 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 744 | arraysize(data_reads)); |
| 745 | EXPECT_EQ(OK, out.rv); |
| 746 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 747 | EXPECT_EQ("Hello", out.response_data); |
| 748 | } |
| 749 | // HTTP/1.0 |
| 750 | { |
| 751 | MockRead data_reads[] = { |
| 752 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 753 | MockRead("Content-Length: 5\r\n"), |
| 754 | MockRead("Content-Length: 5\r\n"), |
| 755 | MockRead("Content-Length: 5\r\n\r\n"), |
| 756 | MockRead("Hello"), |
| 757 | }; |
| 758 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 759 | arraysize(data_reads)); |
| 760 | EXPECT_EQ(OK, out.rv); |
| 761 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 762 | EXPECT_EQ("Hello", out.response_data); |
| 763 | } |
| 764 | // 2 dupes and one mismatched. |
| 765 | { |
| 766 | MockRead data_reads[] = { |
| 767 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 768 | MockRead("Content-Length: 10\r\n"), |
| 769 | MockRead("Content-Length: 10\r\n"), |
| 770 | MockRead("Content-Length: 5\r\n\r\n"), |
| 771 | }; |
| 772 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 773 | arraysize(data_reads)); |
| 774 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 775 | } |
| 776 | } |
| 777 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 778 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 779 | MultipleContentLengthHeadersTransferEncoding) { |
| 780 | MockRead data_reads[] = { |
| 781 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 782 | MockRead("Content-Length: 666\r\n"), |
| 783 | MockRead("Content-Length: 1337\r\n"), |
| 784 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 785 | MockRead("5\r\nHello\r\n"), |
| 786 | MockRead("1\r\n"), |
| 787 | MockRead(" \r\n"), |
| 788 | MockRead("5\r\nworld\r\n"), |
| 789 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 791 | }; |
| 792 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 793 | arraysize(data_reads)); |
| 794 | EXPECT_EQ(OK, out.rv); |
| 795 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 796 | EXPECT_EQ("Hello world", out.response_data); |
| 797 | } |
| 798 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 799 | // Next tests deal with http://crbug.com/98895. |
| 800 | |
| 801 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 802 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 803 | MockRead data_reads[] = { |
| 804 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 805 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 806 | MockRead("Content-Length: 5\r\n\r\n"), |
| 807 | MockRead("Hello"), |
| 808 | }; |
| 809 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 810 | arraysize(data_reads)); |
| 811 | EXPECT_EQ(OK, out.rv); |
| 812 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 813 | EXPECT_EQ("Hello", out.response_data); |
| 814 | } |
| 815 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 816 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 817 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 818 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 819 | MockRead data_reads[] = { |
| 820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 821 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 822 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 823 | MockRead("Content-Length: 5\r\n\r\n"), |
| 824 | MockRead("Hello"), |
| 825 | }; |
| 826 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 827 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 828 | EXPECT_EQ(OK, out.rv); |
| 829 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 830 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 834 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 835 | MockRead data_reads[] = { |
| 836 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 837 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 838 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 839 | MockRead("Content-Length: 5\r\n\r\n"), |
| 840 | MockRead("Hello"), |
| 841 | }; |
| 842 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 843 | arraysize(data_reads)); |
| 844 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 845 | } |
| 846 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 847 | // Checks that two identical Location headers result in no error. |
| 848 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 849 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 850 | MockRead data_reads[] = { |
| 851 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 852 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 853 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 854 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 855 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 856 | }; |
| 857 | |
| 858 | HttpRequestInfo request; |
| 859 | request.method = "GET"; |
| 860 | request.url = GURL("http://redirect.com/"); |
| 861 | request.load_flags = 0; |
| 862 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 865 | CreateSession(&session_deps_))); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 866 | |
| 867 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 868 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 870 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 872 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 874 | |
| 875 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 876 | |
| 877 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 878 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 879 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 880 | std::string url; |
| 881 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 882 | EXPECT_EQ("http://good.com/", url); |
| 883 | } |
| 884 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 885 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 886 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 887 | MockRead data_reads[] = { |
| 888 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 889 | MockRead("Location: http://good.com/\r\n"), |
| 890 | MockRead("Location: http://evil.com/\r\n"), |
| 891 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 893 | }; |
| 894 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 895 | arraysize(data_reads)); |
| 896 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 897 | } |
| 898 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 899 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 900 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 901 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 902 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 903 | request.method = "HEAD"; |
| 904 | request.url = GURL("http://www.google.com/"); |
| 905 | request.load_flags = 0; |
| 906 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 907 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 908 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 909 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 910 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 911 | MockWrite data_writes1[] = { |
| 912 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 913 | "Host: www.google.com\r\n" |
| 914 | "Connection: keep-alive\r\n" |
| 915 | "Content-Length: 0\r\n\r\n"), |
| 916 | }; |
| 917 | MockRead data_reads1[] = { |
| 918 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 919 | MockRead("Server: Blah\r\n"), |
| 920 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 921 | |
| 922 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 923 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 924 | }; |
| 925 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 926 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 927 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 928 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 930 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 932 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 933 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 934 | |
| 935 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 936 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 937 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 938 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 939 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 940 | |
| 941 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 942 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 943 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 944 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
| 945 | |
| 946 | std::string server_header; |
| 947 | void* iter = NULL; |
| 948 | bool has_server_header = response->headers->EnumerateHeader( |
| 949 | &iter, "Server", &server_header); |
| 950 | EXPECT_TRUE(has_server_header); |
| 951 | EXPECT_EQ("Blah", server_header); |
| 952 | |
| 953 | // Reading should give EOF right away, since there is no message body |
| 954 | // (despite non-zero content-length). |
| 955 | std::string response_data; |
| 956 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 957 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 958 | EXPECT_EQ("", response_data); |
| 959 | } |
| 960 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 961 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 963 | |
| 964 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 965 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 966 | MockRead("hello"), |
| 967 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 968 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 969 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 970 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 971 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 972 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 973 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 974 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 975 | "hello", "world" |
| 976 | }; |
| 977 | |
| 978 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 979 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 980 | request.method = "GET"; |
| 981 | request.url = GURL("http://www.google.com/"); |
| 982 | request.load_flags = 0; |
| 983 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 984 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 987 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 989 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 990 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 991 | |
| 992 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 993 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 994 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 995 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 996 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 997 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 998 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 999 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1000 | |
| 1001 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1002 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1003 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1004 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1008 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1009 | ScopedVector<UploadElementReader> element_readers; |
| 1010 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 1011 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1012 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1013 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1014 | request.method = "POST"; |
| 1015 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1016 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1017 | request.load_flags = 0; |
| 1018 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1019 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1021 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1022 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1023 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1024 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1025 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1026 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1027 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1028 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1029 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1030 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1032 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1034 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1036 | |
| 1037 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1038 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1039 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1040 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1041 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1042 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1043 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1044 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1045 | |
| 1046 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1047 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1048 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1049 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1050 | } |
| 1051 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1052 | // This test is almost the same as Ignores100 above, but the response contains |
| 1053 | // 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] | 1054 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1055 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1056 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1057 | request.method = "GET"; |
| 1058 | request.url = GURL("http://www.foo.com/"); |
| 1059 | request.load_flags = 0; |
| 1060 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1061 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1062 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1063 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1064 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1065 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1066 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1067 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1068 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1069 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1070 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1071 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1072 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1074 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1076 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1077 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1078 | |
| 1079 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1080 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1081 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1083 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1084 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1085 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1086 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1087 | |
| 1088 | std::string response_data; |
| 1089 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1090 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1091 | EXPECT_EQ("hello world", response_data); |
| 1092 | } |
| 1093 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1094 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1095 | HttpRequestInfo request; |
| 1096 | request.method = "POST"; |
| 1097 | request.url = GURL("http://www.foo.com/"); |
| 1098 | request.load_flags = 0; |
| 1099 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1100 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1101 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1102 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1103 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1104 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1105 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1106 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1107 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1108 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1111 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1113 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1114 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1115 | |
| 1116 | rv = callback.WaitForResult(); |
| 1117 | EXPECT_EQ(OK, rv); |
| 1118 | |
| 1119 | std::string response_data; |
| 1120 | rv = ReadTransaction(trans.get(), &response_data); |
| 1121 | EXPECT_EQ(OK, rv); |
| 1122 | EXPECT_EQ("", response_data); |
| 1123 | } |
| 1124 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1125 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1126 | HttpRequestInfo request; |
| 1127 | request.method = "POST"; |
| 1128 | request.url = GURL("http://www.foo.com/"); |
| 1129 | request.load_flags = 0; |
| 1130 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1131 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1132 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1133 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1134 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1135 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1136 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1137 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1138 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1141 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1143 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1145 | |
| 1146 | rv = callback.WaitForResult(); |
| 1147 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1148 | } |
| 1149 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1150 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1151 | const MockWrite* write_failure, |
| 1152 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1153 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1154 | request.method = "GET"; |
| 1155 | request.url = GURL("http://www.foo.com/"); |
| 1156 | request.load_flags = 0; |
| 1157 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1158 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1159 | session_deps_.net_log = &net_log; |
| 1160 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1161 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1162 | // Written data for successfully sending both requests. |
| 1163 | MockWrite data1_writes[] = { |
| 1164 | MockWrite("GET / HTTP/1.1\r\n" |
| 1165 | "Host: www.foo.com\r\n" |
| 1166 | "Connection: keep-alive\r\n\r\n"), |
| 1167 | MockWrite("GET / HTTP/1.1\r\n" |
| 1168 | "Host: www.foo.com\r\n" |
| 1169 | "Connection: keep-alive\r\n\r\n") |
| 1170 | }; |
| 1171 | |
| 1172 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1173 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1174 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1175 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1176 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1177 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1178 | |
| 1179 | if (write_failure) { |
| 1180 | ASSERT_TRUE(!read_failure); |
| 1181 | data1_writes[1] = *write_failure; |
| 1182 | } else { |
| 1183 | ASSERT_TRUE(read_failure); |
| 1184 | data1_reads[2] = *read_failure; |
| 1185 | } |
| 1186 | |
| 1187 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1188 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1189 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1190 | |
| 1191 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1192 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1193 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1194 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1195 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1196 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1197 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1198 | |
| 1199 | const char* kExpectedResponseData[] = { |
| 1200 | "hello", "world" |
| 1201 | }; |
| 1202 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1203 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1204 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1205 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1207 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1210 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1211 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1212 | |
| 1213 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1214 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1215 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1216 | LoadTimingInfo load_timing_info; |
| 1217 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1218 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1219 | if (i == 0) { |
| 1220 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1221 | } else { |
| 1222 | // The second request should be using a new socket. |
| 1223 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1224 | } |
| 1225 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1227 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1228 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1229 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1230 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1231 | |
| 1232 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1233 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1234 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1235 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1236 | } |
| 1237 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1239 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1240 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1241 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1242 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1243 | } |
| 1244 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1245 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1246 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1247 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1248 | } |
| 1249 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1250 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1251 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1252 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1253 | } |
| 1254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1255 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1256 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1257 | request.method = "GET"; |
| 1258 | request.url = GURL("http://www.google.com/"); |
| 1259 | request.load_flags = 0; |
| 1260 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1261 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1262 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1263 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1264 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1265 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1266 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1267 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1268 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1269 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1270 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1271 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1272 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1274 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1276 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1278 | |
| 1279 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1280 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1281 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1283 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | // What do various browsers do when the server closes a non-keepalive |
| 1287 | // connection without sending any response header or body? |
| 1288 | // |
| 1289 | // IE7: error page |
| 1290 | // Safari 3.1.2 (Windows): error page |
| 1291 | // Firefox 3.0.1: blank page |
| 1292 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1293 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1294 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1295 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1296 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1297 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1298 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1299 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1300 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1301 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1302 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1303 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1304 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1305 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1306 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1307 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1308 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1309 | // destructor in such situations. |
| 1310 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1311 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1312 | HttpRequestInfo request; |
| 1313 | request.method = "GET"; |
| 1314 | request.url = GURL("http://www.google.com/"); |
| 1315 | request.load_flags = 0; |
| 1316 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1317 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1318 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1319 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1320 | |
| 1321 | MockRead data_reads[] = { |
| 1322 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1323 | MockRead("Connection: keep-alive\r\n"), |
| 1324 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1325 | MockRead("hello"), |
| 1326 | MockRead(SYNCHRONOUS, 0), |
| 1327 | }; |
| 1328 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1330 | |
| 1331 | TestCompletionCallback callback; |
| 1332 | |
| 1333 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1335 | |
| 1336 | rv = callback.WaitForResult(); |
| 1337 | EXPECT_EQ(OK, rv); |
| 1338 | |
| 1339 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1340 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1341 | if (rv == ERR_IO_PENDING) |
| 1342 | rv = callback.WaitForResult(); |
| 1343 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1344 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1345 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1346 | |
| 1347 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1348 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1349 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1350 | } |
| 1351 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1352 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1353 | HttpRequestInfo request; |
| 1354 | request.method = "GET"; |
| 1355 | request.url = GURL("http://www.google.com/"); |
| 1356 | request.load_flags = 0; |
| 1357 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1358 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1359 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1361 | |
| 1362 | MockRead data_reads[] = { |
| 1363 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1364 | MockRead("Connection: keep-alive\r\n"), |
| 1365 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1366 | MockRead(SYNCHRONOUS, 0), |
| 1367 | }; |
| 1368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1370 | |
| 1371 | TestCompletionCallback callback; |
| 1372 | |
| 1373 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1375 | |
| 1376 | rv = callback.WaitForResult(); |
| 1377 | EXPECT_EQ(OK, rv); |
| 1378 | |
| 1379 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1380 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1381 | if (rv == ERR_IO_PENDING) |
| 1382 | rv = callback.WaitForResult(); |
| 1383 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1384 | |
| 1385 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1386 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1387 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1388 | } |
| 1389 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1390 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1391 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1392 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1393 | HttpRequestInfo request; |
| 1394 | request.method = "GET"; |
| 1395 | request.url = GURL("http://www.foo.com/"); |
| 1396 | request.load_flags = 0; |
| 1397 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1398 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1399 | session_deps_.net_log = &net_log; |
| 1400 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1401 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1402 | // Note that because all these reads happen in the same |
| 1403 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1404 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1405 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1406 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1407 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1408 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1409 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1410 | "Content-Length: 0\r\n\r\n"), |
| 1411 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1412 | "Content-Length: 5\r\n\r\n" |
| 1413 | "hello"), |
| 1414 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1415 | "Content-Length: 0\r\n\r\n"), |
| 1416 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1417 | "Content-Length: 5\r\n\r\n" |
| 1418 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1419 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1420 | MockRead("hello"), |
| 1421 | }; |
| 1422 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1423 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1424 | |
| 1425 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1426 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1427 | }; |
| 1428 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1430 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1431 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1432 | std::string response_lines[kNumUnreadBodies]; |
| 1433 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1434 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1435 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1436 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1437 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1438 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1439 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1441 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1443 | |
| 1444 | rv = callback.WaitForResult(); |
| 1445 | EXPECT_EQ(OK, rv); |
| 1446 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1447 | LoadTimingInfo load_timing_info; |
| 1448 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1449 | if (i == 0) { |
| 1450 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1451 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1452 | } else { |
| 1453 | TestLoadTimingReused(load_timing_info); |
| 1454 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1455 | } |
| 1456 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1457 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1458 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1459 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1460 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1461 | response_lines[i] = response->headers->GetStatusLine(); |
| 1462 | |
| 1463 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1464 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1465 | |
| 1466 | const char* const kStatusLines[] = { |
| 1467 | "HTTP/1.1 204 No Content", |
| 1468 | "HTTP/1.1 205 Reset Content", |
| 1469 | "HTTP/1.1 304 Not Modified", |
| 1470 | "HTTP/1.1 302 Found", |
| 1471 | "HTTP/1.1 302 Found", |
| 1472 | "HTTP/1.1 301 Moved Permanently", |
| 1473 | "HTTP/1.1 301 Moved Permanently", |
| 1474 | }; |
| 1475 | |
| 1476 | COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines), |
| 1477 | forgot_to_update_kStatusLines); |
| 1478 | |
| 1479 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1480 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1482 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1483 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1484 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1485 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1486 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1487 | rv = callback.WaitForResult(); |
| 1488 | EXPECT_EQ(OK, rv); |
| 1489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1490 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1491 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1492 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1493 | std::string response_data; |
| 1494 | rv = ReadTransaction(trans.get(), &response_data); |
| 1495 | EXPECT_EQ(OK, rv); |
| 1496 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1497 | } |
| 1498 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1499 | // Test the request-challenge-retry sequence for basic auth. |
| 1500 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1501 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1502 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1503 | request.method = "GET"; |
| 1504 | request.url = GURL("http://www.google.com/"); |
| 1505 | request.load_flags = 0; |
| 1506 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1507 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1508 | session_deps_.net_log = &log; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1511 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1512 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1513 | MockWrite data_writes1[] = { |
| 1514 | MockWrite("GET / HTTP/1.1\r\n" |
| 1515 | "Host: www.google.com\r\n" |
| 1516 | "Connection: keep-alive\r\n\r\n"), |
| 1517 | }; |
| 1518 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1519 | MockRead data_reads1[] = { |
| 1520 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1521 | // Give a couple authenticate options (only the middle one is actually |
| 1522 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1523 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1524 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1525 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1527 | // Large content-length -- won't matter, as connection will be reset. |
| 1528 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1529 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1530 | }; |
| 1531 | |
| 1532 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1533 | // be issuing -- the final header line contains the credentials. |
| 1534 | MockWrite data_writes2[] = { |
| 1535 | MockWrite("GET / HTTP/1.1\r\n" |
| 1536 | "Host: www.google.com\r\n" |
| 1537 | "Connection: keep-alive\r\n" |
| 1538 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1539 | }; |
| 1540 | |
| 1541 | // Lastly, the server responds with the actual content. |
| 1542 | MockRead data_reads2[] = { |
| 1543 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1544 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1545 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1546 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1547 | }; |
| 1548 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1549 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1550 | data_writes1, arraysize(data_writes1)); |
| 1551 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1552 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1553 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1556 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1558 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1559 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1560 | |
| 1561 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1562 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1563 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1564 | LoadTimingInfo load_timing_info1; |
| 1565 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1566 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1567 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1568 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1569 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1570 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1572 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1574 | rv = trans->RestartWithAuth( |
| 1575 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1576 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1577 | |
| 1578 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1579 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1580 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1581 | LoadTimingInfo load_timing_info2; |
| 1582 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1583 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1584 | // The load timing after restart should have a new socket ID, and times after |
| 1585 | // those of the first load timing. |
| 1586 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1587 | load_timing_info2.connect_timing.connect_start); |
| 1588 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1589 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1590 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1591 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1592 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1593 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1594 | } |
| 1595 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1596 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1597 | HttpRequestInfo request; |
| 1598 | request.method = "GET"; |
| 1599 | request.url = GURL("http://www.google.com/"); |
| 1600 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1601 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1602 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1603 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1604 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1605 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1606 | MockWrite data_writes[] = { |
| 1607 | MockWrite("GET / HTTP/1.1\r\n" |
| 1608 | "Host: www.google.com\r\n" |
| 1609 | "Connection: keep-alive\r\n\r\n"), |
| 1610 | }; |
| 1611 | |
| 1612 | MockRead data_reads[] = { |
| 1613 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1614 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1615 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1616 | // Large content-length -- won't matter, as connection will be reset. |
| 1617 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1618 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1619 | }; |
| 1620 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1621 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 1622 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1624 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1626 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1627 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1628 | |
| 1629 | rv = callback.WaitForResult(); |
| 1630 | EXPECT_EQ(0, rv); |
| 1631 | |
| 1632 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1633 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1634 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1635 | } |
| 1636 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1637 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1638 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1639 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1640 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1641 | request.method = "GET"; |
| 1642 | request.url = GURL("http://www.google.com/"); |
| 1643 | request.load_flags = 0; |
| 1644 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1645 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1646 | session_deps_.net_log = &log; |
| 1647 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1648 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1649 | MockWrite data_writes1[] = { |
| 1650 | MockWrite("GET / HTTP/1.1\r\n" |
| 1651 | "Host: www.google.com\r\n" |
| 1652 | "Connection: keep-alive\r\n\r\n"), |
| 1653 | |
| 1654 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1655 | // be issuing -- the final header line contains the credentials. |
| 1656 | MockWrite("GET / HTTP/1.1\r\n" |
| 1657 | "Host: www.google.com\r\n" |
| 1658 | "Connection: keep-alive\r\n" |
| 1659 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1660 | }; |
| 1661 | |
| 1662 | MockRead data_reads1[] = { |
| 1663 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1664 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1665 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1666 | MockRead("Content-Length: 14\r\n\r\n"), |
| 1667 | MockRead("Unauthorized\r\n"), |
| 1668 | |
| 1669 | // Lastly, the server responds with the actual content. |
| 1670 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1671 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1672 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1673 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1674 | }; |
| 1675 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1676 | // If there is a regression where we disconnect a Keep-Alive |
| 1677 | // connection during an auth roundtrip, we'll end up reading this. |
| 1678 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1679 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1680 | }; |
| 1681 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1682 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1683 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1684 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1685 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1686 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1687 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1689 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1690 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1691 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1692 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1693 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1695 | |
| 1696 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1697 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1698 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1699 | LoadTimingInfo load_timing_info1; |
| 1700 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1701 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1702 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1703 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1704 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1705 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1707 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1709 | rv = trans->RestartWithAuth( |
| 1710 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1712 | |
| 1713 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1714 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1715 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1716 | LoadTimingInfo load_timing_info2; |
| 1717 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1718 | TestLoadTimingReused(load_timing_info2); |
| 1719 | // The load timing after restart should have the same socket ID, and times |
| 1720 | // those of the first load timing. |
| 1721 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1722 | load_timing_info2.send_start); |
| 1723 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1724 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1725 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1726 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1727 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1728 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1732 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1733 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1734 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1735 | request.method = "GET"; |
| 1736 | request.url = GURL("http://www.google.com/"); |
| 1737 | request.load_flags = 0; |
| 1738 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1739 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1740 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1741 | MockWrite data_writes1[] = { |
| 1742 | MockWrite("GET / HTTP/1.1\r\n" |
| 1743 | "Host: www.google.com\r\n" |
| 1744 | "Connection: keep-alive\r\n\r\n"), |
| 1745 | |
| 1746 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1747 | // be issuing -- the final header line contains the credentials. |
| 1748 | MockWrite("GET / HTTP/1.1\r\n" |
| 1749 | "Host: www.google.com\r\n" |
| 1750 | "Connection: keep-alive\r\n" |
| 1751 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1752 | }; |
| 1753 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1754 | MockRead data_reads1[] = { |
| 1755 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1756 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1757 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1758 | |
| 1759 | // Lastly, the server responds with the actual content. |
| 1760 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1761 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1762 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1763 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1764 | }; |
| 1765 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1766 | // An incorrect reconnect would cause this to be read. |
| 1767 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1768 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1769 | }; |
| 1770 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1771 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1772 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1773 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1774 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1775 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1776 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1778 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1779 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1780 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1782 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1783 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1784 | |
| 1785 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1786 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1787 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1788 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1789 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1790 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1792 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1794 | rv = trans->RestartWithAuth( |
| 1795 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1796 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1797 | |
| 1798 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1799 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1800 | |
| 1801 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1802 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1803 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1804 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 1808 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1809 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1810 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1811 | request.method = "GET"; |
| 1812 | request.url = GURL("http://www.google.com/"); |
| 1813 | request.load_flags = 0; |
| 1814 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1815 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1816 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1817 | MockWrite data_writes1[] = { |
| 1818 | MockWrite("GET / HTTP/1.1\r\n" |
| 1819 | "Host: www.google.com\r\n" |
| 1820 | "Connection: keep-alive\r\n\r\n"), |
| 1821 | |
| 1822 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1823 | // be issuing -- the final header line contains the credentials. |
| 1824 | MockWrite("GET / HTTP/1.1\r\n" |
| 1825 | "Host: www.google.com\r\n" |
| 1826 | "Connection: keep-alive\r\n" |
| 1827 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1828 | }; |
| 1829 | |
| 1830 | // Respond with 5 kb of response body. |
| 1831 | std::string large_body_string("Unauthorized"); |
| 1832 | large_body_string.append(5 * 1024, ' '); |
| 1833 | large_body_string.append("\r\n"); |
| 1834 | |
| 1835 | MockRead data_reads1[] = { |
| 1836 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1837 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1838 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1839 | // 5134 = 12 + 5 * 1024 + 2 |
| 1840 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1841 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1842 | |
| 1843 | // Lastly, the server responds with the actual content. |
| 1844 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1845 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1846 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1847 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1848 | }; |
| 1849 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1850 | // An incorrect reconnect would cause this to be read. |
| 1851 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1852 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1853 | }; |
| 1854 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1855 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1856 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 1857 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1858 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1859 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1860 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1862 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1863 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1864 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1865 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1866 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1868 | |
| 1869 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1870 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1871 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1872 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1873 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1874 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1876 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1878 | rv = trans->RestartWithAuth( |
| 1879 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1880 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1881 | |
| 1882 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1883 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1884 | |
| 1885 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1886 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1887 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1888 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1892 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1893 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1894 | HttpRequestInfo request; |
| 1895 | request.method = "GET"; |
| 1896 | request.url = GURL("http://www.google.com/"); |
| 1897 | request.load_flags = 0; |
| 1898 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1899 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1900 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1901 | MockWrite data_writes1[] = { |
| 1902 | MockWrite("GET / HTTP/1.1\r\n" |
| 1903 | "Host: www.google.com\r\n" |
| 1904 | "Connection: keep-alive\r\n\r\n"), |
| 1905 | // This simulates the seemingly successful write to a closed connection |
| 1906 | // if the bug is not fixed. |
| 1907 | MockWrite("GET / HTTP/1.1\r\n" |
| 1908 | "Host: www.google.com\r\n" |
| 1909 | "Connection: keep-alive\r\n" |
| 1910 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1911 | }; |
| 1912 | |
| 1913 | MockRead data_reads1[] = { |
| 1914 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 1915 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1916 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1917 | MockRead("Content-Length: 14\r\n\r\n"), |
| 1918 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1919 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1920 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1921 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1922 | }; |
| 1923 | |
| 1924 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1925 | // be issuing -- the final header line contains the credentials. |
| 1926 | MockWrite data_writes2[] = { |
| 1927 | MockWrite("GET / HTTP/1.1\r\n" |
| 1928 | "Host: www.google.com\r\n" |
| 1929 | "Connection: keep-alive\r\n" |
| 1930 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1931 | }; |
| 1932 | |
| 1933 | // Lastly, the server responds with the actual content. |
| 1934 | MockRead data_reads2[] = { |
| 1935 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1936 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1937 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1938 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1939 | }; |
| 1940 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1941 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1942 | data_writes1, arraysize(data_writes1)); |
| 1943 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1944 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1946 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1948 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1949 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1950 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1951 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1952 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1953 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1954 | |
| 1955 | rv = callback1.WaitForResult(); |
| 1956 | EXPECT_EQ(OK, rv); |
| 1957 | |
| 1958 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1959 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1960 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1961 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1962 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1964 | rv = trans->RestartWithAuth( |
| 1965 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1967 | |
| 1968 | rv = callback2.WaitForResult(); |
| 1969 | EXPECT_EQ(OK, rv); |
| 1970 | |
| 1971 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1972 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1973 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1974 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 1975 | } |
| 1976 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1977 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 1978 | // that requires a restart when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1979 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1980 | HttpRequestInfo request; |
| 1981 | request.method = "GET"; |
| 1982 | request.url = GURL("https://www.google.com/"); |
| 1983 | // when the no authentication data flag is set. |
| 1984 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1985 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1986 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1987 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 1988 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 1989 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1990 | session_deps_.net_log = log.bound().net_log(); |
| 1991 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1992 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 1993 | // Since we have proxy, should try to establish tunnel. |
| 1994 | MockWrite data_writes1[] = { |
| 1995 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1996 | "Host: www.google.com\r\n" |
| 1997 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 1998 | |
| 1999 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2000 | // be issuing -- the final header line contains the credentials. |
| 2001 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2002 | "Host: www.google.com\r\n" |
| 2003 | "Proxy-Connection: keep-alive\r\n" |
| 2004 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2005 | |
| 2006 | MockWrite("GET / HTTP/1.1\r\n" |
| 2007 | "Host: www.google.com\r\n" |
| 2008 | "Connection: keep-alive\r\n\r\n"), |
| 2009 | }; |
| 2010 | |
| 2011 | // The proxy responds to the connect with a 407, using a persistent |
| 2012 | // connection. |
| 2013 | MockRead data_reads1[] = { |
| 2014 | // No credentials. |
| 2015 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2016 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2017 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2018 | |
| 2019 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2020 | |
| 2021 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2022 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2023 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2024 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2025 | }; |
| 2026 | |
| 2027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2028 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2030 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2031 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2033 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2034 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2035 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2038 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2039 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2040 | |
| 2041 | rv = callback1.WaitForResult(); |
| 2042 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2043 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2044 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2045 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2046 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2047 | NetLog::PHASE_NONE); |
| 2048 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2049 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2050 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2051 | NetLog::PHASE_NONE); |
| 2052 | |
| 2053 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2054 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2055 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2056 | EXPECT_EQ(407, response->headers->response_code()); |
| 2057 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2058 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2059 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2060 | LoadTimingInfo load_timing_info; |
| 2061 | // CONNECT requests and responses are handled at the connect job level, so |
| 2062 | // the transaction does not yet have a connection. |
| 2063 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2065 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2067 | rv = trans->RestartWithAuth( |
| 2068 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2070 | |
| 2071 | rv = callback2.WaitForResult(); |
| 2072 | EXPECT_EQ(OK, rv); |
| 2073 | |
| 2074 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2075 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2076 | |
| 2077 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2078 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2079 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2080 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2081 | |
| 2082 | // The password prompt info should not be set. |
| 2083 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2084 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2085 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2086 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2087 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2088 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2089 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2090 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2091 | } |
| 2092 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2093 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2094 | // proxy connection, when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2095 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2096 | HttpRequestInfo request; |
| 2097 | request.method = "GET"; |
| 2098 | request.url = GURL("https://www.google.com/"); |
| 2099 | // Ensure that proxy authentication is attempted even |
| 2100 | // when the no authentication data flag is set. |
| 2101 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2102 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2103 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2104 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2105 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2106 | session_deps_.net_log = log.bound().net_log(); |
| 2107 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2108 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2109 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2110 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2111 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2112 | // Since we have proxy, should try to establish tunnel. |
| 2113 | MockWrite data_writes1[] = { |
| 2114 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2115 | "Host: www.google.com\r\n" |
| 2116 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2117 | |
| 2118 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2119 | // be issuing -- the final header line contains the credentials. |
| 2120 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2121 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2122 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2123 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2124 | }; |
| 2125 | |
| 2126 | // The proxy responds to the connect with a 407, using a persistent |
| 2127 | // connection. |
| 2128 | MockRead data_reads1[] = { |
| 2129 | // No credentials. |
| 2130 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2131 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2132 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2133 | MockRead("0123456789"), |
| 2134 | |
| 2135 | // Wrong credentials (wrong password). |
| 2136 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2137 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2138 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2139 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2140 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2141 | }; |
| 2142 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2143 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2144 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2145 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2147 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2149 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2150 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2151 | |
| 2152 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2153 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2154 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2155 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2156 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2157 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2158 | NetLog::PHASE_NONE); |
| 2159 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2160 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2161 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2162 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2163 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2165 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2166 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2167 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2168 | EXPECT_EQ(407, response->headers->response_code()); |
| 2169 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2170 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2171 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2173 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2174 | |
| 2175 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2176 | rv = trans->RestartWithAuth( |
| 2177 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2178 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2179 | |
| 2180 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2181 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2182 | |
| 2183 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2184 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2185 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2187 | EXPECT_EQ(407, response->headers->response_code()); |
| 2188 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2189 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2190 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2191 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2192 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2193 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2194 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2195 | } |
| 2196 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2197 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2198 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2199 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2200 | HttpRequestInfo request; |
| 2201 | request.method = "GET"; |
| 2202 | request.url = GURL("https://www.google.com/"); |
| 2203 | request.load_flags = 0; |
| 2204 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2205 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2206 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2207 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2208 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2209 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2210 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2212 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2213 | // Since we have proxy, should try to establish tunnel. |
| 2214 | MockWrite data_writes[] = { |
| 2215 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2216 | "Host: www.google.com\r\n" |
| 2217 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | // The proxy responds to the connect with a 407. |
| 2221 | MockRead data_reads[] = { |
| 2222 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2223 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2224 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2225 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2226 | }; |
| 2227 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2228 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2229 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2230 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2232 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2234 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2236 | |
| 2237 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2238 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2239 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2240 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2241 | ASSERT_TRUE(response != NULL); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2242 | |
| 2243 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2244 | EXPECT_EQ(407, response->headers->response_code()); |
| 2245 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2246 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2247 | |
| 2248 | std::string response_data; |
| 2249 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2250 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2251 | |
| 2252 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2253 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2254 | } |
| 2255 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2256 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2257 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2258 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2259 | HttpRequestInfo request; |
| 2260 | request.method = "GET"; |
| 2261 | request.url = GURL("http://www.google.com/"); |
| 2262 | request.load_flags = 0; |
| 2263 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2264 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2265 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2266 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2267 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2268 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2269 | MockWrite data_writes1[] = { |
| 2270 | MockWrite("GET / HTTP/1.1\r\n" |
| 2271 | "Host: www.google.com\r\n" |
| 2272 | "Connection: keep-alive\r\n\r\n"), |
| 2273 | }; |
| 2274 | |
| 2275 | MockRead data_reads1[] = { |
| 2276 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2277 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2278 | // Large content-length -- won't matter, as connection will be reset. |
| 2279 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2280 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2281 | }; |
| 2282 | |
| 2283 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2284 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2285 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2287 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2289 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2291 | |
| 2292 | rv = callback.WaitForResult(); |
| 2293 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2294 | } |
| 2295 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2296 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2297 | // through a non-authenticating proxy. The request should fail with |
| 2298 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2299 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2300 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2301 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2302 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2303 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2304 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2305 | HttpRequestInfo request; |
| 2306 | request.method = "GET"; |
| 2307 | request.url = GURL("https://www.google.com/"); |
| 2308 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2309 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2310 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2311 | session_deps_.net_log = log.bound().net_log(); |
| 2312 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2313 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2314 | // Since we have proxy, should try to establish tunnel. |
| 2315 | MockWrite data_writes1[] = { |
| 2316 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2317 | "Host: www.google.com\r\n" |
| 2318 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2319 | |
| 2320 | MockWrite("GET / HTTP/1.1\r\n" |
| 2321 | "Host: www.google.com\r\n" |
| 2322 | "Connection: keep-alive\r\n\r\n"), |
| 2323 | }; |
| 2324 | |
| 2325 | MockRead data_reads1[] = { |
| 2326 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2327 | |
| 2328 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 2329 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2330 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2331 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2332 | }; |
| 2333 | |
| 2334 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2335 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2337 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2340 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2341 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2342 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2343 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2345 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2346 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2347 | |
| 2348 | rv = callback1.WaitForResult(); |
| 2349 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2350 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2351 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2352 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2353 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2354 | NetLog::PHASE_NONE); |
| 2355 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2356 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2357 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2358 | NetLog::PHASE_NONE); |
| 2359 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2360 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2361 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2362 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2363 | HttpRequestInfo request1; |
| 2364 | request1.method = "GET"; |
| 2365 | request1.url = GURL("https://www.google.com/1"); |
| 2366 | |
| 2367 | HttpRequestInfo request2; |
| 2368 | request2.method = "GET"; |
| 2369 | request2.url = GURL("https://www.google.com/2"); |
| 2370 | |
| 2371 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2372 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2373 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 2374 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2375 | session_deps_.net_log = log.bound().net_log(); |
| 2376 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2377 | |
| 2378 | // Since we have proxy, should try to establish tunnel. |
| 2379 | MockWrite data_writes1[] = { |
| 2380 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2381 | "Host: www.google.com\r\n" |
| 2382 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2383 | |
| 2384 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2385 | "Host: www.google.com\r\n" |
| 2386 | "Connection: keep-alive\r\n\r\n"), |
| 2387 | |
| 2388 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2389 | "Host: www.google.com\r\n" |
| 2390 | "Connection: keep-alive\r\n\r\n"), |
| 2391 | }; |
| 2392 | |
| 2393 | // The proxy responds to the connect with a 407, using a persistent |
| 2394 | // connection. |
| 2395 | MockRead data_reads1[] = { |
| 2396 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2397 | |
| 2398 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2399 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2400 | MockRead(SYNCHRONOUS, "1"), |
| 2401 | |
| 2402 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2403 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2404 | MockRead(SYNCHRONOUS, "22"), |
| 2405 | }; |
| 2406 | |
| 2407 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2408 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2409 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2410 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2411 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2412 | |
| 2413 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2414 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2415 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2416 | |
| 2417 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2418 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2419 | |
| 2420 | rv = callback1.WaitForResult(); |
| 2421 | EXPECT_EQ(OK, rv); |
| 2422 | |
| 2423 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2424 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2425 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2426 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2427 | |
| 2428 | LoadTimingInfo load_timing_info1; |
| 2429 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2430 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2431 | |
| 2432 | trans1.reset(); |
| 2433 | |
| 2434 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2435 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2437 | |
| 2438 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2440 | |
| 2441 | rv = callback2.WaitForResult(); |
| 2442 | EXPECT_EQ(OK, rv); |
| 2443 | |
| 2444 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2445 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2446 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2447 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2448 | |
| 2449 | LoadTimingInfo load_timing_info2; |
| 2450 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2451 | TestLoadTimingReused(load_timing_info2); |
| 2452 | |
| 2453 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2454 | |
| 2455 | trans2.reset(); |
| 2456 | session->CloseAllConnections(); |
| 2457 | } |
| 2458 | |
| 2459 | // 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] | 2460 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2461 | HttpRequestInfo request1; |
| 2462 | request1.method = "GET"; |
| 2463 | request1.url = GURL("https://www.google.com/1"); |
| 2464 | |
| 2465 | HttpRequestInfo request2; |
| 2466 | request2.method = "GET"; |
| 2467 | request2.url = GURL("https://www.google.com/2"); |
| 2468 | |
| 2469 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2470 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2471 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2472 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2473 | session_deps_.net_log = log.bound().net_log(); |
| 2474 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2475 | |
| 2476 | // Since we have proxy, should try to establish tunnel. |
| 2477 | MockWrite data_writes1[] = { |
| 2478 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2479 | "Host: www.google.com\r\n" |
| 2480 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2481 | |
| 2482 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2483 | "Host: www.google.com\r\n" |
| 2484 | "Connection: keep-alive\r\n\r\n"), |
| 2485 | |
| 2486 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2487 | "Host: www.google.com\r\n" |
| 2488 | "Connection: keep-alive\r\n\r\n"), |
| 2489 | }; |
| 2490 | |
| 2491 | // The proxy responds to the connect with a 407, using a persistent |
| 2492 | // connection. |
| 2493 | MockRead data_reads1[] = { |
| 2494 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2495 | |
| 2496 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2497 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2498 | MockRead(SYNCHRONOUS, "1"), |
| 2499 | |
| 2500 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2501 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2502 | MockRead(SYNCHRONOUS, "22"), |
| 2503 | }; |
| 2504 | |
| 2505 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2506 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2508 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2510 | |
| 2511 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2512 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2514 | |
| 2515 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2517 | |
| 2518 | rv = callback1.WaitForResult(); |
| 2519 | EXPECT_EQ(OK, rv); |
| 2520 | |
| 2521 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2522 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2523 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2524 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2525 | |
| 2526 | LoadTimingInfo load_timing_info1; |
| 2527 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2528 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 2529 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2530 | |
| 2531 | trans1.reset(); |
| 2532 | |
| 2533 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2534 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2536 | |
| 2537 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2539 | |
| 2540 | rv = callback2.WaitForResult(); |
| 2541 | EXPECT_EQ(OK, rv); |
| 2542 | |
| 2543 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2544 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2545 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2546 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2547 | |
| 2548 | LoadTimingInfo load_timing_info2; |
| 2549 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2550 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 2551 | |
| 2552 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2553 | |
| 2554 | trans2.reset(); |
| 2555 | session->CloseAllConnections(); |
| 2556 | } |
| 2557 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2558 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2559 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2560 | HttpRequestInfo request; |
| 2561 | request.method = "GET"; |
| 2562 | request.url = GURL("http://www.google.com/"); |
| 2563 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2564 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2565 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2566 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2567 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2568 | session_deps_.net_log = log.bound().net_log(); |
| 2569 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2570 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2571 | // Since we have proxy, should use full url |
| 2572 | MockWrite data_writes1[] = { |
| 2573 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 2574 | "Host: www.google.com\r\n" |
| 2575 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2576 | }; |
| 2577 | |
| 2578 | MockRead data_reads1[] = { |
| 2579 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2580 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2581 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2582 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2583 | }; |
| 2584 | |
| 2585 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2586 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2587 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2588 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2591 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2592 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2593 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2596 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2598 | |
| 2599 | rv = callback1.WaitForResult(); |
| 2600 | EXPECT_EQ(OK, rv); |
| 2601 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2602 | LoadTimingInfo load_timing_info; |
| 2603 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2604 | TestLoadTimingNotReused(load_timing_info, |
| 2605 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2606 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2607 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2608 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2609 | |
| 2610 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2611 | EXPECT_EQ(200, response->headers->response_code()); |
| 2612 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2613 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2614 | |
| 2615 | // The password prompt info should not be set. |
| 2616 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2617 | } |
| 2618 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2619 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2620 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2621 | HttpRequestInfo request; |
| 2622 | request.method = "GET"; |
| 2623 | request.url = GURL("http://www.google.com/"); |
| 2624 | request.load_flags = 0; |
| 2625 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2626 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2627 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2628 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2629 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2630 | session_deps_.net_log = log.bound().net_log(); |
| 2631 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2632 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2633 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2634 | scoped_ptr<SpdyFrame> req( |
| 2635 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2636 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 2637 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2638 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2639 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2640 | MockRead spdy_reads[] = { |
| 2641 | CreateMockRead(*resp), |
| 2642 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2643 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2644 | }; |
| 2645 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2646 | DelayedSocketData spdy_data( |
| 2647 | 1, // wait for one write to finish before reading. |
| 2648 | spdy_reads, arraysize(spdy_reads), |
| 2649 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2650 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2651 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2652 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2653 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2654 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2656 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2657 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2658 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2659 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2661 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2662 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2663 | |
| 2664 | rv = callback1.WaitForResult(); |
| 2665 | EXPECT_EQ(OK, rv); |
| 2666 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2667 | LoadTimingInfo load_timing_info; |
| 2668 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2669 | TestLoadTimingNotReused(load_timing_info, |
| 2670 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2671 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2672 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2673 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2674 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2675 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2676 | |
| 2677 | std::string response_data; |
| 2678 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2679 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 2680 | } |
| 2681 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2682 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2683 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2684 | HttpRequestInfo request; |
| 2685 | request.method = "GET"; |
| 2686 | request.url = GURL("http://www.google.com/"); |
| 2687 | request.load_flags = 0; |
| 2688 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2689 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2690 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2691 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2692 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2693 | session_deps_.net_log = log.bound().net_log(); |
| 2694 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2695 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2696 | // The first request will be a bare GET, the second request will be a |
| 2697 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2698 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2699 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2700 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2701 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2702 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2703 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2704 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 2705 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 2706 | false, |
| 2707 | 3, |
| 2708 | LOWEST, |
| 2709 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2710 | MockWrite spdy_writes[] = { |
| 2711 | CreateMockWrite(*req_get, 1), |
| 2712 | CreateMockWrite(*req_get_authorization, 4), |
| 2713 | }; |
| 2714 | |
| 2715 | // The first response is a 407 proxy authentication challenge, and the second |
| 2716 | // response will be a 200 response since the second request includes a valid |
| 2717 | // Authorization header. |
| 2718 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2719 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2720 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2721 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2722 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2723 | "407 Proxy Authentication Required", |
| 2724 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 2725 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2726 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2727 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2728 | scoped_ptr<SpdyFrame> resp_data( |
| 2729 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 2730 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2731 | MockRead spdy_reads[] = { |
| 2732 | CreateMockRead(*resp_authentication, 2), |
| 2733 | CreateMockRead(*body_authentication, 3), |
| 2734 | CreateMockRead(*resp_data, 5), |
| 2735 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2736 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2737 | }; |
| 2738 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2739 | OrderedSocketData data( |
| 2740 | spdy_reads, arraysize(spdy_reads), |
| 2741 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2743 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2744 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2745 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2748 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2749 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2750 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2751 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2753 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2754 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2755 | |
| 2756 | rv = callback1.WaitForResult(); |
| 2757 | EXPECT_EQ(OK, rv); |
| 2758 | |
| 2759 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 2760 | |
| 2761 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2762 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2763 | EXPECT_EQ(407, response->headers->response_code()); |
| 2764 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2765 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2766 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2767 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2769 | rv = trans->RestartWithAuth( |
| 2770 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2771 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2772 | |
| 2773 | rv = callback2.WaitForResult(); |
| 2774 | EXPECT_EQ(OK, rv); |
| 2775 | |
| 2776 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 2777 | |
| 2778 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2779 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 2780 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 2781 | // The password prompt info should not be set. |
| 2782 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 2783 | } |
| 2784 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2785 | // 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] | 2786 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2787 | HttpRequestInfo request; |
| 2788 | request.method = "GET"; |
| 2789 | request.url = GURL("https://www.google.com/"); |
| 2790 | request.load_flags = 0; |
| 2791 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2792 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2793 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2794 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2795 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2796 | session_deps_.net_log = log.bound().net_log(); |
| 2797 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2798 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2799 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2800 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2801 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2802 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 2803 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 2804 | LOWEST)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2805 | // fetch https://www.google.com/ via HTTP |
| 2806 | |
| 2807 | const char get[] = "GET / HTTP/1.1\r\n" |
| 2808 | "Host: www.google.com\r\n" |
| 2809 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2810 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2811 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 2812 | scoped_ptr<SpdyFrame> conn_resp( |
| 2813 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2814 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 2815 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2816 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2817 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2818 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2819 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2820 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2821 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2822 | |
| 2823 | MockWrite spdy_writes[] = { |
| 2824 | CreateMockWrite(*connect, 1), |
| 2825 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2826 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2827 | }; |
| 2828 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2829 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2830 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 2831 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 2832 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 2833 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 2834 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2835 | }; |
| 2836 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2837 | OrderedSocketData spdy_data( |
| 2838 | spdy_reads, arraysize(spdy_reads), |
| 2839 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2840 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2841 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2842 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2843 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2845 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2846 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 2847 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2850 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2852 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2854 | |
| 2855 | rv = callback1.WaitForResult(); |
| 2856 | EXPECT_EQ(OK, rv); |
| 2857 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2858 | LoadTimingInfo load_timing_info; |
| 2859 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2860 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2861 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2862 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2863 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2864 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2865 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2866 | |
| 2867 | std::string response_data; |
| 2868 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 2869 | EXPECT_EQ("1234567890", response_data); |
| 2870 | } |
| 2871 | |
| 2872 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2873 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2874 | HttpRequestInfo request; |
| 2875 | request.method = "GET"; |
| 2876 | request.url = GURL("https://www.google.com/"); |
| 2877 | request.load_flags = 0; |
| 2878 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2879 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2880 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2881 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2882 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2883 | session_deps_.net_log = log.bound().net_log(); |
| 2884 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2885 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2886 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2887 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2888 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2889 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 2890 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 2891 | LOWEST)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2892 | // fetch https://www.google.com/ via SPDY |
| 2893 | const char* const kMyUrl = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2894 | scoped_ptr<SpdyFrame> get( |
| 2895 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2896 | scoped_ptr<SpdyFrame> wrapped_get( |
| 2897 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 2898 | scoped_ptr<SpdyFrame> conn_resp( |
| 2899 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2900 | scoped_ptr<SpdyFrame> get_resp( |
| 2901 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2902 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2903 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 2904 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2905 | scoped_ptr<SpdyFrame> wrapped_body( |
| 2906 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2907 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2908 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2909 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2910 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 2911 | |
| 2912 | MockWrite spdy_writes[] = { |
| 2913 | CreateMockWrite(*connect, 1), |
| 2914 | CreateMockWrite(*wrapped_get, 3), |
| 2915 | CreateMockWrite(*window_update_get_resp, 5), |
| 2916 | CreateMockWrite(*window_update_body, 7), |
| 2917 | }; |
| 2918 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2919 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2920 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 2921 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 2922 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 2923 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2924 | }; |
| 2925 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2926 | OrderedSocketData spdy_data( |
| 2927 | spdy_reads, arraysize(spdy_reads), |
| 2928 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2929 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2930 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2931 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2932 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2934 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2935 | ssl2.SetNextProto(GetParam()); |
| 2936 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2939 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2941 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2943 | |
| 2944 | rv = callback1.WaitForResult(); |
| 2945 | EXPECT_EQ(OK, rv); |
| 2946 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2947 | LoadTimingInfo load_timing_info; |
| 2948 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2949 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2950 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2951 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2952 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2953 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2954 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2955 | |
| 2956 | std::string response_data; |
| 2957 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2958 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2962 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2963 | HttpRequestInfo request; |
| 2964 | request.method = "GET"; |
| 2965 | request.url = GURL("https://www.google.com/"); |
| 2966 | request.load_flags = 0; |
| 2967 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2968 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2969 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2970 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2971 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2972 | session_deps_.net_log = log.bound().net_log(); |
| 2973 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2974 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2975 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2976 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2977 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2978 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 2979 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 2980 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2981 | scoped_ptr<SpdyFrame> get( |
| 2982 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2983 | |
| 2984 | MockWrite spdy_writes[] = { |
| 2985 | CreateMockWrite(*connect, 1), |
| 2986 | CreateMockWrite(*get, 3), |
| 2987 | }; |
| 2988 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2989 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 2990 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2991 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2992 | CreateMockRead(*resp, 2, ASYNC), |
| 2993 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 2994 | }; |
| 2995 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2996 | OrderedSocketData spdy_data( |
| 2997 | spdy_reads, arraysize(spdy_reads), |
| 2998 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2999 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3000 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3001 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3002 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3003 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3004 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3005 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3007 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3008 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3010 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3011 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3012 | |
| 3013 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3014 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3015 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3016 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3017 | } |
| 3018 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3019 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3020 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3021 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3022 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3023 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3024 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3025 | "https://proxy:70")); |
| 3026 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3027 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3028 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3029 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3030 | |
| 3031 | HttpRequestInfo request1; |
| 3032 | request1.method = "GET"; |
| 3033 | request1.url = GURL("https://www.google.com/"); |
| 3034 | request1.load_flags = 0; |
| 3035 | |
| 3036 | HttpRequestInfo request2; |
| 3037 | request2.method = "GET"; |
| 3038 | request2.url = GURL("https://news.google.com/"); |
| 3039 | request2.load_flags = 0; |
| 3040 | |
| 3041 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3042 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3043 | LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3044 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3045 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3046 | |
| 3047 | // Fetch https://www.google.com/ via HTTP. |
| 3048 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3049 | "Host: www.google.com\r\n" |
| 3050 | "Connection: keep-alive\r\n\r\n"; |
| 3051 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3052 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3053 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3054 | "Content-Length: 1\r\n\r\n"; |
| 3055 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3056 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3057 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3058 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3059 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3060 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3061 | |
| 3062 | // CONNECT to news.google.com:443 via SPDY. |
| 3063 | const char* const kConnectHeaders2[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3064 | spdy_util_.GetMethodKey(), "CONNECT", |
| 3065 | spdy_util_.GetPathKey(), "news.google.com:443", |
| 3066 | spdy_util_.GetHostKey(), "news.google.com", |
| 3067 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3068 | }; |
| 3069 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3070 | spdy_util_.ConstructSpdyControlFrame(NULL, |
| 3071 | 0, |
| 3072 | /*compressed*/ false, |
| 3073 | 3, |
| 3074 | LOWEST, |
| 3075 | SYN_STREAM, |
| 3076 | CONTROL_FLAG_NONE, |
| 3077 | kConnectHeaders2, |
| 3078 | arraysize(kConnectHeaders2), |
| 3079 | 0)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3080 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3081 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3082 | |
| 3083 | // Fetch https://news.google.com/ via HTTP. |
| 3084 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3085 | "Host: news.google.com\r\n" |
| 3086 | "Connection: keep-alive\r\n\r\n"; |
| 3087 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3088 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3089 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3090 | "Content-Length: 2\r\n\r\n"; |
| 3091 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3092 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3093 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3094 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3095 | |
| 3096 | MockWrite spdy_writes[] = { |
| 3097 | CreateMockWrite(*connect1, 0), |
| 3098 | CreateMockWrite(*wrapped_get1, 2), |
| 3099 | CreateMockWrite(*connect2, 5), |
| 3100 | CreateMockWrite(*wrapped_get2, 7), |
| 3101 | }; |
| 3102 | |
| 3103 | MockRead spdy_reads[] = { |
| 3104 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3105 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3106 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3107 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3108 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3109 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3110 | MockRead(ASYNC, 0, 10), |
| 3111 | }; |
| 3112 | |
| 3113 | DeterministicSocketData spdy_data( |
| 3114 | spdy_reads, arraysize(spdy_reads), |
| 3115 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3116 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3117 | |
| 3118 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3119 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3120 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3121 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3122 | ssl2.was_npn_negotiated = false; |
| 3123 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3124 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3125 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3126 | ssl3.was_npn_negotiated = false; |
| 3127 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3128 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3129 | |
| 3130 | TestCompletionCallback callback; |
| 3131 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3132 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3134 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3136 | // The first connect and request, each of their responses, and the body. |
| 3137 | spdy_data.RunFor(5); |
| 3138 | |
| 3139 | rv = callback.WaitForResult(); |
| 3140 | EXPECT_EQ(OK, rv); |
| 3141 | |
| 3142 | LoadTimingInfo load_timing_info; |
| 3143 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3144 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3145 | |
| 3146 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3147 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3148 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3150 | |
| 3151 | std::string response_data; |
| 3152 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3153 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3154 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3155 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3156 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3157 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3159 | |
| 3160 | // The second connect and request, each of their responses, and the body. |
| 3161 | spdy_data.RunFor(5); |
| 3162 | rv = callback.WaitForResult(); |
| 3163 | EXPECT_EQ(OK, rv); |
| 3164 | |
| 3165 | LoadTimingInfo load_timing_info2; |
| 3166 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3167 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3168 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3169 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3170 | |
| 3171 | // The requests should have different IDs, since they each are using their own |
| 3172 | // separate stream. |
| 3173 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3174 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3175 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3179 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3180 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3181 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3182 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3183 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3184 | "https://proxy:70")); |
| 3185 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3186 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3187 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3188 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3189 | |
| 3190 | HttpRequestInfo request1; |
| 3191 | request1.method = "GET"; |
| 3192 | request1.url = GURL("https://www.google.com/"); |
| 3193 | request1.load_flags = 0; |
| 3194 | |
| 3195 | HttpRequestInfo request2; |
| 3196 | request2.method = "GET"; |
| 3197 | request2.url = GURL("https://www.google.com/2"); |
| 3198 | request2.load_flags = 0; |
| 3199 | |
| 3200 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3201 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3202 | LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3203 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3204 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3205 | |
| 3206 | // Fetch https://www.google.com/ via HTTP. |
| 3207 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3208 | "Host: www.google.com\r\n" |
| 3209 | "Connection: keep-alive\r\n\r\n"; |
| 3210 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3211 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3212 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3213 | "Content-Length: 1\r\n\r\n"; |
| 3214 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3215 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3216 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3217 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3218 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3219 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3220 | |
| 3221 | // Fetch https://www.google.com/2 via HTTP. |
| 3222 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3223 | "Host: www.google.com\r\n" |
| 3224 | "Connection: keep-alive\r\n\r\n"; |
| 3225 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3226 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3227 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3228 | "Content-Length: 2\r\n\r\n"; |
| 3229 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3230 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3231 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3232 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3233 | |
| 3234 | MockWrite spdy_writes[] = { |
| 3235 | CreateMockWrite(*connect1, 0), |
| 3236 | CreateMockWrite(*wrapped_get1, 2), |
| 3237 | CreateMockWrite(*wrapped_get2, 5), |
| 3238 | }; |
| 3239 | |
| 3240 | MockRead spdy_reads[] = { |
| 3241 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3242 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3243 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3244 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3245 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3246 | MockRead(ASYNC, 0, 8), |
| 3247 | }; |
| 3248 | |
| 3249 | DeterministicSocketData spdy_data( |
| 3250 | spdy_reads, arraysize(spdy_reads), |
| 3251 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3252 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3253 | |
| 3254 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3255 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3256 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3257 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3258 | ssl2.was_npn_negotiated = false; |
| 3259 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3260 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3261 | |
| 3262 | TestCompletionCallback callback; |
| 3263 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3264 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3265 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3266 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3268 | // The first connect and request, each of their responses, and the body. |
| 3269 | spdy_data.RunFor(5); |
| 3270 | |
| 3271 | rv = callback.WaitForResult(); |
| 3272 | EXPECT_EQ(OK, rv); |
| 3273 | |
| 3274 | LoadTimingInfo load_timing_info; |
| 3275 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3276 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3277 | |
| 3278 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3279 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3280 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3281 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3282 | |
| 3283 | std::string response_data; |
| 3284 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3285 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3286 | trans.reset(); |
| 3287 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3288 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3290 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3292 | |
| 3293 | // The second request, response, and body. There should not be a second |
| 3294 | // connect. |
| 3295 | spdy_data.RunFor(3); |
| 3296 | rv = callback.WaitForResult(); |
| 3297 | EXPECT_EQ(OK, rv); |
| 3298 | |
| 3299 | LoadTimingInfo load_timing_info2; |
| 3300 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3301 | TestLoadTimingReused(load_timing_info2); |
| 3302 | |
| 3303 | // The requests should have the same ID. |
| 3304 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3305 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3306 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 3310 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3311 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3312 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 3313 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3314 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3315 | "https://proxy:70")); |
| 3316 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3317 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3318 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3319 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3320 | |
| 3321 | HttpRequestInfo request1; |
| 3322 | request1.method = "GET"; |
| 3323 | request1.url = GURL("http://www.google.com/"); |
| 3324 | request1.load_flags = 0; |
| 3325 | |
| 3326 | HttpRequestInfo request2; |
| 3327 | request2.method = "GET"; |
| 3328 | request2.url = GURL("http://news.google.com/"); |
| 3329 | request2.load_flags = 0; |
| 3330 | |
| 3331 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3332 | scoped_ptr<SpdyHeaderBlock> headers( |
| 3333 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3334 | scoped_ptr<SpdyFrame> get1(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3335 | headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
| 3336 | scoped_ptr<SpdyFrame> get_resp1( |
| 3337 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3338 | scoped_ptr<SpdyFrame> body1( |
| 3339 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3340 | |
| 3341 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3342 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 3343 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 3344 | scoped_ptr<SpdyFrame> get2(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3345 | headers2.Pass(), false, 3, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
| 3346 | scoped_ptr<SpdyFrame> get_resp2( |
| 3347 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3348 | scoped_ptr<SpdyFrame> body2( |
| 3349 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3350 | |
| 3351 | MockWrite spdy_writes[] = { |
| 3352 | CreateMockWrite(*get1, 0), |
| 3353 | CreateMockWrite(*get2, 3), |
| 3354 | }; |
| 3355 | |
| 3356 | MockRead spdy_reads[] = { |
| 3357 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 3358 | CreateMockRead(*body1, 2, ASYNC), |
| 3359 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 3360 | CreateMockRead(*body2, 5, ASYNC), |
| 3361 | MockRead(ASYNC, 0, 6), |
| 3362 | }; |
| 3363 | |
| 3364 | DeterministicSocketData spdy_data( |
| 3365 | spdy_reads, arraysize(spdy_reads), |
| 3366 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3367 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3368 | |
| 3369 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3370 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3371 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3372 | |
| 3373 | TestCompletionCallback callback; |
| 3374 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3375 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3376 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3377 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3378 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3379 | spdy_data.RunFor(2); |
| 3380 | |
| 3381 | rv = callback.WaitForResult(); |
| 3382 | EXPECT_EQ(OK, rv); |
| 3383 | |
| 3384 | LoadTimingInfo load_timing_info; |
| 3385 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3386 | TestLoadTimingNotReused(load_timing_info, |
| 3387 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3388 | |
| 3389 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3390 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3391 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3392 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3393 | |
| 3394 | std::string response_data; |
| 3395 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3396 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3397 | spdy_data.RunFor(1); |
| 3398 | EXPECT_EQ(1, callback.WaitForResult()); |
| 3399 | // Delete the first request, so the second one can reuse the socket. |
| 3400 | trans.reset(); |
| 3401 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3402 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3403 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3404 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3405 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3406 | |
| 3407 | spdy_data.RunFor(2); |
| 3408 | rv = callback.WaitForResult(); |
| 3409 | EXPECT_EQ(OK, rv); |
| 3410 | |
| 3411 | LoadTimingInfo load_timing_info2; |
| 3412 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3413 | TestLoadTimingReused(load_timing_info2); |
| 3414 | |
| 3415 | // The requests should have the same ID. |
| 3416 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3417 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3418 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3419 | spdy_data.RunFor(1); |
| 3420 | EXPECT_EQ(2, callback.WaitForResult()); |
| 3421 | } |
| 3422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3423 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3424 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3425 | HttpRequestInfo request; |
| 3426 | request.method = "GET"; |
| 3427 | request.url = GURL("http://www.google.com/"); |
| 3428 | // when the no authentication data flag is set. |
| 3429 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3430 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3431 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3432 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3433 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3434 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3435 | session_deps_.net_log = log.bound().net_log(); |
| 3436 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3437 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3438 | // Since we have proxy, should use full url |
| 3439 | MockWrite data_writes1[] = { |
| 3440 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3441 | "Host: www.google.com\r\n" |
| 3442 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3443 | |
| 3444 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3445 | // be issuing -- the final header line contains the credentials. |
| 3446 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3447 | "Host: www.google.com\r\n" |
| 3448 | "Proxy-Connection: keep-alive\r\n" |
| 3449 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3450 | }; |
| 3451 | |
| 3452 | // The proxy responds to the GET with a 407, using a persistent |
| 3453 | // connection. |
| 3454 | MockRead data_reads1[] = { |
| 3455 | // No credentials. |
| 3456 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3457 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3458 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3459 | MockRead("Content-Length: 0\r\n\r\n"), |
| 3460 | |
| 3461 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3462 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3463 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3465 | }; |
| 3466 | |
| 3467 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3468 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3469 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3470 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3473 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3474 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3475 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3478 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3479 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3480 | |
| 3481 | rv = callback1.WaitForResult(); |
| 3482 | EXPECT_EQ(OK, rv); |
| 3483 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3484 | LoadTimingInfo load_timing_info; |
| 3485 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3486 | TestLoadTimingNotReused(load_timing_info, |
| 3487 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3488 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3490 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3491 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3492 | EXPECT_EQ(407, response->headers->response_code()); |
| 3493 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3494 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3496 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3498 | rv = trans->RestartWithAuth( |
| 3499 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3500 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3501 | |
| 3502 | rv = callback2.WaitForResult(); |
| 3503 | EXPECT_EQ(OK, rv); |
| 3504 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3505 | load_timing_info = LoadTimingInfo(); |
| 3506 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3507 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 3508 | TestLoadTimingReused(load_timing_info); |
| 3509 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3510 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3511 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3512 | |
| 3513 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3514 | EXPECT_EQ(200, response->headers->response_code()); |
| 3515 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3516 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3517 | |
| 3518 | // The password prompt info should not be set. |
| 3519 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3520 | } |
| 3521 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3522 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3523 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3524 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3525 | request.method = "GET"; |
| 3526 | request.url = GURL("https://www.google.com/"); |
| 3527 | request.load_flags = 0; |
| 3528 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3529 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3530 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3531 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3532 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3533 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3534 | // Since we have proxy, should try to establish tunnel. |
| 3535 | MockWrite data_writes[] = { |
| 3536 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 3537 | "Host: www.google.com\r\n" |
| 3538 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3539 | }; |
| 3540 | |
| 3541 | MockRead data_reads[] = { |
| 3542 | status, |
| 3543 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3544 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3545 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3546 | }; |
| 3547 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3548 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3549 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3550 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3552 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3553 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3554 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3555 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3557 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3558 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3559 | |
| 3560 | rv = callback.WaitForResult(); |
| 3561 | EXPECT_EQ(expected_status, rv); |
| 3562 | } |
| 3563 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3564 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3565 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3566 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3567 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3568 | } |
| 3569 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3570 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3571 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 3572 | } |
| 3573 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3574 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3575 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 3576 | } |
| 3577 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3578 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3579 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 3580 | } |
| 3581 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3582 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3583 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 3584 | } |
| 3585 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3586 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3587 | ConnectStatusHelper( |
| 3588 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 3589 | } |
| 3590 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3591 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3592 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 3593 | } |
| 3594 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3595 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3596 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 3597 | } |
| 3598 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3599 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3600 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 3601 | } |
| 3602 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3603 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3604 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 3605 | } |
| 3606 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3607 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3608 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 3609 | } |
| 3610 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3611 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3612 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 3613 | } |
| 3614 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3615 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3616 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 3617 | } |
| 3618 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3619 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3620 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 3621 | } |
| 3622 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3623 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3624 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 3625 | } |
| 3626 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3627 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3628 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 3629 | } |
| 3630 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3631 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3632 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 3633 | } |
| 3634 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3635 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3636 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 3637 | } |
| 3638 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3639 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3640 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 3641 | } |
| 3642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3643 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3644 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 3645 | } |
| 3646 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3647 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3648 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 3649 | } |
| 3650 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3651 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3652 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 3653 | } |
| 3654 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3655 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3656 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 3657 | } |
| 3658 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3659 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3660 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 3661 | } |
| 3662 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3663 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3664 | ConnectStatusHelperWithExpectedStatus( |
| 3665 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 3666 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3667 | } |
| 3668 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3669 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3670 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 3671 | } |
| 3672 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3673 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3674 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 3675 | } |
| 3676 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3677 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3678 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 3679 | } |
| 3680 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3681 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3682 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 3683 | } |
| 3684 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3685 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3686 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 3687 | } |
| 3688 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3689 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3690 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 3691 | } |
| 3692 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3693 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3694 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 3695 | } |
| 3696 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3697 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3698 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 3699 | } |
| 3700 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3701 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3702 | ConnectStatusHelper( |
| 3703 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 3704 | } |
| 3705 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3706 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3707 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 3708 | } |
| 3709 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3710 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3711 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 3712 | } |
| 3713 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3714 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3715 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 3716 | } |
| 3717 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3718 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3719 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 3720 | } |
| 3721 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3722 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3723 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 3724 | } |
| 3725 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3726 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3727 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 3728 | } |
| 3729 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3730 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3731 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 3732 | } |
| 3733 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3734 | // Test the flow when both the proxy server AND origin server require |
| 3735 | // authentication. Again, this uses basic auth for both since that is |
| 3736 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3737 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3738 | HttpRequestInfo request; |
| 3739 | request.method = "GET"; |
| 3740 | request.url = GURL("http://www.google.com/"); |
| 3741 | request.load_flags = 0; |
| 3742 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3743 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 3744 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3745 | // Configure against proxy server "myproxy:70". |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3746 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3747 | CreateSession(&session_deps_))); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3748 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 3749 | MockWrite data_writes1[] = { |
| 3750 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3751 | "Host: www.google.com\r\n" |
| 3752 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3753 | }; |
| 3754 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3755 | MockRead data_reads1[] = { |
| 3756 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 3757 | // Give a couple authenticate options (only the middle one is actually |
| 3758 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 3759 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3760 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3761 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 3762 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3763 | // Large content-length -- won't matter, as connection will be reset. |
| 3764 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3765 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3766 | }; |
| 3767 | |
| 3768 | // After calling trans->RestartWithAuth() the first time, this is the |
| 3769 | // request we should be issuing -- the final header line contains the |
| 3770 | // proxy's credentials. |
| 3771 | MockWrite data_writes2[] = { |
| 3772 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3773 | "Host: www.google.com\r\n" |
| 3774 | "Proxy-Connection: keep-alive\r\n" |
| 3775 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3776 | }; |
| 3777 | |
| 3778 | // Now the proxy server lets the request pass through to origin server. |
| 3779 | // The origin server responds with a 401. |
| 3780 | MockRead data_reads2[] = { |
| 3781 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 3782 | // Note: We are using the same realm-name as the proxy server. This is |
| 3783 | // completely valid, as realms are unique across hosts. |
| 3784 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3786 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3787 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3788 | }; |
| 3789 | |
| 3790 | // After calling trans->RestartWithAuth() the second time, we should send |
| 3791 | // the credentials for both the proxy and origin server. |
| 3792 | MockWrite data_writes3[] = { |
| 3793 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3794 | "Host: www.google.com\r\n" |
| 3795 | "Proxy-Connection: keep-alive\r\n" |
| 3796 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 3797 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 3798 | }; |
| 3799 | |
| 3800 | // Lastly we get the desired content. |
| 3801 | MockRead data_reads3[] = { |
| 3802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 3803 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3804 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3806 | }; |
| 3807 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3808 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3809 | data_writes1, arraysize(data_writes1)); |
| 3810 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3811 | data_writes2, arraysize(data_writes2)); |
| 3812 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 3813 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3814 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3816 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3818 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3820 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3822 | |
| 3823 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3824 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3825 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3826 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3827 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3828 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3830 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3832 | rv = trans->RestartWithAuth( |
| 3833 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3834 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3835 | |
| 3836 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3837 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3838 | |
| 3839 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3840 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3841 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3843 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3845 | rv = trans->RestartWithAuth( |
| 3846 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3847 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3848 | |
| 3849 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3850 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3851 | |
| 3852 | response = trans->GetResponseInfo(); |
| 3853 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3854 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 3855 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 3856 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 3857 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 3858 | // can't hook into its internals to cause it to generate predictable NTLM |
| 3859 | // authorization headers. |
| 3860 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3861 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 3862 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 3863 | // bytes in the debugger. |
| 3864 | |
| 3865 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3866 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3867 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3868 | request.method = "GET"; |
| 3869 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 3870 | request.load_flags = 0; |
| 3871 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3872 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 3873 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3874 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3875 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3876 | MockWrite data_writes1[] = { |
| 3877 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3878 | "Host: 172.22.68.17\r\n" |
| 3879 | "Connection: keep-alive\r\n\r\n"), |
| 3880 | }; |
| 3881 | |
| 3882 | MockRead data_reads1[] = { |
| 3883 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 3884 | // Negotiate and NTLM are often requested together. However, we only want |
| 3885 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 3886 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3887 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 3888 | MockRead("Connection: close\r\n"), |
| 3889 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 3890 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3891 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3892 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3893 | }; |
| 3894 | |
| 3895 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3896 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3897 | // request we should be issuing -- the final header line contains a Type |
| 3898 | // 1 message. |
| 3899 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3900 | "Host: 172.22.68.17\r\n" |
| 3901 | "Connection: keep-alive\r\n" |
| 3902 | "Authorization: NTLM " |
| 3903 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 3904 | |
| 3905 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 3906 | // (the credentials for the origin server). The second request continues |
| 3907 | // on the same connection. |
| 3908 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 3909 | "Host: 172.22.68.17\r\n" |
| 3910 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3911 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 3912 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 3913 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 3914 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 3915 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3916 | }; |
| 3917 | |
| 3918 | MockRead data_reads2[] = { |
| 3919 | // The origin server responds with a Type 2 message. |
| 3920 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 3921 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3922 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3923 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 3924 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 3925 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 3926 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 3927 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 3928 | "BtAAAAAAA=\r\n"), |
| 3929 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 3930 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3931 | MockRead("You are not authorized to view this page\r\n"), |
| 3932 | |
| 3933 | // Lastly we get the desired content. |
| 3934 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3935 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 3936 | MockRead("Content-Length: 13\r\n\r\n"), |
| 3937 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3938 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3939 | }; |
| 3940 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3941 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3942 | data_writes1, arraysize(data_writes1)); |
| 3943 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3944 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3946 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3948 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3949 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3950 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3951 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3953 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3954 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3955 | |
| 3956 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3957 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3958 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3959 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3960 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3961 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3962 | ASSERT_FALSE(response == NULL); |
| 3963 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3965 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3966 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 3967 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3968 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3970 | |
| 3971 | rv = callback2.WaitForResult(); |
| 3972 | EXPECT_EQ(OK, rv); |
| 3973 | |
| 3974 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3975 | |
| 3976 | response = trans->GetResponseInfo(); |
| 3977 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 3978 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3980 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3982 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3984 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 3985 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3986 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3987 | |
| 3988 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3989 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 3990 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3991 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 3992 | } |
| 3993 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3994 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3995 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3996 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 3997 | request.method = "GET"; |
| 3998 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 3999 | request.load_flags = 0; |
| 4000 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4001 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4002 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4003 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4004 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4005 | MockWrite data_writes1[] = { |
| 4006 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4007 | "Host: 172.22.68.17\r\n" |
| 4008 | "Connection: keep-alive\r\n\r\n"), |
| 4009 | }; |
| 4010 | |
| 4011 | MockRead data_reads1[] = { |
| 4012 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4013 | // Negotiate and NTLM are often requested together. However, we only want |
| 4014 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4015 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4016 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4017 | MockRead("Connection: close\r\n"), |
| 4018 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4019 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4020 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4021 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4022 | }; |
| 4023 | |
| 4024 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4025 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4026 | // request we should be issuing -- the final header line contains a Type |
| 4027 | // 1 message. |
| 4028 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4029 | "Host: 172.22.68.17\r\n" |
| 4030 | "Connection: keep-alive\r\n" |
| 4031 | "Authorization: NTLM " |
| 4032 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4033 | |
| 4034 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4035 | // (the credentials for the origin server). The second request continues |
| 4036 | // on the same connection. |
| 4037 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4038 | "Host: 172.22.68.17\r\n" |
| 4039 | "Connection: keep-alive\r\n" |
| 4040 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4041 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4042 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4043 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4044 | "4Ww7b7E=\r\n\r\n"), |
| 4045 | }; |
| 4046 | |
| 4047 | MockRead data_reads2[] = { |
| 4048 | // The origin server responds with a Type 2 message. |
| 4049 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4050 | MockRead("WWW-Authenticate: NTLM " |
| 4051 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4052 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4053 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4054 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4055 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4056 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4057 | "BtAAAAAAA=\r\n"), |
| 4058 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4059 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4060 | MockRead("You are not authorized to view this page\r\n"), |
| 4061 | |
| 4062 | // Wrong password. |
| 4063 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4064 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4065 | MockRead("Connection: close\r\n"), |
| 4066 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4067 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4068 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4069 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4070 | }; |
| 4071 | |
| 4072 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4073 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4074 | // request we should be issuing -- the final header line contains a Type |
| 4075 | // 1 message. |
| 4076 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4077 | "Host: 172.22.68.17\r\n" |
| 4078 | "Connection: keep-alive\r\n" |
| 4079 | "Authorization: NTLM " |
| 4080 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4081 | |
| 4082 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4083 | // (the credentials for the origin server). The second request continues |
| 4084 | // on the same connection. |
| 4085 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4086 | "Host: 172.22.68.17\r\n" |
| 4087 | "Connection: keep-alive\r\n" |
| 4088 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4089 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4090 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4091 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4092 | "+4MUm7c=\r\n\r\n"), |
| 4093 | }; |
| 4094 | |
| 4095 | MockRead data_reads3[] = { |
| 4096 | // The origin server responds with a Type 2 message. |
| 4097 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4098 | MockRead("WWW-Authenticate: NTLM " |
| 4099 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4100 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4101 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4102 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4103 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4104 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4105 | "BtAAAAAAA=\r\n"), |
| 4106 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4107 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4108 | MockRead("You are not authorized to view this page\r\n"), |
| 4109 | |
| 4110 | // Lastly we get the desired content. |
| 4111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4112 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4113 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4114 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4115 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4116 | }; |
| 4117 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4118 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4119 | data_writes1, arraysize(data_writes1)); |
| 4120 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4121 | data_writes2, arraysize(data_writes2)); |
| 4122 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4123 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4124 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4125 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4126 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4128 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4129 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4130 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4133 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4134 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4135 | |
| 4136 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4137 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4138 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4139 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4140 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4141 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4142 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4143 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4145 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4146 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4147 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4148 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4149 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4150 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4151 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4152 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4153 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4154 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4155 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4156 | TestCompletionCallback callback3; |
| 4157 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4159 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4160 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4161 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4162 | |
| 4163 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4164 | ASSERT_FALSE(response == NULL); |
| 4165 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4167 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4168 | |
| 4169 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4170 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4171 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4172 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4173 | |
| 4174 | rv = callback4.WaitForResult(); |
| 4175 | EXPECT_EQ(OK, rv); |
| 4176 | |
| 4177 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4179 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4180 | |
| 4181 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4182 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4184 | |
| 4185 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4186 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4187 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4188 | response = trans->GetResponseInfo(); |
| 4189 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4190 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4191 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4192 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4193 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4194 | // Test reading a server response which has only headers, and no body. |
| 4195 | // After some maximum number of bytes is consumed, the transaction should |
| 4196 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4197 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4198 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4199 | request.method = "GET"; |
| 4200 | request.url = GURL("http://www.google.com/"); |
| 4201 | request.load_flags = 0; |
| 4202 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4203 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4205 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4206 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4207 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4208 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4209 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4210 | |
| 4211 | MockRead data_reads[] = { |
| 4212 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4213 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4214 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4216 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4220 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4222 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4223 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4224 | |
| 4225 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4226 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4227 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4228 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4229 | EXPECT_TRUE(response == NULL); |
| 4230 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4231 | |
| 4232 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4233 | // establish tunnel. |
| 4234 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4235 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4236 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4237 | HttpRequestInfo request; |
| 4238 | request.method = "GET"; |
| 4239 | request.url = GURL("https://www.google.com/"); |
| 4240 | request.load_flags = 0; |
| 4241 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4242 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4243 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 4244 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4245 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4246 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4247 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4249 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4250 | // Since we have proxy, should try to establish tunnel. |
| 4251 | MockWrite data_writes1[] = { |
| 4252 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4253 | "Host: www.google.com\r\n" |
| 4254 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4255 | }; |
| 4256 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 4257 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4258 | // connection. Usually a proxy would return 501 (not implemented), |
| 4259 | // or 200 (tunnel established). |
| 4260 | MockRead data_reads1[] = { |
| 4261 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 4262 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4263 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4264 | }; |
| 4265 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4266 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4267 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4268 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4270 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4272 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4274 | |
| 4275 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4276 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4277 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4278 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4279 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4280 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4281 | // Empty the current queue. This is necessary because idle sockets are |
| 4282 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4283 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4284 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4285 | // We now check to make sure the TCPClientSocket was not added back to |
| 4286 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4287 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4288 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4289 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4290 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4291 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4292 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4293 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4294 | // 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] | 4295 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4296 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4297 | request.method = "GET"; |
| 4298 | request.url = GURL("http://www.google.com/"); |
| 4299 | request.load_flags = 0; |
| 4300 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4301 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4302 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4303 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4304 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4305 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4306 | MockRead data_reads[] = { |
| 4307 | // A part of the response body is received with the response headers. |
| 4308 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 4309 | // The rest of the response body is received in two parts. |
| 4310 | MockRead("lo"), |
| 4311 | MockRead(" world"), |
| 4312 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4313 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4314 | }; |
| 4315 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4319 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4320 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4321 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4322 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4323 | |
| 4324 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4325 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4326 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4327 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4328 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4329 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4330 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4331 | std::string status_line = response->headers->GetStatusLine(); |
| 4332 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 4333 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4334 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4335 | |
| 4336 | std::string response_data; |
| 4337 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4338 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4339 | EXPECT_EQ("hello world", response_data); |
| 4340 | |
| 4341 | // Empty the current queue. This is necessary because idle sockets are |
| 4342 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4343 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4344 | |
| 4345 | // 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] | 4346 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4347 | } |
| 4348 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4349 | // Make sure that we recycle a SSL socket after reading all of the response |
| 4350 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4351 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4352 | HttpRequestInfo request; |
| 4353 | request.method = "GET"; |
| 4354 | request.url = GURL("https://www.google.com/"); |
| 4355 | request.load_flags = 0; |
| 4356 | |
| 4357 | MockWrite data_writes[] = { |
| 4358 | MockWrite("GET / HTTP/1.1\r\n" |
| 4359 | "Host: www.google.com\r\n" |
| 4360 | "Connection: keep-alive\r\n\r\n"), |
| 4361 | }; |
| 4362 | |
| 4363 | MockRead data_reads[] = { |
| 4364 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4365 | MockRead("Content-Length: 11\r\n\r\n"), |
| 4366 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4367 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4368 | }; |
| 4369 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4370 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4372 | |
| 4373 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4374 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4375 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4377 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4378 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4379 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4380 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4381 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4384 | |
| 4385 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4386 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4387 | |
| 4388 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4389 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4390 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4391 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4392 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4393 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4394 | |
| 4395 | std::string response_data; |
| 4396 | rv = ReadTransaction(trans.get(), &response_data); |
| 4397 | EXPECT_EQ(OK, rv); |
| 4398 | EXPECT_EQ("hello world", response_data); |
| 4399 | |
| 4400 | // Empty the current queue. This is necessary because idle sockets are |
| 4401 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4402 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4403 | |
| 4404 | // 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] | 4405 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 4409 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4410 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4411 | HttpRequestInfo request; |
| 4412 | request.method = "GET"; |
| 4413 | request.url = GURL("https://www.google.com/"); |
| 4414 | request.load_flags = 0; |
| 4415 | |
| 4416 | MockWrite data_writes[] = { |
| 4417 | MockWrite("GET / HTTP/1.1\r\n" |
| 4418 | "Host: www.google.com\r\n" |
| 4419 | "Connection: keep-alive\r\n\r\n"), |
| 4420 | MockWrite("GET / HTTP/1.1\r\n" |
| 4421 | "Host: www.google.com\r\n" |
| 4422 | "Connection: keep-alive\r\n\r\n"), |
| 4423 | }; |
| 4424 | |
| 4425 | MockRead data_reads[] = { |
| 4426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4427 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4428 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4429 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4430 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4431 | }; |
| 4432 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4433 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4434 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4437 | |
| 4438 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4439 | data_writes, arraysize(data_writes)); |
| 4440 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 4441 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4442 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4443 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4445 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4446 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4447 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4448 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4449 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4451 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4452 | |
| 4453 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4454 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4455 | |
| 4456 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4457 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4458 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4459 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4460 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4461 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4462 | |
| 4463 | std::string response_data; |
| 4464 | rv = ReadTransaction(trans.get(), &response_data); |
| 4465 | EXPECT_EQ(OK, rv); |
| 4466 | EXPECT_EQ("hello world", response_data); |
| 4467 | |
| 4468 | // Empty the current queue. This is necessary because idle sockets are |
| 4469 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4470 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4471 | |
| 4472 | // 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] | 4473 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4474 | |
| 4475 | // Now start the second transaction, which should reuse the previous socket. |
| 4476 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4477 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4479 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4480 | |
| 4481 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4482 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4483 | |
| 4484 | response = trans->GetResponseInfo(); |
| 4485 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4486 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4487 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4488 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4489 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4490 | |
| 4491 | rv = ReadTransaction(trans.get(), &response_data); |
| 4492 | EXPECT_EQ(OK, rv); |
| 4493 | EXPECT_EQ("hello world", response_data); |
| 4494 | |
| 4495 | // Empty the current queue. This is necessary because idle sockets are |
| 4496 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4497 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4498 | |
| 4499 | // 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] | 4500 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4501 | } |
| 4502 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4503 | // Make sure that we recycle a socket after a zero-length response. |
| 4504 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4505 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4506 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4507 | request.method = "GET"; |
| 4508 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 4509 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 4510 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 4511 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 4512 | request.load_flags = 0; |
| 4513 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4514 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4515 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4516 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4517 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4518 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4519 | MockRead data_reads[] = { |
| 4520 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 4521 | "Content-Length: 0\r\n" |
| 4522 | "Content-Type: text/html\r\n\r\n"), |
| 4523 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4524 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4525 | }; |
| 4526 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4527 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4528 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4530 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4532 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4533 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4534 | |
| 4535 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4536 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4537 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4538 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4539 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4540 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4541 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4542 | std::string status_line = response->headers->GetStatusLine(); |
| 4543 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 4544 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4545 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4546 | |
| 4547 | std::string response_data; |
| 4548 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4549 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4550 | EXPECT_EQ("", response_data); |
| 4551 | |
| 4552 | // Empty the current queue. This is necessary because idle sockets are |
| 4553 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4554 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4555 | |
| 4556 | // 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] | 4557 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4558 | } |
| 4559 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4560 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 4561 | ScopedVector<UploadElementReader> element_readers; |
| 4562 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 4563 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 4564 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4565 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4566 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 4567 | // after use. |
| 4568 | request[0].method = "GET"; |
| 4569 | request[0].url = GURL("http://www.google.com/"); |
| 4570 | request[0].load_flags = 0; |
| 4571 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 4572 | // transaction 1. The first attempts fails when writing the POST data. |
| 4573 | // This causes the transaction to retry with a new socket. The second |
| 4574 | // attempt succeeds. |
| 4575 | request[1].method = "POST"; |
| 4576 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 4577 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4578 | request[1].load_flags = 0; |
| 4579 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4580 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4581 | |
| 4582 | // The first socket is used for transaction 1 and the first attempt of |
| 4583 | // transaction 2. |
| 4584 | |
| 4585 | // The response of transaction 1. |
| 4586 | MockRead data_reads1[] = { |
| 4587 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 4588 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4590 | }; |
| 4591 | // The mock write results of transaction 1 and the first attempt of |
| 4592 | // transaction 2. |
| 4593 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4594 | MockWrite(SYNCHRONOUS, 64), // GET |
| 4595 | MockWrite(SYNCHRONOUS, 93), // POST |
| 4596 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4597 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4598 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4599 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4600 | |
| 4601 | // The second socket is used for the second attempt of transaction 2. |
| 4602 | |
| 4603 | // The response of transaction 2. |
| 4604 | MockRead data_reads2[] = { |
| 4605 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 4606 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4608 | }; |
| 4609 | // The mock write results of the second attempt of transaction 2. |
| 4610 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4611 | MockWrite(SYNCHRONOUS, 93), // POST |
| 4612 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4613 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4614 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4615 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4616 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4617 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4618 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4619 | |
| 4620 | const char* kExpectedResponseData[] = { |
| 4621 | "hello world", "welcome" |
| 4622 | }; |
| 4623 | |
| 4624 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4625 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4628 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4630 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4631 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4632 | |
| 4633 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4634 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4635 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4636 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4637 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4638 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4639 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4640 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4641 | |
| 4642 | std::string response_data; |
| 4643 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4644 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4645 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 4646 | } |
| 4647 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4648 | |
| 4649 | // Test the request-challenge-retry sequence for basic auth when there is |
| 4650 | // 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] | 4651 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4652 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4653 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4654 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4655 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 4656 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4657 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4658 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4659 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4660 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4661 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 4662 | // The password contains an escaped character -- for this test to pass it |
| 4663 | // will need to be unescaped by HttpNetworkTransaction. |
| 4664 | EXPECT_EQ("b%40r", request.url.password()); |
| 4665 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4666 | MockWrite data_writes1[] = { |
| 4667 | MockWrite("GET / HTTP/1.1\r\n" |
| 4668 | "Host: www.google.com\r\n" |
| 4669 | "Connection: keep-alive\r\n\r\n"), |
| 4670 | }; |
| 4671 | |
| 4672 | MockRead data_reads1[] = { |
| 4673 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4674 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4675 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4676 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4677 | }; |
| 4678 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4679 | // After the challenge above, the transaction will be restarted using the |
| 4680 | // identity from the url (foo, b@r) to answer the challenge. |
| 4681 | MockWrite data_writes2[] = { |
| 4682 | MockWrite("GET / HTTP/1.1\r\n" |
| 4683 | "Host: www.google.com\r\n" |
| 4684 | "Connection: keep-alive\r\n" |
| 4685 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 4686 | }; |
| 4687 | |
| 4688 | MockRead data_reads2[] = { |
| 4689 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4690 | MockRead("Content-Length: 100\r\n\r\n"), |
| 4691 | MockRead(SYNCHRONOUS, OK), |
| 4692 | }; |
| 4693 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4694 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4695 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4696 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4697 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4701 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4702 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4704 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4705 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4706 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4707 | |
| 4708 | TestCompletionCallback callback2; |
| 4709 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 4710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4711 | rv = callback2.WaitForResult(); |
| 4712 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4713 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4714 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4715 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4716 | ASSERT_TRUE(response != NULL); |
| 4717 | |
| 4718 | // There is no challenge info, since the identity in URL worked. |
| 4719 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4720 | |
| 4721 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4722 | |
| 4723 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4724 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 4728 | // incorrect identity in the URL. The identity from the URL should be used only |
| 4729 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4730 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4731 | HttpRequestInfo request; |
| 4732 | request.method = "GET"; |
| 4733 | // Note: the URL has a username:password in it. The password "baz" is |
| 4734 | // wrong (should be "bar"). |
| 4735 | request.url = GURL("http://foo:[email protected]/"); |
| 4736 | |
| 4737 | request.load_flags = LOAD_NORMAL; |
| 4738 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4739 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4740 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4741 | CreateSession(&session_deps_))); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4742 | |
| 4743 | MockWrite data_writes1[] = { |
| 4744 | MockWrite("GET / HTTP/1.1\r\n" |
| 4745 | "Host: www.google.com\r\n" |
| 4746 | "Connection: keep-alive\r\n\r\n"), |
| 4747 | }; |
| 4748 | |
| 4749 | MockRead data_reads1[] = { |
| 4750 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4751 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4752 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4753 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 4754 | }; |
| 4755 | |
| 4756 | // After the challenge above, the transaction will be restarted using the |
| 4757 | // identity from the url (foo, baz) to answer the challenge. |
| 4758 | MockWrite data_writes2[] = { |
| 4759 | MockWrite("GET / HTTP/1.1\r\n" |
| 4760 | "Host: www.google.com\r\n" |
| 4761 | "Connection: keep-alive\r\n" |
| 4762 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 4763 | }; |
| 4764 | |
| 4765 | MockRead data_reads2[] = { |
| 4766 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4767 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4768 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4769 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 4770 | }; |
| 4771 | |
| 4772 | // After the challenge above, the transaction will be restarted using the |
| 4773 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 4774 | MockWrite data_writes3[] = { |
| 4775 | MockWrite("GET / HTTP/1.1\r\n" |
| 4776 | "Host: www.google.com\r\n" |
| 4777 | "Connection: keep-alive\r\n" |
| 4778 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4779 | }; |
| 4780 | |
| 4781 | MockRead data_reads3[] = { |
| 4782 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4783 | MockRead("Content-Length: 100\r\n\r\n"), |
| 4784 | MockRead(SYNCHRONOUS, OK), |
| 4785 | }; |
| 4786 | |
| 4787 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4788 | data_writes1, arraysize(data_writes1)); |
| 4789 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4790 | data_writes2, arraysize(data_writes2)); |
| 4791 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4792 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4793 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4794 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4795 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 4796 | |
| 4797 | TestCompletionCallback callback1; |
| 4798 | |
| 4799 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 4800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4801 | |
| 4802 | rv = callback1.WaitForResult(); |
| 4803 | EXPECT_EQ(OK, rv); |
| 4804 | |
| 4805 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4806 | TestCompletionCallback callback2; |
| 4807 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 4808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4809 | rv = callback2.WaitForResult(); |
| 4810 | EXPECT_EQ(OK, rv); |
| 4811 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4812 | |
| 4813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4814 | ASSERT_TRUE(response != NULL); |
| 4815 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 4816 | |
| 4817 | TestCompletionCallback callback3; |
| 4818 | rv = trans->RestartWithAuth( |
| 4819 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 4820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4821 | rv = callback3.WaitForResult(); |
| 4822 | EXPECT_EQ(OK, rv); |
| 4823 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4824 | |
| 4825 | response = trans->GetResponseInfo(); |
| 4826 | ASSERT_TRUE(response != NULL); |
| 4827 | |
| 4828 | // There is no challenge info, since the identity worked. |
| 4829 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4830 | |
| 4831 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4832 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4833 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4834 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4835 | } |
| 4836 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4837 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4838 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4839 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4840 | |
| 4841 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 4842 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4843 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4844 | request.method = "GET"; |
| 4845 | request.url = GURL("http://www.google.com/x/y/z"); |
| 4846 | request.load_flags = 0; |
| 4847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4850 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4851 | MockWrite data_writes1[] = { |
| 4852 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 4853 | "Host: www.google.com\r\n" |
| 4854 | "Connection: keep-alive\r\n\r\n"), |
| 4855 | }; |
| 4856 | |
| 4857 | MockRead data_reads1[] = { |
| 4858 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4859 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4860 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4861 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4862 | }; |
| 4863 | |
| 4864 | // Resend with authorization (username=foo, password=bar) |
| 4865 | MockWrite data_writes2[] = { |
| 4866 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 4867 | "Host: www.google.com\r\n" |
| 4868 | "Connection: keep-alive\r\n" |
| 4869 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4870 | }; |
| 4871 | |
| 4872 | // Sever accepts the authorization. |
| 4873 | MockRead data_reads2[] = { |
| 4874 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4875 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4876 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4877 | }; |
| 4878 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4879 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4880 | data_writes1, arraysize(data_writes1)); |
| 4881 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4882 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4884 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4886 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4888 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4889 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4890 | |
| 4891 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4892 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4893 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4894 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4895 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4896 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4898 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4900 | rv = trans->RestartWithAuth( |
| 4901 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4902 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4903 | |
| 4904 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4905 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4906 | |
| 4907 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4908 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4909 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4910 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4911 | } |
| 4912 | |
| 4913 | // ------------------------------------------------------------------------ |
| 4914 | |
| 4915 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 4916 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4917 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4918 | request.method = "GET"; |
| 4919 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 4920 | // protection space as MyRealm1. |
| 4921 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 4922 | request.load_flags = 0; |
| 4923 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4924 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4925 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4926 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4927 | MockWrite data_writes1[] = { |
| 4928 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 4929 | "Host: www.google.com\r\n" |
| 4930 | "Connection: keep-alive\r\n" |
| 4931 | // Send preemptive authorization for MyRealm1 |
| 4932 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4933 | }; |
| 4934 | |
| 4935 | // The server didn't like the preemptive authorization, and |
| 4936 | // challenges us for a different realm (MyRealm2). |
| 4937 | MockRead data_reads1[] = { |
| 4938 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4939 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 4940 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4941 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4942 | }; |
| 4943 | |
| 4944 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 4945 | MockWrite data_writes2[] = { |
| 4946 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 4947 | "Host: www.google.com\r\n" |
| 4948 | "Connection: keep-alive\r\n" |
| 4949 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4950 | }; |
| 4951 | |
| 4952 | // Sever accepts the authorization. |
| 4953 | MockRead data_reads2[] = { |
| 4954 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4955 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4956 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4957 | }; |
| 4958 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4959 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4960 | data_writes1, arraysize(data_writes1)); |
| 4961 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4962 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4963 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4964 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4966 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4968 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4970 | |
| 4971 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4972 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4973 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4974 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4975 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4976 | ASSERT_TRUE(response->auth_challenge.get()); |
| 4977 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4978 | EXPECT_EQ("www.google.com:80", |
| 4979 | response->auth_challenge->challenger.ToString()); |
| 4980 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 4981 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4983 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4985 | rv = trans->RestartWithAuth( |
| 4986 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4987 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4988 | |
| 4989 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4990 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4991 | |
| 4992 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4993 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4994 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4995 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4996 | } |
| 4997 | |
| 4998 | // ------------------------------------------------------------------------ |
| 4999 | |
| 5000 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5001 | // succeed with preemptive authorization. |
| 5002 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5003 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5004 | request.method = "GET"; |
| 5005 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5006 | request.load_flags = 0; |
| 5007 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5008 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5009 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5010 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5011 | MockWrite data_writes1[] = { |
| 5012 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5013 | "Host: www.google.com\r\n" |
| 5014 | "Connection: keep-alive\r\n" |
| 5015 | // The authorization for MyRealm1 gets sent preemptively |
| 5016 | // (since the url is in the same protection space) |
| 5017 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5018 | }; |
| 5019 | |
| 5020 | // Sever accepts the preemptive authorization |
| 5021 | MockRead data_reads1[] = { |
| 5022 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5023 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5025 | }; |
| 5026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5028 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5031 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5033 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5034 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5035 | |
| 5036 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5037 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5038 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5039 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5040 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5041 | |
| 5042 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5043 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5044 | } |
| 5045 | |
| 5046 | // ------------------------------------------------------------------------ |
| 5047 | |
| 5048 | // Transaction 4: request another URL in MyRealm (however the |
| 5049 | // url is not known to belong to the protection space, so no pre-auth). |
| 5050 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5051 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5052 | request.method = "GET"; |
| 5053 | request.url = GURL("http://www.google.com/x/1"); |
| 5054 | request.load_flags = 0; |
| 5055 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5056 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5057 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5058 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5059 | MockWrite data_writes1[] = { |
| 5060 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5061 | "Host: www.google.com\r\n" |
| 5062 | "Connection: keep-alive\r\n\r\n"), |
| 5063 | }; |
| 5064 | |
| 5065 | MockRead data_reads1[] = { |
| 5066 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5067 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5068 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5069 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5070 | }; |
| 5071 | |
| 5072 | // Resend with authorization from MyRealm's cache. |
| 5073 | MockWrite data_writes2[] = { |
| 5074 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5075 | "Host: www.google.com\r\n" |
| 5076 | "Connection: keep-alive\r\n" |
| 5077 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5078 | }; |
| 5079 | |
| 5080 | // Sever accepts the authorization. |
| 5081 | MockRead data_reads2[] = { |
| 5082 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5083 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5084 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5085 | }; |
| 5086 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5088 | data_writes1, arraysize(data_writes1)); |
| 5089 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5090 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5091 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5092 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5094 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5096 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5097 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5098 | |
| 5099 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5100 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5101 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5102 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5103 | TestCompletionCallback callback2; |
| 5104 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5106 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5107 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5108 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5109 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5110 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5111 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5112 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5113 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5114 | } |
| 5115 | |
| 5116 | // ------------------------------------------------------------------------ |
| 5117 | |
| 5118 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5119 | // cached identity. Should invalidate and re-prompt. |
| 5120 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5121 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5122 | request.method = "GET"; |
| 5123 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5124 | request.load_flags = 0; |
| 5125 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5126 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5127 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5128 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5129 | MockWrite data_writes1[] = { |
| 5130 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5131 | "Host: www.google.com\r\n" |
| 5132 | "Connection: keep-alive\r\n\r\n"), |
| 5133 | }; |
| 5134 | |
| 5135 | MockRead data_reads1[] = { |
| 5136 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5137 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5138 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5139 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5140 | }; |
| 5141 | |
| 5142 | // Resend with authorization from cache for MyRealm. |
| 5143 | MockWrite data_writes2[] = { |
| 5144 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5145 | "Host: www.google.com\r\n" |
| 5146 | "Connection: keep-alive\r\n" |
| 5147 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5148 | }; |
| 5149 | |
| 5150 | // Sever rejects the authorization. |
| 5151 | MockRead data_reads2[] = { |
| 5152 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5153 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5154 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5155 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5156 | }; |
| 5157 | |
| 5158 | // At this point we should prompt for new credentials for MyRealm. |
| 5159 | // Restart with username=foo3, password=foo4. |
| 5160 | MockWrite data_writes3[] = { |
| 5161 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5162 | "Host: www.google.com\r\n" |
| 5163 | "Connection: keep-alive\r\n" |
| 5164 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 5165 | }; |
| 5166 | |
| 5167 | // Sever accepts the authorization. |
| 5168 | MockRead data_reads3[] = { |
| 5169 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5170 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5171 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5172 | }; |
| 5173 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5174 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5175 | data_writes1, arraysize(data_writes1)); |
| 5176 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5177 | data_writes2, arraysize(data_writes2)); |
| 5178 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5179 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5180 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5181 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5182 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5184 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5186 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5187 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5188 | |
| 5189 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5190 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5191 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5192 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5193 | TestCompletionCallback callback2; |
| 5194 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5195 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5196 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5197 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5198 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5199 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5200 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5201 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5202 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5204 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5206 | rv = trans->RestartWithAuth( |
| 5207 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5208 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5209 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5210 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5211 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5212 | |
| 5213 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5214 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5215 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5216 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5217 | } |
| 5218 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5219 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5220 | // Tests that nonce count increments when multiple auth attempts |
| 5221 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5222 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 5223 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 5224 | new HttpAuthHandlerDigest::Factory(); |
| 5225 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 5226 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 5227 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5228 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 5229 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5230 | |
| 5231 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5232 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5233 | HttpRequestInfo request; |
| 5234 | request.method = "GET"; |
| 5235 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5236 | request.load_flags = 0; |
| 5237 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5238 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5240 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5241 | MockWrite data_writes1[] = { |
| 5242 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5243 | "Host: www.google.com\r\n" |
| 5244 | "Connection: keep-alive\r\n\r\n"), |
| 5245 | }; |
| 5246 | |
| 5247 | MockRead data_reads1[] = { |
| 5248 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5249 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 5250 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5251 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5252 | }; |
| 5253 | |
| 5254 | // Resend with authorization (username=foo, password=bar) |
| 5255 | MockWrite data_writes2[] = { |
| 5256 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5257 | "Host: www.google.com\r\n" |
| 5258 | "Connection: keep-alive\r\n" |
| 5259 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5260 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 5261 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 5262 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5263 | }; |
| 5264 | |
| 5265 | // Sever accepts the authorization. |
| 5266 | MockRead data_reads2[] = { |
| 5267 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5268 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5269 | }; |
| 5270 | |
| 5271 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5272 | data_writes1, arraysize(data_writes1)); |
| 5273 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5274 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5275 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5276 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5278 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5280 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5281 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5282 | |
| 5283 | rv = callback1.WaitForResult(); |
| 5284 | EXPECT_EQ(OK, rv); |
| 5285 | |
| 5286 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5287 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5288 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5290 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5292 | rv = trans->RestartWithAuth( |
| 5293 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5295 | |
| 5296 | rv = callback2.WaitForResult(); |
| 5297 | EXPECT_EQ(OK, rv); |
| 5298 | |
| 5299 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5300 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5301 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5302 | } |
| 5303 | |
| 5304 | // ------------------------------------------------------------------------ |
| 5305 | |
| 5306 | // Transaction 2: Request another resource in digestive's protection space. |
| 5307 | // This will preemptively add an Authorization header which should have an |
| 5308 | // "nc" value of 2 (as compared to 1 in the first use. |
| 5309 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5310 | HttpRequestInfo request; |
| 5311 | request.method = "GET"; |
| 5312 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5313 | // protection space as digest. |
| 5314 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5315 | request.load_flags = 0; |
| 5316 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5317 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5318 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5319 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5320 | MockWrite data_writes1[] = { |
| 5321 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5322 | "Host: www.google.com\r\n" |
| 5323 | "Connection: keep-alive\r\n" |
| 5324 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5325 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 5326 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 5327 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5328 | }; |
| 5329 | |
| 5330 | // Sever accepts the authorization. |
| 5331 | MockRead data_reads1[] = { |
| 5332 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5333 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5334 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5335 | }; |
| 5336 | |
| 5337 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5338 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5339 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5341 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5343 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5344 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5345 | |
| 5346 | rv = callback1.WaitForResult(); |
| 5347 | EXPECT_EQ(OK, rv); |
| 5348 | |
| 5349 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5350 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5351 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5352 | } |
| 5353 | } |
| 5354 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5355 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5356 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5357 | // Create a transaction (the dependencies aren't important). |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5358 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5360 | CreateSession(&session_deps_))); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5361 | |
| 5362 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5363 | trans->read_buf_ = new IOBuffer(15); |
| 5364 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5365 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5366 | |
| 5367 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 5368 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5369 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5370 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5371 | response->response_time = base::Time::Now(); |
| 5372 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5373 | |
| 5374 | { // Setup state for response_.vary_data |
| 5375 | HttpRequestInfo request; |
| 5376 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 5377 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 5378 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 5379 | request.extra_headers.SetHeader("Foo", "1"); |
| 5380 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5381 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | // Cause the above state to be reset. |
| 5385 | trans->ResetStateForRestart(); |
| 5386 | |
| 5387 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 5388 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5389 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5390 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5391 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5392 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 5393 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5394 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5395 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5396 | } |
| 5397 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5398 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5399 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5400 | HttpRequestInfo request; |
| 5401 | request.method = "GET"; |
| 5402 | request.url = GURL("https://www.google.com/"); |
| 5403 | request.load_flags = 0; |
| 5404 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5405 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5406 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5408 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5409 | MockWrite data_writes[] = { |
| 5410 | MockWrite("GET / HTTP/1.1\r\n" |
| 5411 | "Host: www.google.com\r\n" |
| 5412 | "Connection: keep-alive\r\n\r\n"), |
| 5413 | }; |
| 5414 | |
| 5415 | MockRead data_reads[] = { |
| 5416 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5417 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5418 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5419 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5420 | }; |
| 5421 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 5422 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5423 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5424 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5425 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5426 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5427 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5428 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5429 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5433 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5435 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5436 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5437 | |
| 5438 | rv = callback.WaitForResult(); |
| 5439 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5441 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5443 | |
| 5444 | rv = callback.WaitForResult(); |
| 5445 | EXPECT_EQ(OK, rv); |
| 5446 | |
| 5447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5448 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5449 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5450 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5451 | } |
| 5452 | |
| 5453 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 5454 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5455 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5457 | |
| 5458 | HttpRequestInfo request; |
| 5459 | request.method = "GET"; |
| 5460 | request.url = GURL("https://www.google.com/"); |
| 5461 | request.load_flags = 0; |
| 5462 | |
| 5463 | MockWrite proxy_writes[] = { |
| 5464 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5465 | "Host: www.google.com\r\n" |
| 5466 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5467 | }; |
| 5468 | |
| 5469 | MockRead proxy_reads[] = { |
| 5470 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5471 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5472 | }; |
| 5473 | |
| 5474 | MockWrite data_writes[] = { |
| 5475 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5476 | "Host: www.google.com\r\n" |
| 5477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5478 | MockWrite("GET / HTTP/1.1\r\n" |
| 5479 | "Host: www.google.com\r\n" |
| 5480 | "Connection: keep-alive\r\n\r\n"), |
| 5481 | }; |
| 5482 | |
| 5483 | MockRead data_reads[] = { |
| 5484 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 5485 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5487 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5488 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5489 | }; |
| 5490 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5491 | StaticSocketDataProvider ssl_bad_certificate( |
| 5492 | proxy_reads, arraysize(proxy_reads), |
| 5493 | proxy_writes, arraysize(proxy_writes)); |
| 5494 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5495 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5496 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5497 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5498 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5499 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5503 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5504 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5505 | |
| 5506 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5507 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5508 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5511 | CreateSession(&session_deps_))); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5513 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5514 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5515 | |
| 5516 | rv = callback.WaitForResult(); |
| 5517 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5519 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5521 | |
| 5522 | rv = callback.WaitForResult(); |
| 5523 | EXPECT_EQ(OK, rv); |
| 5524 | |
| 5525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5526 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5527 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5528 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5529 | } |
| 5530 | } |
| 5531 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5532 | |
| 5533 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5534 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5535 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5536 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 5537 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5538 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5539 | |
| 5540 | HttpRequestInfo request; |
| 5541 | request.method = "GET"; |
| 5542 | request.url = GURL("https://www.google.com/"); |
| 5543 | request.load_flags = 0; |
| 5544 | |
| 5545 | MockWrite data_writes[] = { |
| 5546 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5547 | "Host: www.google.com\r\n" |
| 5548 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5549 | MockWrite("GET / HTTP/1.1\r\n" |
| 5550 | "Host: www.google.com\r\n" |
| 5551 | "Connection: keep-alive\r\n\r\n"), |
| 5552 | }; |
| 5553 | |
| 5554 | MockRead data_reads[] = { |
| 5555 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 5556 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5557 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5558 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5559 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5560 | }; |
| 5561 | |
| 5562 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5563 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5564 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 5565 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5566 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 5569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5571 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5572 | |
| 5573 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5574 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5575 | CreateSession(&session_deps_))); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5577 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5578 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5579 | |
| 5580 | rv = callback.WaitForResult(); |
| 5581 | EXPECT_EQ(OK, rv); |
| 5582 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5583 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5584 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5585 | |
| 5586 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5587 | EXPECT_EQ(200, response->headers->response_code()); |
| 5588 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5589 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5590 | |
| 5591 | LoadTimingInfo load_timing_info; |
| 5592 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5593 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5594 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5595 | } |
| 5596 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5597 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5598 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5599 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5600 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 5601 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5602 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5603 | |
| 5604 | HttpRequestInfo request; |
| 5605 | request.method = "GET"; |
| 5606 | request.url = GURL("https://www.google.com/"); |
| 5607 | request.load_flags = 0; |
| 5608 | |
| 5609 | MockWrite data_writes[] = { |
| 5610 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5611 | "Host: www.google.com\r\n" |
| 5612 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5613 | }; |
| 5614 | |
| 5615 | MockRead data_reads[] = { |
| 5616 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 5617 | MockRead("Location: http://login.example.com/\r\n"), |
| 5618 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5619 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5620 | }; |
| 5621 | |
| 5622 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5623 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5624 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5625 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5629 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5630 | |
| 5631 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5632 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5633 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5635 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5636 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5637 | |
| 5638 | rv = callback.WaitForResult(); |
| 5639 | EXPECT_EQ(OK, rv); |
| 5640 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5641 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5642 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5643 | |
| 5644 | EXPECT_EQ(302, response->headers->response_code()); |
| 5645 | std::string url; |
| 5646 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 5647 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5648 | |
| 5649 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 5650 | // timing for the proxy connection instead of the connection to the host, |
| 5651 | // and no send / receive times. |
| 5652 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 5653 | LoadTimingInfo load_timing_info; |
| 5654 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5655 | |
| 5656 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 5657 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 5658 | |
| 5659 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 5660 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 5661 | load_timing_info.proxy_resolve_end); |
| 5662 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 5663 | load_timing_info.connect_timing.connect_start); |
| 5664 | ExpectConnectTimingHasTimes( |
| 5665 | load_timing_info.connect_timing, |
| 5666 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5667 | |
| 5668 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 5669 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 5670 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5674 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5675 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5676 | ProxyService::CreateFixed("https://proxy:70")); |
| 5677 | |
| 5678 | HttpRequestInfo request; |
| 5679 | request.method = "GET"; |
| 5680 | request.url = GURL("https://www.google.com/"); |
| 5681 | request.load_flags = 0; |
| 5682 | |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 5683 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 5684 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5685 | scoped_ptr<SpdyFrame> goaway( |
| 5686 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5687 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5688 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 5689 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5690 | }; |
| 5691 | |
| 5692 | static const char* const kExtraHeaders[] = { |
| 5693 | "location", |
| 5694 | "http://login.example.com/", |
| 5695 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5696 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5697 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5698 | arraysize(kExtraHeaders)/2, 1)); |
| 5699 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5700 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 5701 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5702 | }; |
| 5703 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5704 | DelayedSocketData data( |
| 5705 | 1, // wait for one write to finish before reading. |
| 5706 | data_reads, arraysize(data_reads), |
| 5707 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5708 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5709 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5710 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5714 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5715 | |
| 5716 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5718 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5720 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5722 | |
| 5723 | rv = callback.WaitForResult(); |
| 5724 | EXPECT_EQ(OK, rv); |
| 5725 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5726 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5727 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5728 | |
| 5729 | EXPECT_EQ(302, response->headers->response_code()); |
| 5730 | std::string url; |
| 5731 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 5732 | EXPECT_EQ("http://login.example.com/", url); |
| 5733 | } |
| 5734 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5735 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5736 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5737 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5738 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5739 | ProxyService::CreateFixed("https://proxy:70")); |
| 5740 | |
| 5741 | HttpRequestInfo request; |
| 5742 | request.method = "GET"; |
| 5743 | request.url = GURL("https://www.google.com/"); |
| 5744 | request.load_flags = 0; |
| 5745 | |
| 5746 | MockWrite data_writes[] = { |
| 5747 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 5748 | "Host: www.google.com\r\n" |
| 5749 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5750 | }; |
| 5751 | |
| 5752 | MockRead data_reads[] = { |
| 5753 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5754 | MockRead("Content-Length: 23\r\n\r\n"), |
| 5755 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5756 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5757 | }; |
| 5758 | |
| 5759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5760 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5761 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5762 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5766 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5767 | |
| 5768 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5769 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5770 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5772 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5774 | |
| 5775 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5776 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5777 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5778 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5779 | } |
| 5780 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5781 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5782 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5783 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5784 | session_deps_.proxy_service.reset( |
| 5785 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5786 | |
| 5787 | HttpRequestInfo request; |
| 5788 | request.method = "GET"; |
| 5789 | request.url = GURL("https://www.google.com/"); |
| 5790 | request.load_flags = 0; |
| 5791 | |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 5792 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 5793 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5794 | scoped_ptr<SpdyFrame> rst( |
| 5795 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5796 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5797 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5798 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5799 | }; |
| 5800 | |
| 5801 | static const char* const kExtraHeaders[] = { |
| 5802 | "location", |
| 5803 | "http://login.example.com/", |
| 5804 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5805 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5806 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5807 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5808 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5809 | spdy_util_.ConstructSpdyBodyFrame( |
| 5810 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5811 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5812 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 5813 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5814 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5815 | }; |
| 5816 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5817 | DelayedSocketData data( |
| 5818 | 1, // wait for one write to finish before reading. |
| 5819 | data_reads, arraysize(data_reads), |
| 5820 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5821 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5822 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5823 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5827 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5828 | |
| 5829 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5830 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5831 | CreateSession(&session_deps_))); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5833 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5834 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5835 | |
| 5836 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5837 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5838 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 5839 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 5840 | } |
| 5841 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5842 | // Test the request-challenge-retry sequence for basic auth, through |
| 5843 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5844 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5845 | HttpRequestInfo request; |
| 5846 | request.method = "GET"; |
| 5847 | request.url = GURL("https://www.google.com/"); |
| 5848 | // when the no authentication data flag is set. |
| 5849 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 5850 | |
| 5851 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5852 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5853 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 5854 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5855 | session_deps_.net_log = log.bound().net_log(); |
| 5856 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5857 | |
| 5858 | // Since we have proxy, should try to establish tunnel. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 5859 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 5860 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5861 | scoped_ptr<SpdyFrame> rst( |
| 5862 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5863 | |
| 5864 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5865 | // be issuing -- the final header line contains the credentials. |
| 5866 | const char* const kAuthCredentials[] = { |
| 5867 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 5868 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 5869 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 5870 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5871 | // fetch https://www.google.com/ via HTTP |
| 5872 | const char get[] = "GET / HTTP/1.1\r\n" |
| 5873 | "Host: www.google.com\r\n" |
| 5874 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5875 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5876 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5877 | |
| 5878 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5879 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5880 | CreateMockWrite(*rst, 4, ASYNC), |
| 5881 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5882 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5883 | }; |
| 5884 | |
| 5885 | // The proxy responds to the connect with a 407, using a persistent |
| 5886 | // connection. |
| 5887 | const char* const kAuthChallenge[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5888 | spdy_util_.GetStatusKey(), "407 Proxy Authentication Required", |
| 5889 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5890 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 5891 | }; |
| 5892 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5893 | scoped_ptr<SpdyFrame> conn_auth_resp( |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5894 | spdy_util_.ConstructSpdyControlFrame(NULL, |
| 5895 | 0, |
| 5896 | false, |
| 5897 | 1, |
| 5898 | LOWEST, |
| 5899 | SYN_REPLY, |
| 5900 | CONTROL_FLAG_NONE, |
| 5901 | kAuthChallenge, |
| 5902 | arraysize(kAuthChallenge), |
| 5903 | 0)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5904 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5905 | scoped_ptr<SpdyFrame> conn_resp( |
| 5906 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5907 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5908 | "Content-Length: 5\r\n\r\n"; |
| 5909 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5910 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5911 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5912 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5913 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5914 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 5915 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 5916 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 5917 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 5918 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 5919 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5920 | }; |
| 5921 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5922 | OrderedSocketData spdy_data( |
| 5923 | spdy_reads, arraysize(spdy_reads), |
| 5924 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5925 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5926 | // Negotiate SPDY to the proxy |
| 5927 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5928 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5930 | // Vanilla SSL to the server |
| 5931 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5933 | |
| 5934 | TestCompletionCallback callback1; |
| 5935 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5936 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5937 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5938 | |
| 5939 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 5940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5941 | |
| 5942 | rv = callback1.WaitForResult(); |
| 5943 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 5944 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5945 | log.GetEntries(&entries); |
| 5946 | size_t pos = ExpectLogContainsSomewhere( |
| 5947 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 5948 | NetLog::PHASE_NONE); |
| 5949 | ExpectLogContainsSomewhere( |
| 5950 | entries, pos, |
| 5951 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 5952 | NetLog::PHASE_NONE); |
| 5953 | |
| 5954 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5955 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5956 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5957 | EXPECT_EQ(407, response->headers->response_code()); |
| 5958 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5959 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 5960 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5961 | |
| 5962 | TestCompletionCallback callback2; |
| 5963 | |
| 5964 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 5965 | callback2.callback()); |
| 5966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5967 | |
| 5968 | rv = callback2.WaitForResult(); |
| 5969 | EXPECT_EQ(OK, rv); |
| 5970 | |
| 5971 | response = trans->GetResponseInfo(); |
| 5972 | ASSERT_TRUE(response != NULL); |
| 5973 | |
| 5974 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5975 | EXPECT_EQ(200, response->headers->response_code()); |
| 5976 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 5977 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5978 | |
| 5979 | // The password prompt info should not be set. |
| 5980 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5981 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5982 | LoadTimingInfo load_timing_info; |
| 5983 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5984 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5985 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5986 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 5987 | trans.reset(); |
| 5988 | session->CloseAllConnections(); |
| 5989 | } |
| 5990 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5991 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 5992 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5993 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5994 | HttpRequestInfo request; |
| 5995 | HttpRequestInfo push_request; |
| 5996 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5997 | request.method = "GET"; |
| 5998 | request.url = GURL("http://www.google.com/"); |
| 5999 | push_request.method = "GET"; |
| 6000 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6001 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6002 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6003 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6004 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6005 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6006 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6007 | |
| 6008 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6009 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6010 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6011 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6012 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6013 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6014 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6015 | |
| 6016 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6017 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6018 | }; |
| 6019 | |
| 6020 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6021 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6022 | |
| 6023 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6024 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6025 | |
| 6026 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6027 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6028 | 0, |
| 6029 | 2, |
| 6030 | 1, |
| 6031 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6032 | const char kPushedData[] = "pushed"; |
| 6033 | scoped_ptr<SpdyFrame> stream2_body( |
| 6034 | spdy_util_.ConstructSpdyBodyFrame( |
| 6035 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6036 | |
| 6037 | MockRead spdy_reads[] = { |
| 6038 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6039 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6040 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6041 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6042 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6043 | }; |
| 6044 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6045 | OrderedSocketData spdy_data( |
| 6046 | spdy_reads, arraysize(spdy_reads), |
| 6047 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6048 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6049 | // Negotiate SPDY to the proxy |
| 6050 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6051 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6053 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6054 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6056 | TestCompletionCallback callback; |
| 6057 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6059 | |
| 6060 | rv = callback.WaitForResult(); |
| 6061 | EXPECT_EQ(OK, rv); |
| 6062 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6063 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6064 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6066 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6067 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6068 | |
| 6069 | rv = callback.WaitForResult(); |
| 6070 | EXPECT_EQ(OK, rv); |
| 6071 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6072 | |
| 6073 | ASSERT_TRUE(response != NULL); |
| 6074 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6075 | |
| 6076 | EXPECT_EQ(200, response->headers->response_code()); |
| 6077 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6078 | |
| 6079 | std::string response_data; |
| 6080 | rv = ReadTransaction(trans.get(), &response_data); |
| 6081 | EXPECT_EQ(OK, rv); |
| 6082 | EXPECT_EQ("hello!", response_data); |
| 6083 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6084 | LoadTimingInfo load_timing_info; |
| 6085 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6086 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6087 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6088 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6089 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6090 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6091 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6092 | |
| 6093 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6094 | EXPECT_EQ(OK, rv); |
| 6095 | EXPECT_EQ("pushed", response_data); |
| 6096 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6097 | LoadTimingInfo push_load_timing_info; |
| 6098 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6099 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6100 | // The transactions should share a socket ID, despite being for different |
| 6101 | // origins. |
| 6102 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6103 | push_load_timing_info.socket_log_id); |
| 6104 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6105 | trans.reset(); |
| 6106 | push_trans.reset(); |
| 6107 | session->CloseAllConnections(); |
| 6108 | } |
| 6109 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6110 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6111 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6112 | HttpRequestInfo request; |
| 6113 | |
| 6114 | request.method = "GET"; |
| 6115 | request.url = GURL("http://www.google.com/"); |
| 6116 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6117 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6118 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6119 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6120 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6121 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6122 | |
| 6123 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6124 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6125 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6126 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6127 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6128 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6129 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6130 | |
| 6131 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6132 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6133 | |
| 6134 | MockWrite spdy_writes[] = { |
| 6135 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6136 | CreateMockWrite(*push_rst, 4), |
| 6137 | }; |
| 6138 | |
| 6139 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6140 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6141 | |
| 6142 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6143 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6144 | |
| 6145 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6146 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6147 | 0, |
| 6148 | 2, |
| 6149 | 1, |
| 6150 | "https://www.another-origin.com/foo.dat")); |
| 6151 | |
| 6152 | MockRead spdy_reads[] = { |
| 6153 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6154 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6155 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6156 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6157 | }; |
| 6158 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6159 | OrderedSocketData spdy_data( |
| 6160 | spdy_reads, arraysize(spdy_reads), |
| 6161 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6162 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6163 | // Negotiate SPDY to the proxy |
| 6164 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6165 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6166 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6167 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6168 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6169 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6170 | TestCompletionCallback callback; |
| 6171 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6172 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6173 | |
| 6174 | rv = callback.WaitForResult(); |
| 6175 | EXPECT_EQ(OK, rv); |
| 6176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6177 | |
| 6178 | ASSERT_TRUE(response != NULL); |
| 6179 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6180 | |
| 6181 | EXPECT_EQ(200, response->headers->response_code()); |
| 6182 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6183 | |
| 6184 | std::string response_data; |
| 6185 | rv = ReadTransaction(trans.get(), &response_data); |
| 6186 | EXPECT_EQ(OK, rv); |
| 6187 | EXPECT_EQ("hello!", response_data); |
| 6188 | |
| 6189 | trans.reset(); |
| 6190 | session->CloseAllConnections(); |
| 6191 | } |
| 6192 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6193 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 6194 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6195 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6196 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 6197 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6198 | |
| 6199 | HttpRequestInfo request; |
| 6200 | request.method = "GET"; |
| 6201 | request.url = GURL("https://www.google.com/"); |
| 6202 | request.load_flags = 0; |
| 6203 | |
| 6204 | // Attempt to fetch the URL from a server with a bad cert |
| 6205 | MockWrite bad_cert_writes[] = { |
| 6206 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6207 | "Host: www.google.com\r\n" |
| 6208 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6209 | }; |
| 6210 | |
| 6211 | MockRead bad_cert_reads[] = { |
| 6212 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6213 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6214 | }; |
| 6215 | |
| 6216 | // Attempt to fetch the URL with a good cert |
| 6217 | MockWrite good_data_writes[] = { |
| 6218 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6219 | "Host: www.google.com\r\n" |
| 6220 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6221 | MockWrite("GET / HTTP/1.1\r\n" |
| 6222 | "Host: www.google.com\r\n" |
| 6223 | "Connection: keep-alive\r\n\r\n"), |
| 6224 | }; |
| 6225 | |
| 6226 | MockRead good_cert_reads[] = { |
| 6227 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6228 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6229 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6230 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6231 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6232 | }; |
| 6233 | |
| 6234 | StaticSocketDataProvider ssl_bad_certificate( |
| 6235 | bad_cert_reads, arraysize(bad_cert_reads), |
| 6236 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 6237 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 6238 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6239 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6240 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6241 | |
| 6242 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6243 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6244 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6246 | |
| 6247 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6253 | |
| 6254 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6255 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6256 | CreateSession(&session_deps_))); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6258 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6259 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6260 | |
| 6261 | rv = callback.WaitForResult(); |
| 6262 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6264 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6266 | |
| 6267 | rv = callback.WaitForResult(); |
| 6268 | EXPECT_EQ(OK, rv); |
| 6269 | |
| 6270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6271 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6272 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6273 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6274 | } |
| 6275 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6276 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6277 | HttpRequestInfo request; |
| 6278 | request.method = "GET"; |
| 6279 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6280 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6281 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6282 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6283 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6284 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6285 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6286 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6287 | MockWrite data_writes[] = { |
| 6288 | MockWrite("GET / HTTP/1.1\r\n" |
| 6289 | "Host: www.google.com\r\n" |
| 6290 | "Connection: keep-alive\r\n" |
| 6291 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6292 | }; |
| 6293 | |
| 6294 | // Lastly, the server responds with the actual content. |
| 6295 | MockRead data_reads[] = { |
| 6296 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6297 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6298 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6299 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6300 | }; |
| 6301 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6303 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6304 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6306 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6308 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6309 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6310 | |
| 6311 | rv = callback.WaitForResult(); |
| 6312 | EXPECT_EQ(OK, rv); |
| 6313 | } |
| 6314 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6315 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6316 | HttpRequestInfo request; |
| 6317 | request.method = "GET"; |
| 6318 | request.url = GURL("https://www.google.com/"); |
| 6319 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6320 | "Chromium Ultra Awesome X Edition"); |
| 6321 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6322 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6323 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6324 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6325 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6326 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6327 | MockWrite data_writes[] = { |
| 6328 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6329 | "Host: www.google.com\r\n" |
| 6330 | "Proxy-Connection: keep-alive\r\n" |
| 6331 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6332 | }; |
| 6333 | MockRead data_reads[] = { |
| 6334 | // Return an error, so the transaction stops here (this test isn't |
| 6335 | // interested in the rest). |
| 6336 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6337 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6338 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 6339 | }; |
| 6340 | |
| 6341 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6342 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6345 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6347 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6349 | |
| 6350 | rv = callback.WaitForResult(); |
| 6351 | EXPECT_EQ(OK, rv); |
| 6352 | } |
| 6353 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6354 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6355 | HttpRequestInfo request; |
| 6356 | request.method = "GET"; |
| 6357 | request.url = GURL("http://www.google.com/"); |
| 6358 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6359 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 6360 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6361 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6362 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6363 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6364 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6365 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6366 | MockWrite data_writes[] = { |
| 6367 | MockWrite("GET / HTTP/1.1\r\n" |
| 6368 | "Host: www.google.com\r\n" |
| 6369 | "Connection: keep-alive\r\n" |
| 6370 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 6371 | }; |
| 6372 | |
| 6373 | // Lastly, the server responds with the actual content. |
| 6374 | MockRead data_reads[] = { |
| 6375 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6376 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6377 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6378 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6379 | }; |
| 6380 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6381 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6382 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6383 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6385 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6387 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6388 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6389 | |
| 6390 | rv = callback.WaitForResult(); |
| 6391 | EXPECT_EQ(OK, rv); |
| 6392 | } |
| 6393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6394 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6395 | HttpRequestInfo request; |
| 6396 | request.method = "POST"; |
| 6397 | request.url = GURL("http://www.google.com/"); |
| 6398 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6399 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6400 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6401 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6402 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6403 | MockWrite data_writes[] = { |
| 6404 | MockWrite("POST / HTTP/1.1\r\n" |
| 6405 | "Host: www.google.com\r\n" |
| 6406 | "Connection: keep-alive\r\n" |
| 6407 | "Content-Length: 0\r\n\r\n"), |
| 6408 | }; |
| 6409 | |
| 6410 | // Lastly, the server responds with the actual content. |
| 6411 | MockRead data_reads[] = { |
| 6412 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6413 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6414 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6415 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6416 | }; |
| 6417 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6419 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6422 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6424 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6426 | |
| 6427 | rv = callback.WaitForResult(); |
| 6428 | EXPECT_EQ(OK, rv); |
| 6429 | } |
| 6430 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6431 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6432 | HttpRequestInfo request; |
| 6433 | request.method = "PUT"; |
| 6434 | request.url = GURL("http://www.google.com/"); |
| 6435 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6436 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6437 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6438 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6439 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6440 | MockWrite data_writes[] = { |
| 6441 | MockWrite("PUT / HTTP/1.1\r\n" |
| 6442 | "Host: www.google.com\r\n" |
| 6443 | "Connection: keep-alive\r\n" |
| 6444 | "Content-Length: 0\r\n\r\n"), |
| 6445 | }; |
| 6446 | |
| 6447 | // Lastly, the server responds with the actual content. |
| 6448 | MockRead data_reads[] = { |
| 6449 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6450 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6451 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6452 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6453 | }; |
| 6454 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6455 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6456 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6457 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6459 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6461 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6463 | |
| 6464 | rv = callback.WaitForResult(); |
| 6465 | EXPECT_EQ(OK, rv); |
| 6466 | } |
| 6467 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6468 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6469 | HttpRequestInfo request; |
| 6470 | request.method = "HEAD"; |
| 6471 | request.url = GURL("http://www.google.com/"); |
| 6472 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6473 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6474 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6475 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6476 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6477 | MockWrite data_writes[] = { |
| 6478 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 6479 | "Host: www.google.com\r\n" |
| 6480 | "Connection: keep-alive\r\n" |
| 6481 | "Content-Length: 0\r\n\r\n"), |
| 6482 | }; |
| 6483 | |
| 6484 | // Lastly, the server responds with the actual content. |
| 6485 | MockRead data_reads[] = { |
| 6486 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6487 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6488 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6489 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6490 | }; |
| 6491 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6492 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6493 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6496 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6498 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6499 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6500 | |
| 6501 | rv = callback.WaitForResult(); |
| 6502 | EXPECT_EQ(OK, rv); |
| 6503 | } |
| 6504 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6505 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6506 | HttpRequestInfo request; |
| 6507 | request.method = "GET"; |
| 6508 | request.url = GURL("http://www.google.com/"); |
| 6509 | request.load_flags = LOAD_BYPASS_CACHE; |
| 6510 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6511 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6513 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6514 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6515 | MockWrite data_writes[] = { |
| 6516 | MockWrite("GET / HTTP/1.1\r\n" |
| 6517 | "Host: www.google.com\r\n" |
| 6518 | "Connection: keep-alive\r\n" |
| 6519 | "Pragma: no-cache\r\n" |
| 6520 | "Cache-Control: no-cache\r\n\r\n"), |
| 6521 | }; |
| 6522 | |
| 6523 | // Lastly, the server responds with the actual content. |
| 6524 | MockRead data_reads[] = { |
| 6525 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6526 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6527 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6528 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6529 | }; |
| 6530 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6531 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6532 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6535 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6537 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6539 | |
| 6540 | rv = callback.WaitForResult(); |
| 6541 | EXPECT_EQ(OK, rv); |
| 6542 | } |
| 6543 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6544 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6545 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6546 | HttpRequestInfo request; |
| 6547 | request.method = "GET"; |
| 6548 | request.url = GURL("http://www.google.com/"); |
| 6549 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 6550 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6551 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6553 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6554 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6555 | MockWrite data_writes[] = { |
| 6556 | MockWrite("GET / HTTP/1.1\r\n" |
| 6557 | "Host: www.google.com\r\n" |
| 6558 | "Connection: keep-alive\r\n" |
| 6559 | "Cache-Control: max-age=0\r\n\r\n"), |
| 6560 | }; |
| 6561 | |
| 6562 | // Lastly, the server responds with the actual content. |
| 6563 | MockRead data_reads[] = { |
| 6564 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6566 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6567 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6568 | }; |
| 6569 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6570 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6571 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6574 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6576 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6577 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6578 | |
| 6579 | rv = callback.WaitForResult(); |
| 6580 | EXPECT_EQ(OK, rv); |
| 6581 | } |
| 6582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6583 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6584 | HttpRequestInfo request; |
| 6585 | request.method = "GET"; |
| 6586 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6587 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6588 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6589 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6590 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6591 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6592 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6593 | MockWrite data_writes[] = { |
| 6594 | MockWrite("GET / HTTP/1.1\r\n" |
| 6595 | "Host: www.google.com\r\n" |
| 6596 | "Connection: keep-alive\r\n" |
| 6597 | "FooHeader: Bar\r\n\r\n"), |
| 6598 | }; |
| 6599 | |
| 6600 | // Lastly, the server responds with the actual content. |
| 6601 | MockRead data_reads[] = { |
| 6602 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6603 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6604 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6606 | }; |
| 6607 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6609 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6612 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6614 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6616 | |
| 6617 | rv = callback.WaitForResult(); |
| 6618 | EXPECT_EQ(OK, rv); |
| 6619 | } |
| 6620 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6621 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6622 | HttpRequestInfo request; |
| 6623 | request.method = "GET"; |
| 6624 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6625 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 6626 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 6627 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6628 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6629 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6631 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6632 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6633 | MockWrite data_writes[] = { |
| 6634 | MockWrite("GET / HTTP/1.1\r\n" |
| 6635 | "Host: www.google.com\r\n" |
| 6636 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6637 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6638 | "hEllo: Kitty\r\n" |
| 6639 | "FoO: bar\r\n\r\n"), |
| 6640 | }; |
| 6641 | |
| 6642 | // Lastly, the server responds with the actual content. |
| 6643 | MockRead data_reads[] = { |
| 6644 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6645 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6646 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6647 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6648 | }; |
| 6649 | |
| 6650 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6651 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6654 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6656 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 6657 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6658 | |
| 6659 | rv = callback.WaitForResult(); |
| 6660 | EXPECT_EQ(OK, rv); |
| 6661 | } |
| 6662 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6663 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6664 | HttpRequestInfo request; |
| 6665 | request.method = "GET"; |
| 6666 | request.url = GURL("http://www.google.com/"); |
| 6667 | request.load_flags = 0; |
| 6668 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6669 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6670 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 6671 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6672 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6673 | |
| 6674 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6675 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6676 | CreateSession(&session_deps_))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6677 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6678 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 6679 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6680 | |
| 6681 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6682 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6683 | MockWrite("GET / HTTP/1.1\r\n" |
| 6684 | "Host: www.google.com\r\n" |
| 6685 | "Connection: keep-alive\r\n\r\n") |
| 6686 | }; |
| 6687 | |
| 6688 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6689 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6690 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6691 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6692 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6693 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6694 | }; |
| 6695 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6696 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6697 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6698 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6700 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6702 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6704 | |
| 6705 | rv = callback.WaitForResult(); |
| 6706 | EXPECT_EQ(OK, rv); |
| 6707 | |
| 6708 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6709 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6710 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6711 | LoadTimingInfo load_timing_info; |
| 6712 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6713 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6714 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6715 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6716 | std::string response_text; |
| 6717 | rv = ReadTransaction(trans.get(), &response_text); |
| 6718 | EXPECT_EQ(OK, rv); |
| 6719 | EXPECT_EQ("Payload", response_text); |
| 6720 | } |
| 6721 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6722 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6723 | HttpRequestInfo request; |
| 6724 | request.method = "GET"; |
| 6725 | request.url = GURL("https://www.google.com/"); |
| 6726 | request.load_flags = 0; |
| 6727 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6728 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6729 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 6730 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6731 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6732 | |
| 6733 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6734 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6735 | CreateSession(&session_deps_))); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6736 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6737 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 6738 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6739 | |
| 6740 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6741 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6742 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6743 | MockWrite("GET / HTTP/1.1\r\n" |
| 6744 | "Host: www.google.com\r\n" |
| 6745 | "Connection: keep-alive\r\n\r\n") |
| 6746 | }; |
| 6747 | |
| 6748 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6749 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 6750 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6751 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6753 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6754 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6755 | }; |
| 6756 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6757 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6758 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6760 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6761 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6764 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6766 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6767 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6768 | |
| 6769 | rv = callback.WaitForResult(); |
| 6770 | EXPECT_EQ(OK, rv); |
| 6771 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6772 | LoadTimingInfo load_timing_info; |
| 6773 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6774 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6775 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6776 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6777 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6778 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6779 | |
| 6780 | std::string response_text; |
| 6781 | rv = ReadTransaction(trans.get(), &response_text); |
| 6782 | EXPECT_EQ(OK, rv); |
| 6783 | EXPECT_EQ("Payload", response_text); |
| 6784 | } |
| 6785 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6786 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6787 | HttpRequestInfo request; |
| 6788 | request.method = "GET"; |
| 6789 | request.url = GURL("http://www.google.com/"); |
| 6790 | request.load_flags = 0; |
| 6791 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6792 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6793 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 6794 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6795 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6796 | |
| 6797 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6798 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6799 | CreateSession(&session_deps_))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6800 | |
| 6801 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 6802 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 6803 | |
| 6804 | MockWrite data_writes[] = { |
| 6805 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 6806 | MockWrite("GET / HTTP/1.1\r\n" |
| 6807 | "Host: www.google.com\r\n" |
| 6808 | "Connection: keep-alive\r\n\r\n") |
| 6809 | }; |
| 6810 | |
| 6811 | MockRead data_reads[] = { |
| 6812 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 6813 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6814 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6815 | MockRead("Payload"), |
| 6816 | MockRead(SYNCHRONOUS, OK) |
| 6817 | }; |
| 6818 | |
| 6819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6820 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6822 | |
| 6823 | TestCompletionCallback callback; |
| 6824 | |
| 6825 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6826 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6827 | |
| 6828 | rv = callback.WaitForResult(); |
| 6829 | EXPECT_EQ(OK, rv); |
| 6830 | |
| 6831 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6832 | ASSERT_TRUE(response != NULL); |
| 6833 | |
| 6834 | LoadTimingInfo load_timing_info; |
| 6835 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6836 | TestLoadTimingNotReused(load_timing_info, |
| 6837 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6838 | |
| 6839 | std::string response_text; |
| 6840 | rv = ReadTransaction(trans.get(), &response_text); |
| 6841 | EXPECT_EQ(OK, rv); |
| 6842 | EXPECT_EQ("Payload", response_text); |
| 6843 | } |
| 6844 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6845 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6846 | HttpRequestInfo request; |
| 6847 | request.method = "GET"; |
| 6848 | request.url = GURL("http://www.google.com/"); |
| 6849 | request.load_flags = 0; |
| 6850 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6851 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6852 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 6853 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6854 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6855 | |
| 6856 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6857 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6858 | CreateSession(&session_deps_))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6859 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6860 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 6861 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 6862 | const char kSOCKS5OkRequest[] = { |
| 6863 | 0x05, // Version |
| 6864 | 0x01, // Command (CONNECT) |
| 6865 | 0x00, // Reserved. |
| 6866 | 0x03, // Address type (DOMAINNAME). |
| 6867 | 0x0E, // Length of domain (14) |
| 6868 | // Domain string: |
| 6869 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 6870 | 0x00, 0x50, // 16-bit port (80) |
| 6871 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6872 | const char kSOCKS5OkResponse[] = |
| 6873 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 6874 | |
| 6875 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6876 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 6877 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6878 | MockWrite("GET / HTTP/1.1\r\n" |
| 6879 | "Host: www.google.com\r\n" |
| 6880 | "Connection: keep-alive\r\n\r\n") |
| 6881 | }; |
| 6882 | |
| 6883 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6884 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 6885 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6886 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6887 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6888 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6889 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6890 | }; |
| 6891 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6892 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6893 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6894 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6896 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6898 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6900 | |
| 6901 | rv = callback.WaitForResult(); |
| 6902 | EXPECT_EQ(OK, rv); |
| 6903 | |
| 6904 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6905 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6906 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6907 | LoadTimingInfo load_timing_info; |
| 6908 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6909 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6910 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6911 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6912 | std::string response_text; |
| 6913 | rv = ReadTransaction(trans.get(), &response_text); |
| 6914 | EXPECT_EQ(OK, rv); |
| 6915 | EXPECT_EQ("Payload", response_text); |
| 6916 | } |
| 6917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6918 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6919 | HttpRequestInfo request; |
| 6920 | request.method = "GET"; |
| 6921 | request.url = GURL("https://www.google.com/"); |
| 6922 | request.load_flags = 0; |
| 6923 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6924 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6925 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 6926 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6927 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6928 | |
| 6929 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6930 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6931 | CreateSession(&session_deps_))); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6932 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6933 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 6934 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 6935 | const unsigned char kSOCKS5OkRequest[] = { |
| 6936 | 0x05, // Version |
| 6937 | 0x01, // Command (CONNECT) |
| 6938 | 0x00, // Reserved. |
| 6939 | 0x03, // Address type (DOMAINNAME). |
| 6940 | 0x0E, // Length of domain (14) |
| 6941 | // Domain string: |
| 6942 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 6943 | 0x01, 0xBB, // 16-bit port (443) |
| 6944 | }; |
| 6945 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6946 | const char kSOCKS5OkResponse[] = |
| 6947 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 6948 | |
| 6949 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6950 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 6951 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 6952 | arraysize(kSOCKS5OkRequest)), |
| 6953 | MockWrite("GET / HTTP/1.1\r\n" |
| 6954 | "Host: www.google.com\r\n" |
| 6955 | "Connection: keep-alive\r\n\r\n") |
| 6956 | }; |
| 6957 | |
| 6958 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 6959 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 6960 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6961 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6962 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 6963 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6964 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6965 | }; |
| 6966 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6967 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6968 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6970 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6971 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6974 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6975 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6976 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6977 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6978 | |
| 6979 | rv = callback.WaitForResult(); |
| 6980 | EXPECT_EQ(OK, rv); |
| 6981 | |
| 6982 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6983 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6984 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6985 | LoadTimingInfo load_timing_info; |
| 6986 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6987 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6988 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6989 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 6990 | std::string response_text; |
| 6991 | rv = ReadTransaction(trans.get(), &response_text); |
| 6992 | EXPECT_EQ(OK, rv); |
| 6993 | EXPECT_EQ("Payload", response_text); |
| 6994 | } |
| 6995 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6996 | namespace { |
| 6997 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 6998 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 6999 | |
| 7000 | struct GroupNameTest { |
| 7001 | std::string proxy_server; |
| 7002 | std::string url; |
| 7003 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7004 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7005 | }; |
| 7006 | |
| 7007 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7008 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7009 | SpdySessionDependencies* session_deps_) { |
| 7010 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7011 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7012 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7013 | session->http_server_properties(); |
| 7014 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7015 | HostPortPair("host.with.alternate", 80), 443, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7016 | AlternateProtocolFromNextProto(next_proto)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7017 | |
| 7018 | return session; |
| 7019 | } |
| 7020 | |
| 7021 | int GroupNameTransactionHelper( |
| 7022 | const std::string& url, |
| 7023 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7024 | HttpRequestInfo request; |
| 7025 | request.method = "GET"; |
| 7026 | request.url = GURL(url); |
| 7027 | request.load_flags = 0; |
| 7028 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7029 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7030 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7032 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7033 | |
| 7034 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7035 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7036 | } |
| 7037 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7038 | } // namespace |
| 7039 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7040 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7041 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7042 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7043 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7044 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7045 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7046 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7047 | }, |
| 7048 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7049 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7050 | "http://[2001:1418:13:1::25]/direct", |
| 7051 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7052 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7053 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7054 | |
| 7055 | // SSL Tests |
| 7056 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7057 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7058 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7059 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7060 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7061 | }, |
| 7062 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7063 | "", // unused |
| 7064 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7065 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7066 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7067 | }, |
| 7068 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7069 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7070 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7071 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7072 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7073 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7074 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7075 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7076 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7077 | |
| 7078 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7079 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7080 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7081 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7082 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7083 | |
| 7084 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7085 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7086 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7087 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7088 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7089 | MockClientSocketPoolManager* mock_pool_manager = |
| 7090 | new MockClientSocketPoolManager; |
| 7091 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7092 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
| 7093 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7094 | |
| 7095 | EXPECT_EQ(ERR_IO_PENDING, |
| 7096 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7097 | if (tests[i].ssl) |
| 7098 | EXPECT_EQ(tests[i].expected_group_name, |
| 7099 | ssl_conn_pool->last_group_name_received()); |
| 7100 | else |
| 7101 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7102 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7103 | } |
| 7104 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7105 | } |
| 7106 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7107 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7108 | const GroupNameTest tests[] = { |
| 7109 | { |
| 7110 | "http_proxy", |
| 7111 | "http://www.google.com/http_proxy_normal", |
| 7112 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7113 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7114 | }, |
| 7115 | |
| 7116 | // SSL Tests |
| 7117 | { |
| 7118 | "http_proxy", |
| 7119 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7120 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7121 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7122 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7123 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7124 | { |
| 7125 | "http_proxy", |
| 7126 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7127 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7128 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7129 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7130 | |
| 7131 | { |
| 7132 | "http_proxy", |
| 7133 | "ftp://ftp.google.com/http_proxy_normal", |
| 7134 | "ftp/ftp.google.com:21", |
| 7135 | false, |
| 7136 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7137 | }; |
| 7138 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7139 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7140 | |
| 7141 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7142 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7143 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7144 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7145 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7146 | |
| 7147 | HttpNetworkSessionPeer peer(session); |
| 7148 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7149 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7150 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7151 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7152 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7153 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7154 | |
| 7155 | MockClientSocketPoolManager* mock_pool_manager = |
| 7156 | new MockClientSocketPoolManager; |
| 7157 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7158 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
| 7159 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7160 | |
| 7161 | EXPECT_EQ(ERR_IO_PENDING, |
| 7162 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7163 | if (tests[i].ssl) |
| 7164 | EXPECT_EQ(tests[i].expected_group_name, |
| 7165 | ssl_conn_pool->last_group_name_received()); |
| 7166 | else |
| 7167 | EXPECT_EQ(tests[i].expected_group_name, |
| 7168 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7169 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7170 | } |
| 7171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7172 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7173 | const GroupNameTest tests[] = { |
| 7174 | { |
| 7175 | "socks4://socks_proxy:1080", |
| 7176 | "http://www.google.com/socks4_direct", |
| 7177 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7178 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7179 | }, |
| 7180 | { |
| 7181 | "socks5://socks_proxy:1080", |
| 7182 | "http://www.google.com/socks5_direct", |
| 7183 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7184 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7185 | }, |
| 7186 | |
| 7187 | // SSL Tests |
| 7188 | { |
| 7189 | "socks4://socks_proxy:1080", |
| 7190 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7191 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7192 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7193 | }, |
| 7194 | { |
| 7195 | "socks5://socks_proxy:1080", |
| 7196 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7197 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7198 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7199 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7200 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7201 | { |
| 7202 | "socks4://socks_proxy:1080", |
| 7203 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7204 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7205 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7206 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7207 | }; |
| 7208 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 7209 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7210 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7211 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7212 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7213 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7214 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7215 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7216 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7217 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7218 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7219 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7220 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7221 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7222 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7223 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7224 | |
| 7225 | MockClientSocketPoolManager* mock_pool_manager = |
| 7226 | new MockClientSocketPoolManager; |
| 7227 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 7228 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
| 7229 | peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7230 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7231 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7233 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7234 | EXPECT_EQ(ERR_IO_PENDING, |
| 7235 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7236 | if (tests[i].ssl) |
| 7237 | EXPECT_EQ(tests[i].expected_group_name, |
| 7238 | ssl_conn_pool->last_group_name_received()); |
| 7239 | else |
| 7240 | EXPECT_EQ(tests[i].expected_group_name, |
| 7241 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7242 | } |
| 7243 | } |
| 7244 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7245 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7246 | HttpRequestInfo request; |
| 7247 | request.method = "GET"; |
| 7248 | request.url = GURL("http://www.google.com/"); |
| 7249 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7250 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 7251 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7252 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 7253 | // This simulates failure resolving all hostnames; that means we will fail |
| 7254 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7255 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7256 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7257 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7258 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7259 | CreateSession(&session_deps_))); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7261 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7263 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7264 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7265 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7266 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 7267 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7268 | } |
| 7269 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7270 | // Base test to make sure that when the load flags for a request specify to |
| 7271 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7272 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7273 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7274 | // Issue a request, asking to bypass the cache(s). |
| 7275 | HttpRequestInfo request; |
| 7276 | request.method = "GET"; |
| 7277 | request.load_flags = load_flags; |
| 7278 | request.url = GURL("http://www.google.com/"); |
| 7279 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 7280 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7281 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7282 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7283 | scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7284 | CreateSession(&session_deps_))); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7285 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7286 | // 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] | 7287 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7288 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7289 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7290 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7291 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7292 | &addrlist, |
| 7293 | callback.callback(), |
| 7294 | NULL, |
| 7295 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7297 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7298 | EXPECT_EQ(OK, rv); |
| 7299 | |
| 7300 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 7301 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7302 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7303 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7304 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7305 | &addrlist, |
| 7306 | callback.callback(), |
| 7307 | NULL, |
| 7308 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7309 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7310 | |
| 7311 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 7312 | // we can tell if the next lookup hit the cache, or the "network". |
| 7313 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7314 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7315 | |
| 7316 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 7317 | // 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] | 7318 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7319 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7321 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7322 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7323 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7324 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7325 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7326 | |
| 7327 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 7328 | // "www.google.com". |
| 7329 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 7330 | } |
| 7331 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7332 | // There are multiple load flags that should trigger the host cache bypass. |
| 7333 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7334 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7335 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 7336 | } |
| 7337 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7338 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7339 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 7340 | } |
| 7341 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7342 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7343 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 7344 | } |
| 7345 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7346 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7347 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7348 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7349 | |
| 7350 | HttpRequestInfo request; |
| 7351 | request.method = "GET"; |
| 7352 | request.url = GURL("http://www.foo.com/"); |
| 7353 | request.load_flags = 0; |
| 7354 | |
| 7355 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7356 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7357 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7358 | StaticSocketDataProvider data(NULL, 0, |
| 7359 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7362 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7363 | |
| 7364 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7365 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7366 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7370 | |
| 7371 | rv = callback.WaitForResult(); |
| 7372 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 7373 | } |
| 7374 | |
| 7375 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7376 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7377 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7378 | |
| 7379 | HttpRequestInfo request; |
| 7380 | request.method = "GET"; |
| 7381 | request.url = GURL("http://www.foo.com/"); |
| 7382 | request.load_flags = 0; |
| 7383 | |
| 7384 | MockRead data_reads[] = { |
| 7385 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7386 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7387 | }; |
| 7388 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7392 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7393 | |
| 7394 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7396 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7398 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7399 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7400 | |
| 7401 | rv = callback.WaitForResult(); |
| 7402 | EXPECT_EQ(OK, rv); |
| 7403 | |
| 7404 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7405 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7406 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7407 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7408 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7409 | |
| 7410 | std::string response_data; |
| 7411 | rv = ReadTransaction(trans.get(), &response_data); |
| 7412 | EXPECT_EQ(OK, rv); |
| 7413 | EXPECT_EQ("", response_data); |
| 7414 | } |
| 7415 | |
| 7416 | // Make sure that a dropped connection while draining the body for auth |
| 7417 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7418 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7419 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7420 | |
| 7421 | HttpRequestInfo request; |
| 7422 | request.method = "GET"; |
| 7423 | request.url = GURL("http://www.google.com/"); |
| 7424 | request.load_flags = 0; |
| 7425 | |
| 7426 | MockWrite data_writes1[] = { |
| 7427 | MockWrite("GET / HTTP/1.1\r\n" |
| 7428 | "Host: www.google.com\r\n" |
| 7429 | "Connection: keep-alive\r\n\r\n"), |
| 7430 | }; |
| 7431 | |
| 7432 | MockRead data_reads1[] = { |
| 7433 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7434 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7435 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7436 | MockRead("Content-Length: 14\r\n\r\n"), |
| 7437 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7438 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7439 | }; |
| 7440 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7441 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7442 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7443 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7444 | |
| 7445 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7446 | // be issuing -- the final header line contains the credentials. |
| 7447 | MockWrite data_writes2[] = { |
| 7448 | MockWrite("GET / HTTP/1.1\r\n" |
| 7449 | "Host: www.google.com\r\n" |
| 7450 | "Connection: keep-alive\r\n" |
| 7451 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 7452 | }; |
| 7453 | |
| 7454 | // Lastly, the server responds with the actual content. |
| 7455 | MockRead data_reads2[] = { |
| 7456 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7457 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7458 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7459 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7460 | }; |
| 7461 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7462 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7463 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7464 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7466 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7467 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7468 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7469 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7471 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7472 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7473 | |
| 7474 | rv = callback1.WaitForResult(); |
| 7475 | EXPECT_EQ(OK, rv); |
| 7476 | |
| 7477 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7478 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7479 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7481 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7483 | rv = trans->RestartWithAuth( |
| 7484 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7486 | |
| 7487 | rv = callback2.WaitForResult(); |
| 7488 | EXPECT_EQ(OK, rv); |
| 7489 | |
| 7490 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7491 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7492 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7493 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7494 | } |
| 7495 | |
| 7496 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7497 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7498 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7499 | |
| 7500 | HttpRequestInfo request; |
| 7501 | request.method = "GET"; |
| 7502 | request.url = GURL("https://www.google.com/"); |
| 7503 | request.load_flags = 0; |
| 7504 | |
| 7505 | MockRead proxy_reads[] = { |
| 7506 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7507 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7508 | }; |
| 7509 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7510 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7511 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7512 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7516 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7517 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7518 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7519 | |
| 7520 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7521 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7522 | CreateSession(&session_deps_))); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7524 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7526 | |
| 7527 | rv = callback.WaitForResult(); |
| 7528 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 7529 | } |
| 7530 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7531 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7532 | HttpRequestInfo request; |
| 7533 | request.method = "GET"; |
| 7534 | request.url = GURL("http://www.google.com/"); |
| 7535 | request.load_flags = 0; |
| 7536 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7537 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7538 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7539 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7540 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7541 | MockRead data_reads[] = { |
| 7542 | 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] | 7543 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7544 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7545 | |
| 7546 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7549 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7551 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7552 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7553 | |
| 7554 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 7555 | |
| 7556 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7557 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7558 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7559 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 7560 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7561 | |
| 7562 | std::string response_data; |
| 7563 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 7564 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 7565 | } |
| 7566 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7567 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7568 | base::FilePath temp_file_path; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7569 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path)); |
| 7570 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 7571 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 7572 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7573 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7574 | ScopedVector<UploadElementReader> element_readers; |
| 7575 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7576 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7577 | temp_file_path, |
| 7578 | 0, |
| 7579 | kuint64max, |
| 7580 | base::Time())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 7581 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7582 | |
| 7583 | HttpRequestInfo request; |
| 7584 | request.method = "POST"; |
| 7585 | request.url = GURL("http://www.google.com/upload"); |
| 7586 | request.upload_data_stream = &upload_data_stream; |
| 7587 | request.load_flags = 0; |
| 7588 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7589 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7590 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7591 | CreateSession(&session_deps_))); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7592 | |
| 7593 | MockRead data_reads[] = { |
| 7594 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 7595 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7596 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7597 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7598 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7599 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7601 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7603 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7605 | |
| 7606 | rv = callback.WaitForResult(); |
| 7607 | EXPECT_EQ(OK, rv); |
| 7608 | |
| 7609 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7610 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7611 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7612 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7613 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7614 | |
| 7615 | std::string response_data; |
| 7616 | rv = ReadTransaction(trans.get(), &response_data); |
| 7617 | EXPECT_EQ(OK, rv); |
| 7618 | EXPECT_EQ("hello world", response_data); |
| 7619 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7620 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 7621 | } |
| 7622 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7623 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7624 | base::FilePath temp_file; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7625 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
| 7626 | std::string temp_file_content("Unreadable file."); |
| 7627 | ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_content.c_str(), |
| 7628 | temp_file_content.length())); |
| 7629 | ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
| 7630 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7631 | ScopedVector<UploadElementReader> element_readers; |
| 7632 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7633 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7634 | temp_file, |
| 7635 | 0, |
| 7636 | kuint64max, |
| 7637 | base::Time())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 7638 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7639 | |
| 7640 | HttpRequestInfo request; |
| 7641 | request.method = "POST"; |
| 7642 | request.url = GURL("http://www.google.com/upload"); |
| 7643 | request.upload_data_stream = &upload_data_stream; |
| 7644 | request.load_flags = 0; |
| 7645 | |
| 7646 | // If we try to upload an unreadable file, the network stack should report |
| 7647 | // the file size as zero and upload zero bytes for that file. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7648 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7649 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7650 | CreateSession(&session_deps_))); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7651 | |
| 7652 | MockRead data_reads[] = { |
| 7653 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7654 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7655 | }; |
| 7656 | MockWrite data_writes[] = { |
| 7657 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7658 | "Host: www.google.com\r\n" |
| 7659 | "Connection: keep-alive\r\n" |
| 7660 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7661 | MockWrite(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7662 | }; |
| 7663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7664 | arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7667 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7669 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7671 | |
| 7672 | rv = callback.WaitForResult(); |
| 7673 | EXPECT_EQ(OK, rv); |
| 7674 | |
| 7675 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7676 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7677 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7678 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7679 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7680 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7681 | } |
| 7682 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7683 | TEST_P(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 7684 | base::FilePath temp_file; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7685 | ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file)); |
| 7686 | std::string temp_file_contents("Unreadable file."); |
| 7687 | std::string unreadable_contents(temp_file_contents.length(), '\0'); |
| 7688 | ASSERT_TRUE(file_util::WriteFile(temp_file, temp_file_contents.c_str(), |
| 7689 | temp_file_contents.length())); |
| 7690 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 7691 | ScopedVector<UploadElementReader> element_readers; |
| 7692 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 7693 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 7694 | temp_file, |
| 7695 | 0, |
| 7696 | kuint64max, |
| 7697 | base::Time())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 7698 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7699 | |
| 7700 | HttpRequestInfo request; |
| 7701 | request.method = "POST"; |
| 7702 | request.url = GURL("http://www.google.com/upload"); |
| 7703 | request.upload_data_stream = &upload_data_stream; |
| 7704 | request.load_flags = 0; |
| 7705 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7706 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7707 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7708 | CreateSession(&session_deps_))); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7709 | |
| 7710 | MockRead data_reads[] = { |
| 7711 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7712 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7713 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
| 7714 | |
| 7715 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7716 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7717 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7718 | }; |
| 7719 | MockWrite data_writes[] = { |
| 7720 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7721 | "Host: www.google.com\r\n" |
| 7722 | "Connection: keep-alive\r\n" |
| 7723 | "Content-Length: 16\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7724 | MockWrite(SYNCHRONOUS, temp_file_contents.c_str()), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7725 | |
| 7726 | MockWrite("POST /upload HTTP/1.1\r\n" |
| 7727 | "Host: www.google.com\r\n" |
| 7728 | "Connection: keep-alive\r\n" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 7729 | "Content-Length: 0\r\n" |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7730 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7731 | MockWrite(SYNCHRONOUS, unreadable_contents.c_str(), |
| 7732 | temp_file_contents.length()), |
| 7733 | MockWrite(SYNCHRONOUS, OK), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7734 | }; |
| 7735 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7736 | arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7739 | TestCompletionCallback callback1; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7741 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7743 | |
| 7744 | rv = callback1.WaitForResult(); |
| 7745 | EXPECT_EQ(OK, rv); |
| 7746 | |
| 7747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7748 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7749 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7750 | EXPECT_EQ("HTTP/1.1 401 Unauthorized", response->headers->GetStatusLine()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7751 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7752 | |
| 7753 | // Now make the file unreadable and try again. |
| 7754 | ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file)); |
| 7755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7756 | TestCompletionCallback callback2; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7758 | rv = trans->RestartWithAuth( |
| 7759 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7761 | |
| 7762 | rv = callback2.WaitForResult(); |
| 7763 | EXPECT_EQ(OK, rv); |
| 7764 | |
| 7765 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7766 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7767 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7768 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7769 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7770 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 7771 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 7772 | } |
| 7773 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame^] | 7774 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 7775 | class FakeUploadElementReader : public UploadElementReader { |
| 7776 | public: |
| 7777 | FakeUploadElementReader() {} |
| 7778 | virtual ~FakeUploadElementReader() {} |
| 7779 | |
| 7780 | const CompletionCallback& callback() const { return callback_; } |
| 7781 | |
| 7782 | // UploadElementReader overrides: |
| 7783 | virtual int Init(const CompletionCallback& callback) OVERRIDE { |
| 7784 | callback_ = callback; |
| 7785 | return ERR_IO_PENDING; |
| 7786 | } |
| 7787 | virtual uint64 GetContentLength() const OVERRIDE { return 0; } |
| 7788 | virtual uint64 BytesRemaining() const OVERRIDE { return 0; } |
| 7789 | virtual int Read(IOBuffer* buf, |
| 7790 | int buf_length, |
| 7791 | const CompletionCallback& callback) OVERRIDE { |
| 7792 | return ERR_FAILED; |
| 7793 | } |
| 7794 | |
| 7795 | private: |
| 7796 | CompletionCallback callback_; |
| 7797 | }; |
| 7798 | |
| 7799 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 7800 | ScopedVector<UploadElementReader> element_readers; |
| 7801 | element_readers.push_back(fake_reader); |
| 7802 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 7803 | |
| 7804 | HttpRequestInfo request; |
| 7805 | request.method = "POST"; |
| 7806 | request.url = GURL("http://www.google.com/upload"); |
| 7807 | request.upload_data_stream = &upload_data_stream; |
| 7808 | request.load_flags = 0; |
| 7809 | |
| 7810 | scoped_ptr<HttpTransaction> trans( |
| 7811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 7812 | CreateSession(&session_deps_))); |
| 7813 | |
| 7814 | StaticSocketDataProvider data; |
| 7815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7816 | |
| 7817 | TestCompletionCallback callback; |
| 7818 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7820 | base::MessageLoop::current()->RunUntilIdle(); |
| 7821 | |
| 7822 | // Transaction is pending on request body initialization. |
| 7823 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 7824 | |
| 7825 | // Return Init()'s result after the transaction gets destroyed. |
| 7826 | trans.reset(); |
| 7827 | fake_reader->callback().Run(OK); // Should not crash. |
| 7828 | } |
| 7829 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7830 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7831 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7832 | |
| 7833 | HttpRequestInfo request; |
| 7834 | request.method = "GET"; |
| 7835 | request.url = GURL("http://www.google.com/"); |
| 7836 | request.load_flags = 0; |
| 7837 | |
| 7838 | // First transaction will request a resource and receive a Basic challenge |
| 7839 | // with realm="first_realm". |
| 7840 | MockWrite data_writes1[] = { |
| 7841 | MockWrite("GET / HTTP/1.1\r\n" |
| 7842 | "Host: www.google.com\r\n" |
| 7843 | "Connection: keep-alive\r\n" |
| 7844 | "\r\n"), |
| 7845 | }; |
| 7846 | MockRead data_reads1[] = { |
| 7847 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7848 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 7849 | "\r\n"), |
| 7850 | }; |
| 7851 | |
| 7852 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 7853 | // for first_realm. The server will reject and provide a challenge with |
| 7854 | // second_realm. |
| 7855 | MockWrite data_writes2[] = { |
| 7856 | MockWrite("GET / HTTP/1.1\r\n" |
| 7857 | "Host: www.google.com\r\n" |
| 7858 | "Connection: keep-alive\r\n" |
| 7859 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 7860 | "\r\n"), |
| 7861 | }; |
| 7862 | MockRead data_reads2[] = { |
| 7863 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7864 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 7865 | "\r\n"), |
| 7866 | }; |
| 7867 | |
| 7868 | // This again fails, and goes back to first_realm. Make sure that the |
| 7869 | // entry is removed from cache. |
| 7870 | MockWrite data_writes3[] = { |
| 7871 | MockWrite("GET / HTTP/1.1\r\n" |
| 7872 | "Host: www.google.com\r\n" |
| 7873 | "Connection: keep-alive\r\n" |
| 7874 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 7875 | "\r\n"), |
| 7876 | }; |
| 7877 | MockRead data_reads3[] = { |
| 7878 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 7879 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 7880 | "\r\n"), |
| 7881 | }; |
| 7882 | |
| 7883 | // Try one last time (with the correct password) and get the resource. |
| 7884 | MockWrite data_writes4[] = { |
| 7885 | MockWrite("GET / HTTP/1.1\r\n" |
| 7886 | "Host: www.google.com\r\n" |
| 7887 | "Connection: keep-alive\r\n" |
| 7888 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 7889 | "\r\n"), |
| 7890 | }; |
| 7891 | MockRead data_reads4[] = { |
| 7892 | MockRead("HTTP/1.1 200 OK\r\n" |
| 7893 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7894 | "Content-Length: 5\r\n" |
| 7895 | "\r\n" |
| 7896 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7897 | }; |
| 7898 | |
| 7899 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7900 | data_writes1, arraysize(data_writes1)); |
| 7901 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7902 | data_writes2, arraysize(data_writes2)); |
| 7903 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7904 | data_writes3, arraysize(data_writes3)); |
| 7905 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 7906 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7907 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7908 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7909 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7910 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7911 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7912 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7913 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7914 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7915 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7916 | CreateSession(&session_deps_))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7917 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7918 | // Issue the first request with Authorize headers. There should be a |
| 7919 | // password prompt for first_realm waiting to be filled in after the |
| 7920 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7921 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7923 | rv = callback1.WaitForResult(); |
| 7924 | EXPECT_EQ(OK, rv); |
| 7925 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7926 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7927 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 7928 | ASSERT_FALSE(challenge == NULL); |
| 7929 | EXPECT_FALSE(challenge->is_proxy); |
| 7930 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7931 | EXPECT_EQ("first_realm", challenge->realm); |
| 7932 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7933 | |
| 7934 | // Issue the second request with an incorrect password. There should be a |
| 7935 | // password prompt for second_realm waiting to be filled in after the |
| 7936 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7937 | TestCompletionCallback callback2; |
| 7938 | rv = trans->RestartWithAuth( |
| 7939 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7941 | rv = callback2.WaitForResult(); |
| 7942 | EXPECT_EQ(OK, rv); |
| 7943 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7944 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7945 | challenge = response->auth_challenge.get(); |
| 7946 | ASSERT_FALSE(challenge == NULL); |
| 7947 | EXPECT_FALSE(challenge->is_proxy); |
| 7948 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7949 | EXPECT_EQ("second_realm", challenge->realm); |
| 7950 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7951 | |
| 7952 | // Issue the third request with another incorrect password. There should be |
| 7953 | // a password prompt for first_realm waiting to be filled in. If the password |
| 7954 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 7955 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7956 | TestCompletionCallback callback3; |
| 7957 | rv = trans->RestartWithAuth( |
| 7958 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7959 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7960 | rv = callback3.WaitForResult(); |
| 7961 | EXPECT_EQ(OK, rv); |
| 7962 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7963 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7964 | challenge = response->auth_challenge.get(); |
| 7965 | ASSERT_FALSE(challenge == NULL); |
| 7966 | EXPECT_FALSE(challenge->is_proxy); |
| 7967 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 7968 | EXPECT_EQ("first_realm", challenge->realm); |
| 7969 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7970 | |
| 7971 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7972 | TestCompletionCallback callback4; |
| 7973 | rv = trans->RestartWithAuth( |
| 7974 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7976 | rv = callback4.WaitForResult(); |
| 7977 | EXPECT_EQ(OK, rv); |
| 7978 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7979 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 7980 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7981 | } |
| 7982 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7983 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 7984 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7985 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 7986 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7987 | std::string alternate_protocol_http_header = |
| 7988 | GetAlternateProtocolHttpHeader(); |
| 7989 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7990 | MockRead data_reads[] = { |
| 7991 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7992 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7993 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7994 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 7995 | }; |
| 7996 | |
| 7997 | HttpRequestInfo request; |
| 7998 | request.method = "GET"; |
| 7999 | request.url = GURL("http://www.google.com/"); |
| 8000 | request.load_flags = 0; |
| 8001 | |
| 8002 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8003 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8004 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8005 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8006 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8007 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8008 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8009 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8010 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8012 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8014 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8015 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8016 | const HttpServerProperties& http_server_properties = |
| 8017 | *session->http_server_properties(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8018 | EXPECT_FALSE( |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8019 | http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8020 | |
| 8021 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8022 | |
| 8023 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8024 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8025 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8026 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8027 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8028 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8029 | |
| 8030 | std::string response_data; |
| 8031 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8032 | EXPECT_EQ("hello world", response_data); |
| 8033 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8034 | ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
| 8035 | const PortAlternateProtocolPair alternate = |
| 8036 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 8037 | PortAlternateProtocolPair expected_alternate; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8038 | expected_alternate.port = 443; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8039 | expected_alternate.protocol = AlternateProtocolFromNextProto(GetParam()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8040 | EXPECT_TRUE(expected_alternate.Equals(alternate)); |
| 8041 | } |
| 8042 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8043 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8044 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8045 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8046 | |
| 8047 | HttpRequestInfo request; |
| 8048 | request.method = "GET"; |
| 8049 | request.url = GURL("http://www.google.com/"); |
| 8050 | request.load_flags = 0; |
| 8051 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8052 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8053 | StaticSocketDataProvider first_data; |
| 8054 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8055 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8056 | |
| 8057 | MockRead data_reads[] = { |
| 8058 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8059 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8060 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8061 | }; |
| 8062 | StaticSocketDataProvider second_data( |
| 8063 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8064 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8065 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8066 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8067 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8068 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8069 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8070 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8071 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8072 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8073 | HostPortPair::FromURL(request.url), |
| 8074 | 666 /* port is ignored by MockConnect anyway */, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8075 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8076 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8077 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8079 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8081 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8083 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8084 | |
| 8085 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8086 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8087 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8089 | |
| 8090 | std::string response_data; |
| 8091 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8092 | EXPECT_EQ("hello world", response_data); |
| 8093 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8094 | ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8095 | HostPortPair::FromURL(request.url))); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8096 | const PortAlternateProtocolPair alternate = |
| 8097 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8098 | HostPortPair::FromURL(request.url)); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8099 | EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8100 | } |
| 8101 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8102 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8103 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8104 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8105 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8106 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8107 | // other cases. |
| 8108 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8109 | |
| 8110 | HttpRequestInfo restricted_port_request; |
| 8111 | restricted_port_request.method = "GET"; |
| 8112 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8113 | restricted_port_request.load_flags = 0; |
| 8114 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8115 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8116 | StaticSocketDataProvider first_data; |
| 8117 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8118 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8119 | |
| 8120 | MockRead data_reads[] = { |
| 8121 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8122 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8123 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8124 | }; |
| 8125 | StaticSocketDataProvider second_data( |
| 8126 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8127 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8128 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8129 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8130 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8131 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8132 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8133 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8134 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8135 | HostPortPair::FromURL(restricted_port_request.url), |
| 8136 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8137 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8138 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8139 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8141 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8143 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8144 | &restricted_port_request, |
| 8145 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8147 | // Invalid change to unrestricted port should fail. |
| 8148 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8149 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8151 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8152 | AlternateProtocolPortRestrictedPermitted) { |
| 8153 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8154 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8155 | // on a restricted port (port < 1024) if we set |
| 8156 | // enable_user_alternate_protocol_ports. |
| 8157 | |
| 8158 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8159 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8160 | |
| 8161 | HttpRequestInfo restricted_port_request; |
| 8162 | restricted_port_request.method = "GET"; |
| 8163 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8164 | restricted_port_request.load_flags = 0; |
| 8165 | |
| 8166 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8167 | StaticSocketDataProvider first_data; |
| 8168 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8169 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8170 | |
| 8171 | MockRead data_reads[] = { |
| 8172 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8173 | MockRead("hello world"), |
| 8174 | MockRead(ASYNC, OK), |
| 8175 | }; |
| 8176 | StaticSocketDataProvider second_data( |
| 8177 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8178 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8179 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8180 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8181 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8182 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8183 | session->http_server_properties(); |
| 8184 | const int kUnrestrictedAlternatePort = 1024; |
| 8185 | http_server_properties->SetAlternateProtocol( |
| 8186 | HostPortPair::FromURL(restricted_port_request.url), |
| 8187 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8188 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8189 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8190 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8192 | TestCompletionCallback callback; |
| 8193 | |
| 8194 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8195 | &restricted_port_request, |
| 8196 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8197 | // Change to unrestricted port should succeed. |
| 8198 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8199 | } |
| 8200 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8201 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8202 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8203 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8204 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8205 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8206 | // other cases. |
| 8207 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8208 | |
| 8209 | HttpRequestInfo restricted_port_request; |
| 8210 | restricted_port_request.method = "GET"; |
| 8211 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8212 | restricted_port_request.load_flags = 0; |
| 8213 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8214 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8215 | StaticSocketDataProvider first_data; |
| 8216 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8217 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8218 | |
| 8219 | MockRead data_reads[] = { |
| 8220 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8221 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8222 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8223 | }; |
| 8224 | StaticSocketDataProvider second_data( |
| 8225 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8226 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8227 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8229 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8230 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8231 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8232 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8233 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8234 | HostPortPair::FromURL(restricted_port_request.url), |
| 8235 | kRestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8236 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8237 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8238 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8240 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8242 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8243 | &restricted_port_request, |
| 8244 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8245 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8246 | // Valid change to restricted port should pass. |
| 8247 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8248 | } |
| 8249 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8250 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8251 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8252 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8253 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8254 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8255 | // other cases. |
| 8256 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8257 | |
| 8258 | HttpRequestInfo unrestricted_port_request; |
| 8259 | unrestricted_port_request.method = "GET"; |
| 8260 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8261 | unrestricted_port_request.load_flags = 0; |
| 8262 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8263 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8264 | StaticSocketDataProvider first_data; |
| 8265 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8266 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8267 | |
| 8268 | MockRead data_reads[] = { |
| 8269 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8270 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8271 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8272 | }; |
| 8273 | StaticSocketDataProvider second_data( |
| 8274 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8275 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8276 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8277 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8278 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8279 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8280 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8281 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8282 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8283 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8284 | kRestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8285 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8286 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8287 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8289 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8291 | int rv = trans->Start( |
| 8292 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8294 | // Valid change to restricted port should pass. |
| 8295 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8296 | } |
| 8297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8298 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8299 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8300 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8301 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8302 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8303 | // other cases. |
| 8304 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8305 | |
| 8306 | HttpRequestInfo unrestricted_port_request; |
| 8307 | unrestricted_port_request.method = "GET"; |
| 8308 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8309 | unrestricted_port_request.load_flags = 0; |
| 8310 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8311 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8312 | StaticSocketDataProvider first_data; |
| 8313 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8314 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8315 | |
| 8316 | MockRead data_reads[] = { |
| 8317 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8318 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8319 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8320 | }; |
| 8321 | StaticSocketDataProvider second_data( |
| 8322 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8323 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8324 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8325 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8326 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8327 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8328 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8329 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8330 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8331 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8332 | kUnrestrictedAlternatePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8333 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8334 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8335 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8336 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8337 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8339 | int rv = trans->Start( |
| 8340 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8342 | // Valid change to an unrestricted port should pass. |
| 8343 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8344 | } |
| 8345 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8346 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8347 | AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8348 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8349 | // protocol to an unsafe port, and that we resume the second |
| 8350 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
| 8351 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8352 | |
| 8353 | HttpRequestInfo request; |
| 8354 | request.method = "GET"; |
| 8355 | request.url = GURL("http://www.google.com/"); |
| 8356 | request.load_flags = 0; |
| 8357 | |
| 8358 | // The alternate protocol request will error out before we attempt to connect, |
| 8359 | // so only the standard HTTP request will try to connect. |
| 8360 | MockRead data_reads[] = { |
| 8361 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8362 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8363 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8364 | }; |
| 8365 | StaticSocketDataProvider data( |
| 8366 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8367 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8368 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8369 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8370 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8371 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8372 | session->http_server_properties(); |
| 8373 | const int kUnsafePort = 7; |
| 8374 | http_server_properties->SetAlternateProtocol( |
| 8375 | HostPortPair::FromURL(request.url), |
| 8376 | kUnsafePort, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8377 | AlternateProtocolFromNextProto(GetParam())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8378 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8379 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8380 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8381 | TestCompletionCallback callback; |
| 8382 | |
| 8383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8385 | // The HTTP request should succeed. |
| 8386 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8387 | |
| 8388 | // Disable alternate protocol before the asserts. |
| 8389 | HttpStreamFactory::set_use_alternate_protocols(false); |
| 8390 | |
| 8391 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8392 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8393 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8394 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8395 | |
| 8396 | std::string response_data; |
| 8397 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8398 | EXPECT_EQ("hello world", response_data); |
| 8399 | } |
| 8400 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8401 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8402 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8403 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8404 | |
| 8405 | HttpRequestInfo request; |
| 8406 | request.method = "GET"; |
| 8407 | request.url = GURL("http://www.google.com/"); |
| 8408 | request.load_flags = 0; |
| 8409 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8410 | std::string alternate_protocol_http_header = |
| 8411 | GetAlternateProtocolHttpHeader(); |
| 8412 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8413 | MockRead data_reads[] = { |
| 8414 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8415 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8416 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8417 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 8418 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8419 | }; |
| 8420 | |
| 8421 | StaticSocketDataProvider first_transaction( |
| 8422 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8423 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8424 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8425 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8426 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8428 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8429 | scoped_ptr<SpdyFrame> req( |
| 8430 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8431 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8432 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8433 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8434 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8435 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8436 | CreateMockRead(*resp), |
| 8437 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8439 | }; |
| 8440 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8441 | DelayedSocketData spdy_data( |
| 8442 | 1, // wait for one write to finish before reading. |
| 8443 | spdy_reads, arraysize(spdy_reads), |
| 8444 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8445 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8446 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8447 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8448 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8449 | NULL, 0, NULL, 0); |
| 8450 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8451 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8452 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8453 | &hanging_non_alternate_protocol_socket); |
| 8454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8455 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8456 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8457 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8458 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8461 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8463 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8464 | |
| 8465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8466 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8467 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8468 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8469 | |
| 8470 | std::string response_data; |
| 8471 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8472 | EXPECT_EQ("hello world", response_data); |
| 8473 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8474 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8476 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8477 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8478 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8479 | |
| 8480 | response = trans->GetResponseInfo(); |
| 8481 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8482 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8483 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8484 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8485 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8486 | |
| 8487 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8488 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8489 | } |
| 8490 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8491 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8492 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8493 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8494 | |
| 8495 | HttpRequestInfo request; |
| 8496 | request.method = "GET"; |
| 8497 | request.url = GURL("http://www.google.com/"); |
| 8498 | request.load_flags = 0; |
| 8499 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8500 | std::string alternate_protocol_http_header = |
| 8501 | GetAlternateProtocolHttpHeader(); |
| 8502 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8503 | MockRead data_reads[] = { |
| 8504 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8505 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8506 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8507 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8508 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8509 | }; |
| 8510 | |
| 8511 | StaticSocketDataProvider first_transaction( |
| 8512 | data_reads, arraysize(data_reads), NULL, 0); |
| 8513 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8514 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8515 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8516 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8517 | StaticSocketDataProvider hanging_socket( |
| 8518 | NULL, 0, NULL, 0); |
| 8519 | hanging_socket.set_connect_data(never_finishing_connect); |
| 8520 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 8521 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8522 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 8523 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8524 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8525 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8526 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8528 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8529 | scoped_ptr<SpdyFrame> req1( |
| 8530 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 8531 | scoped_ptr<SpdyFrame> req2( |
| 8532 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8533 | MockWrite spdy_writes[] = { |
| 8534 | CreateMockWrite(*req1), |
| 8535 | CreateMockWrite(*req2), |
| 8536 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8537 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8538 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8539 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 8540 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8541 | MockRead spdy_reads[] = { |
| 8542 | CreateMockRead(*resp1), |
| 8543 | CreateMockRead(*data1), |
| 8544 | CreateMockRead(*resp2), |
| 8545 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8546 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8547 | }; |
| 8548 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8549 | DelayedSocketData spdy_data( |
| 8550 | 2, // wait for writes to finish before reading. |
| 8551 | spdy_reads, arraysize(spdy_reads), |
| 8552 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8553 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8554 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8555 | |
| 8556 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8557 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8558 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8559 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8560 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8561 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8563 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8565 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 8566 | |
| 8567 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 8568 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8569 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8570 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8571 | |
| 8572 | std::string response_data; |
| 8573 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 8574 | EXPECT_EQ("hello world", response_data); |
| 8575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8576 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8577 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8578 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8579 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8581 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8582 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8583 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8584 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8585 | |
| 8586 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 8587 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 8588 | |
| 8589 | response = trans2.GetResponseInfo(); |
| 8590 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8591 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8592 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8593 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8594 | EXPECT_TRUE(response->was_npn_negotiated); |
| 8595 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 8596 | EXPECT_EQ("hello!", response_data); |
| 8597 | |
| 8598 | response = trans3.GetResponseInfo(); |
| 8599 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8600 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8601 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8602 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8603 | EXPECT_TRUE(response->was_npn_negotiated); |
| 8604 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 8605 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8606 | } |
| 8607 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8608 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8609 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8610 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8611 | |
| 8612 | HttpRequestInfo request; |
| 8613 | request.method = "GET"; |
| 8614 | request.url = GURL("http://www.google.com/"); |
| 8615 | request.load_flags = 0; |
| 8616 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8617 | std::string alternate_protocol_http_header = |
| 8618 | GetAlternateProtocolHttpHeader(); |
| 8619 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8620 | MockRead data_reads[] = { |
| 8621 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8622 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8623 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8624 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8625 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8626 | }; |
| 8627 | |
| 8628 | StaticSocketDataProvider first_transaction( |
| 8629 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8630 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8631 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8632 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8633 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8635 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8636 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8637 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 8638 | NULL, 0, NULL, 0); |
| 8639 | hanging_alternate_protocol_socket.set_connect_data( |
| 8640 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8641 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8642 | &hanging_alternate_protocol_socket); |
| 8643 | |
| 8644 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8645 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8647 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8648 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8649 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8650 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8651 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8653 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8654 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8655 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8656 | |
| 8657 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8658 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8659 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8660 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8661 | |
| 8662 | std::string response_data; |
| 8663 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8664 | EXPECT_EQ("hello world", response_data); |
| 8665 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8666 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8668 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8670 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8671 | |
| 8672 | response = trans->GetResponseInfo(); |
| 8673 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8674 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8675 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8676 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8677 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8678 | |
| 8679 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8680 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8681 | } |
| 8682 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8683 | class CapturingProxyResolver : public ProxyResolver { |
| 8684 | public: |
| 8685 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
| 8686 | virtual ~CapturingProxyResolver() {} |
| 8687 | |
| 8688 | virtual int GetProxyForURL(const GURL& url, |
| 8689 | ProxyInfo* results, |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 8690 | const CompletionCallback& callback, |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8691 | RequestHandle* request, |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8692 | const BoundNetLog& net_log) OVERRIDE { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 8693 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 8694 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8695 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8696 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8697 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8698 | } |
| 8699 | |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8700 | virtual void CancelRequest(RequestHandle request) OVERRIDE { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8701 | NOTREACHED(); |
| 8702 | } |
| 8703 | |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 8704 | virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 8705 | NOTREACHED(); |
| 8706 | return LOAD_STATE_IDLE; |
| 8707 | } |
| 8708 | |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8709 | virtual void CancelSetPacScript() OVERRIDE { |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 8710 | NOTREACHED(); |
| 8711 | } |
| 8712 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 8713 | virtual int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 8714 | const CompletionCallback& /*callback*/) OVERRIDE { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8715 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8716 | } |
| 8717 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 8718 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 8719 | |
| 8720 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8721 | std::vector<GURL> resolved_; |
| 8722 | |
| 8723 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 8724 | }; |
| 8725 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8726 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8727 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8728 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8729 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8730 | |
| 8731 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8732 | proxy_config.set_auto_detect(true); |
| 8733 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 8734 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8735 | CapturingProxyResolver* capturing_proxy_resolver = |
| 8736 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8737 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 8738 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 8739 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8740 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8741 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8742 | |
| 8743 | HttpRequestInfo request; |
| 8744 | request.method = "GET"; |
| 8745 | request.url = GURL("http://www.google.com/"); |
| 8746 | request.load_flags = 0; |
| 8747 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8748 | std::string alternate_protocol_http_header = |
| 8749 | GetAlternateProtocolHttpHeader(); |
| 8750 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8751 | MockRead data_reads[] = { |
| 8752 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8753 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8754 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8755 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8756 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8757 | }; |
| 8758 | |
| 8759 | StaticSocketDataProvider first_transaction( |
| 8760 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8761 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8762 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8763 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8764 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8766 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8767 | scoped_ptr<SpdyFrame> req( |
| 8768 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8769 | MockWrite spdy_writes[] = { |
| 8770 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 8771 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8772 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8773 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8774 | }; |
| 8775 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8776 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 8777 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8778 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8779 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8780 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8781 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8782 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 8783 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8784 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8785 | }; |
| 8786 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8787 | OrderedSocketData spdy_data( |
| 8788 | spdy_reads, arraysize(spdy_reads), |
| 8789 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8790 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8791 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8792 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8793 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8794 | NULL, 0, NULL, 0); |
| 8795 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8796 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8797 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8798 | &hanging_non_alternate_protocol_socket); |
| 8799 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8800 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8801 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8802 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8803 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8806 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8808 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8809 | |
| 8810 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8811 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8812 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8813 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8814 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8815 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8816 | |
| 8817 | std::string response_data; |
| 8818 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8819 | EXPECT_EQ("hello world", response_data); |
| 8820 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8821 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8823 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8825 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8826 | |
| 8827 | response = trans->GetResponseInfo(); |
| 8828 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8829 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8830 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8831 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8832 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8833 | |
| 8834 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8835 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8836 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8837 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8838 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 8839 | EXPECT_EQ("https://www.google.com/", |
| 8840 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8841 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8842 | LoadTimingInfo load_timing_info; |
| 8843 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8844 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8845 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8846 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 8847 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8848 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8849 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 8850 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 8851 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8852 | |
| 8853 | HttpRequestInfo request; |
| 8854 | request.method = "GET"; |
| 8855 | request.url = GURL("http://www.google.com/"); |
| 8856 | request.load_flags = 0; |
| 8857 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8858 | std::string alternate_protocol_http_header = |
| 8859 | GetAlternateProtocolHttpHeader(); |
| 8860 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8861 | MockRead data_reads[] = { |
| 8862 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8863 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8864 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8865 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8866 | }; |
| 8867 | |
| 8868 | StaticSocketDataProvider first_transaction( |
| 8869 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8870 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8871 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8872 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8873 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8875 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8876 | scoped_ptr<SpdyFrame> req( |
| 8877 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8878 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8879 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8880 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8881 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8882 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8883 | CreateMockRead(*resp), |
| 8884 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8885 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8886 | }; |
| 8887 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8888 | DelayedSocketData spdy_data( |
| 8889 | 1, // wait for one write to finish before reading. |
| 8890 | spdy_reads, arraysize(spdy_reads), |
| 8891 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8892 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8893 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 8894 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8895 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8896 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8897 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8898 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8901 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8902 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8903 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8904 | |
| 8905 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8906 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8907 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8908 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8909 | |
| 8910 | std::string response_data; |
| 8911 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8912 | EXPECT_EQ("hello world", response_data); |
| 8913 | |
| 8914 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 8915 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 8916 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 8917 | kPrivacyModeDisabled); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 8918 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 8919 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 8920 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8921 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8923 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8924 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8925 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8926 | |
| 8927 | response = trans->GetResponseInfo(); |
| 8928 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8929 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8930 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8931 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8932 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8933 | |
| 8934 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8935 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8936 | } |
| 8937 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8938 | // GenerateAuthToken is a mighty big test. |
| 8939 | // It tests all permutation of GenerateAuthToken behavior: |
| 8940 | // - Synchronous and Asynchronous completion. |
| 8941 | // - OK or error on completion. |
| 8942 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 8943 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 8944 | // - Non-authenticating and authenticating backend. |
| 8945 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 8946 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8947 | // problems generating an auth token for an authenticating proxy, we don't |
| 8948 | // need to test all permutations of the backend server). |
| 8949 | // |
| 8950 | // The test proceeds by going over each of the configuration cases, and |
| 8951 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 8952 | // specifies both the configuration for the test as well as the expectations |
| 8953 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8954 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8955 | static const char kServer[] = "http://www.example.com"; |
| 8956 | static const char kSecureServer[] = "https://www.example.com"; |
| 8957 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 8958 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 8959 | |
| 8960 | enum AuthTiming { |
| 8961 | AUTH_NONE, |
| 8962 | AUTH_SYNC, |
| 8963 | AUTH_ASYNC, |
| 8964 | }; |
| 8965 | |
| 8966 | const MockWrite kGet( |
| 8967 | "GET / HTTP/1.1\r\n" |
| 8968 | "Host: www.example.com\r\n" |
| 8969 | "Connection: keep-alive\r\n\r\n"); |
| 8970 | const MockWrite kGetProxy( |
| 8971 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8972 | "Host: www.example.com\r\n" |
| 8973 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 8974 | const MockWrite kGetAuth( |
| 8975 | "GET / HTTP/1.1\r\n" |
| 8976 | "Host: www.example.com\r\n" |
| 8977 | "Connection: keep-alive\r\n" |
| 8978 | "Authorization: auth_token\r\n\r\n"); |
| 8979 | const MockWrite kGetProxyAuth( |
| 8980 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8981 | "Host: www.example.com\r\n" |
| 8982 | "Proxy-Connection: keep-alive\r\n" |
| 8983 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 8984 | const MockWrite kGetAuthThroughProxy( |
| 8985 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8986 | "Host: www.example.com\r\n" |
| 8987 | "Proxy-Connection: keep-alive\r\n" |
| 8988 | "Authorization: auth_token\r\n\r\n"); |
| 8989 | const MockWrite kGetAuthWithProxyAuth( |
| 8990 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 8991 | "Host: www.example.com\r\n" |
| 8992 | "Proxy-Connection: keep-alive\r\n" |
| 8993 | "Proxy-Authorization: auth_token\r\n" |
| 8994 | "Authorization: auth_token\r\n\r\n"); |
| 8995 | const MockWrite kConnect( |
| 8996 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 8997 | "Host: www.example.com\r\n" |
| 8998 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 8999 | const MockWrite kConnectProxyAuth( |
| 9000 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9001 | "Host: www.example.com\r\n" |
| 9002 | "Proxy-Connection: keep-alive\r\n" |
| 9003 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9004 | |
| 9005 | const MockRead kSuccess( |
| 9006 | "HTTP/1.1 200 OK\r\n" |
| 9007 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9008 | "Content-Length: 3\r\n\r\n" |
| 9009 | "Yes"); |
| 9010 | const MockRead kFailure( |
| 9011 | "Should not be called."); |
| 9012 | const MockRead kServerChallenge( |
| 9013 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9014 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9015 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9016 | "Content-Length: 14\r\n\r\n" |
| 9017 | "Unauthorized\r\n"); |
| 9018 | const MockRead kProxyChallenge( |
| 9019 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9020 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9021 | "Proxy-Connection: close\r\n" |
| 9022 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9023 | "Content-Length: 14\r\n\r\n" |
| 9024 | "Unauthorized\r\n"); |
| 9025 | const MockRead kProxyConnected( |
| 9026 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9027 | |
| 9028 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9029 | // no constructors, but the C++ compiler on Windows warns about |
| 9030 | // unspecified data in compound literals. So, moved to using constructors, |
| 9031 | // and TestRound's created with the default constructor should not be used. |
| 9032 | struct TestRound { |
| 9033 | TestRound() |
| 9034 | : expected_rv(ERR_UNEXPECTED), |
| 9035 | extra_write(NULL), |
| 9036 | extra_read(NULL) { |
| 9037 | } |
| 9038 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9039 | int expected_rv_arg) |
| 9040 | : write(write_arg), |
| 9041 | read(read_arg), |
| 9042 | expected_rv(expected_rv_arg), |
| 9043 | extra_write(NULL), |
| 9044 | extra_read(NULL) { |
| 9045 | } |
| 9046 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9047 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9048 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9049 | : write(write_arg), |
| 9050 | read(read_arg), |
| 9051 | expected_rv(expected_rv_arg), |
| 9052 | extra_write(extra_write_arg), |
| 9053 | extra_read(extra_read_arg) { |
| 9054 | } |
| 9055 | MockWrite write; |
| 9056 | MockRead read; |
| 9057 | int expected_rv; |
| 9058 | const MockWrite* extra_write; |
| 9059 | const MockRead* extra_read; |
| 9060 | }; |
| 9061 | |
| 9062 | static const int kNoSSL = 500; |
| 9063 | |
| 9064 | struct TestConfig { |
| 9065 | const char* proxy_url; |
| 9066 | AuthTiming proxy_auth_timing; |
| 9067 | int proxy_auth_rv; |
| 9068 | const char* server_url; |
| 9069 | AuthTiming server_auth_timing; |
| 9070 | int server_auth_rv; |
| 9071 | int num_auth_rounds; |
| 9072 | int first_ssl_round; |
| 9073 | TestRound rounds[3]; |
| 9074 | } test_configs[] = { |
| 9075 | // Non-authenticating HTTP server with a direct connection. |
| 9076 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9077 | { TestRound(kGet, kSuccess, OK)}}, |
| 9078 | // Authenticating HTTP server with a direct connection. |
| 9079 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9080 | { TestRound(kGet, kServerChallenge, OK), |
| 9081 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9082 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9083 | { TestRound(kGet, kServerChallenge, OK), |
| 9084 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9085 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9086 | { TestRound(kGet, kServerChallenge, OK), |
| 9087 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9088 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9089 | { TestRound(kGet, kServerChallenge, OK), |
| 9090 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9091 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9092 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9093 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9094 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9095 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9096 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9097 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9098 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9099 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9100 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9101 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9102 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9103 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9104 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9105 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9106 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9107 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9108 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9109 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9110 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9111 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9112 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9113 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9114 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9115 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9116 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9117 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9118 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9119 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9120 | // Authenticating HTTP server through an authenticating proxy. |
| 9121 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9122 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9123 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9124 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9125 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9126 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9127 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9128 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9129 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9130 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9131 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9132 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9133 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9134 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9135 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9136 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9137 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9138 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9139 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9140 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9141 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9142 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9143 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9144 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9145 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9146 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9147 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9148 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9149 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9150 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9151 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9152 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9153 | // Non-authenticating HTTPS server with a direct connection. |
| 9154 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9155 | { TestRound(kGet, kSuccess, OK)}}, |
| 9156 | // Authenticating HTTPS server with a direct connection. |
| 9157 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9158 | { TestRound(kGet, kServerChallenge, OK), |
| 9159 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9160 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9161 | { TestRound(kGet, kServerChallenge, OK), |
| 9162 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9163 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9164 | { TestRound(kGet, kServerChallenge, OK), |
| 9165 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9166 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9167 | { TestRound(kGet, kServerChallenge, OK), |
| 9168 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9169 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9170 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9171 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9172 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9173 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9174 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9175 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9176 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9177 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9178 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9179 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9180 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9181 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9182 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9183 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9184 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9185 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9186 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9187 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9188 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9189 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9190 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9191 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9192 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9193 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9194 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9195 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9196 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9197 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9198 | // Authenticating HTTPS server through an authenticating proxy. |
| 9199 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9200 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9201 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9202 | &kGet, &kServerChallenge), |
| 9203 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9204 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9205 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9206 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9207 | &kGet, &kServerChallenge), |
| 9208 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9209 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9210 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9211 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9212 | &kGet, &kServerChallenge), |
| 9213 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9214 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9215 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9216 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9217 | &kGet, &kServerChallenge), |
| 9218 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9219 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9220 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9221 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9222 | &kGet, &kServerChallenge), |
| 9223 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9224 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9225 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9226 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9227 | &kGet, &kServerChallenge), |
| 9228 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9229 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9230 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9231 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9232 | &kGet, &kServerChallenge), |
| 9233 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9234 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9235 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9236 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9237 | &kGet, &kServerChallenge), |
| 9238 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9239 | }; |
| 9240 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9241 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9242 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9243 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9244 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9245 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9246 | |
| 9247 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9248 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9249 | for (int n = 0; n < 2; n++) { |
| 9250 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9251 | std::string auth_challenge = "Mock realm=proxy"; |
| 9252 | GURL origin(test_config.proxy_url); |
| 9253 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9254 | auth_challenge.end()); |
| 9255 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9256 | origin, BoundNetLog()); |
| 9257 | auth_handler->SetGenerateExpectation( |
| 9258 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9259 | test_config.proxy_auth_rv); |
| 9260 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9261 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9262 | } |
| 9263 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9264 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9265 | std::string auth_challenge = "Mock realm=server"; |
| 9266 | GURL origin(test_config.server_url); |
| 9267 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9268 | auth_challenge.end()); |
| 9269 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9270 | origin, BoundNetLog()); |
| 9271 | auth_handler->SetGenerateExpectation( |
| 9272 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9273 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9274 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9275 | } |
| 9276 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9277 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9278 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9279 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9280 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9281 | } |
| 9282 | |
| 9283 | HttpRequestInfo request; |
| 9284 | request.method = "GET"; |
| 9285 | request.url = GURL(test_config.server_url); |
| 9286 | request.load_flags = 0; |
| 9287 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9288 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9289 | HttpNetworkTransaction trans( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9290 | DEFAULT_PRIORITY, CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9291 | |
| 9292 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 9293 | const TestRound& read_write_round = test_config.rounds[round]; |
| 9294 | |
| 9295 | // Set up expected reads and writes. |
| 9296 | MockRead reads[2]; |
| 9297 | reads[0] = read_write_round.read; |
| 9298 | size_t length_reads = 1; |
| 9299 | if (read_write_round.extra_read) { |
| 9300 | reads[1] = *read_write_round.extra_read; |
| 9301 | length_reads = 2; |
| 9302 | } |
| 9303 | |
| 9304 | MockWrite writes[2]; |
| 9305 | writes[0] = read_write_round.write; |
| 9306 | size_t length_writes = 1; |
| 9307 | if (read_write_round.extra_write) { |
| 9308 | writes[1] = *read_write_round.extra_write; |
| 9309 | length_writes = 2; |
| 9310 | } |
| 9311 | StaticSocketDataProvider data_provider( |
| 9312 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9313 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9314 | |
| 9315 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9316 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9317 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9318 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9319 | &ssl_socket_data_provider); |
| 9320 | |
| 9321 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9322 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9323 | int rv; |
| 9324 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9325 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9326 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9327 | rv = trans.RestartWithAuth( |
| 9328 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9329 | } |
| 9330 | if (rv == ERR_IO_PENDING) |
| 9331 | rv = callback.WaitForResult(); |
| 9332 | |
| 9333 | // Compare results with expected data. |
| 9334 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9335 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9336 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9337 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9338 | } else { |
| 9339 | EXPECT_TRUE(response == NULL); |
| 9340 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 9341 | continue; |
| 9342 | } |
| 9343 | if (round + 1 < test_config.num_auth_rounds) { |
| 9344 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 9345 | } else { |
| 9346 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9347 | } |
| 9348 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 9349 | } |
| 9350 | } |
| 9351 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9352 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9353 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9354 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9355 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9356 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9357 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 9358 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 9359 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9360 | |
| 9361 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9362 | auth_handler->set_connection_based(true); |
| 9363 | std::string auth_challenge = "Mock realm=server"; |
| 9364 | GURL origin("http://www.example.com"); |
| 9365 | HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9366 | auth_challenge.end()); |
| 9367 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9368 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9369 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9370 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9371 | int rv = OK; |
| 9372 | const HttpResponseInfo* response = NULL; |
| 9373 | HttpRequestInfo request; |
| 9374 | request.method = "GET"; |
| 9375 | request.url = origin; |
| 9376 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9377 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9378 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9379 | |
| 9380 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 9381 | // to validate that the TCP socket is not released to the pool between |
| 9382 | // each round of multi-round authentication. |
| 9383 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9384 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 9385 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9386 | 50, // Max sockets for pool |
| 9387 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9388 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9389 | session_deps_.host_resolver.get(), |
| 9390 | session_deps_.socket_factory.get(), |
| 9391 | session_deps_.net_log); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9392 | MockClientSocketPoolManager* mock_pool_manager = |
| 9393 | new MockClientSocketPoolManager; |
| 9394 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
| 9395 | session_peer.SetClientSocketPoolManager(mock_pool_manager); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9396 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9397 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9398 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9399 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9400 | |
| 9401 | const MockWrite kGet( |
| 9402 | "GET / HTTP/1.1\r\n" |
| 9403 | "Host: www.example.com\r\n" |
| 9404 | "Connection: keep-alive\r\n\r\n"); |
| 9405 | const MockWrite kGetAuth( |
| 9406 | "GET / HTTP/1.1\r\n" |
| 9407 | "Host: www.example.com\r\n" |
| 9408 | "Connection: keep-alive\r\n" |
| 9409 | "Authorization: auth_token\r\n\r\n"); |
| 9410 | |
| 9411 | const MockRead kServerChallenge( |
| 9412 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9413 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9414 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9415 | "Content-Length: 14\r\n\r\n" |
| 9416 | "Unauthorized\r\n"); |
| 9417 | const MockRead kSuccess( |
| 9418 | "HTTP/1.1 200 OK\r\n" |
| 9419 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9420 | "Content-Length: 3\r\n\r\n" |
| 9421 | "Yes"); |
| 9422 | |
| 9423 | MockWrite writes[] = { |
| 9424 | // First round |
| 9425 | kGet, |
| 9426 | // Second round |
| 9427 | kGetAuth, |
| 9428 | // Third round |
| 9429 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9430 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9431 | kGetAuth, |
| 9432 | // Competing request |
| 9433 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9434 | }; |
| 9435 | MockRead reads[] = { |
| 9436 | // First round |
| 9437 | kServerChallenge, |
| 9438 | // Second round |
| 9439 | kServerChallenge, |
| 9440 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9441 | kServerChallenge, |
| 9442 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9443 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9444 | // Competing response |
| 9445 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9446 | }; |
| 9447 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 9448 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9449 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9450 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9451 | const char* const kSocketGroup = "www.example.com:80"; |
| 9452 | |
| 9453 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9454 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9455 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9456 | if (rv == ERR_IO_PENDING) |
| 9457 | rv = callback.WaitForResult(); |
| 9458 | EXPECT_EQ(OK, rv); |
| 9459 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9460 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9461 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9462 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9463 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9464 | // In between rounds, another request comes in for the same domain. |
| 9465 | // It should not be able to grab the TCP socket that trans has already |
| 9466 | // claimed. |
| 9467 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9468 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9469 | TestCompletionCallback callback_compete; |
| 9470 | rv = trans_compete->Start( |
| 9471 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9472 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9473 | // callback_compete.WaitForResult at this point would stall forever, |
| 9474 | // since the HttpNetworkTransaction does not release the request back to |
| 9475 | // the pool until after authentication completes. |
| 9476 | |
| 9477 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9478 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9479 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9480 | if (rv == ERR_IO_PENDING) |
| 9481 | rv = callback.WaitForResult(); |
| 9482 | EXPECT_EQ(OK, rv); |
| 9483 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9484 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9485 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9486 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9487 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9488 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9489 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9490 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9491 | if (rv == ERR_IO_PENDING) |
| 9492 | rv = callback.WaitForResult(); |
| 9493 | EXPECT_EQ(OK, rv); |
| 9494 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9495 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9496 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9497 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9498 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9499 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9500 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9501 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9502 | if (rv == ERR_IO_PENDING) |
| 9503 | rv = callback.WaitForResult(); |
| 9504 | EXPECT_EQ(OK, rv); |
| 9505 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9506 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9507 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9508 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9509 | |
| 9510 | // Read the body since the fourth round was successful. This will also |
| 9511 | // release the socket back to the pool. |
| 9512 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9513 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9514 | if (rv == ERR_IO_PENDING) |
| 9515 | rv = callback.WaitForResult(); |
| 9516 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9517 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9518 | EXPECT_EQ(0, rv); |
| 9519 | // There are still 0 idle sockets, since the trans_compete transaction |
| 9520 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9521 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9522 | |
| 9523 | // The competing request can now finish. Wait for the headers and then |
| 9524 | // read the body. |
| 9525 | rv = callback_compete.WaitForResult(); |
| 9526 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9527 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9528 | if (rv == ERR_IO_PENDING) |
| 9529 | rv = callback.WaitForResult(); |
| 9530 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9531 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9532 | EXPECT_EQ(0, rv); |
| 9533 | |
| 9534 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9535 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9536 | } |
| 9537 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9538 | // This tests the case that a request is issued via http instead of spdy after |
| 9539 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9540 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9541 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 9542 | std::vector<NextProto> next_protos; |
| 9543 | next_protos.push_back(kProtoHTTP11); |
| 9544 | HttpStreamFactory::SetNextProtos(next_protos); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9545 | HttpRequestInfo request; |
| 9546 | request.method = "GET"; |
| 9547 | request.url = GURL("https://www.google.com/"); |
| 9548 | request.load_flags = 0; |
| 9549 | |
| 9550 | MockWrite data_writes[] = { |
| 9551 | MockWrite("GET / HTTP/1.1\r\n" |
| 9552 | "Host: www.google.com\r\n" |
| 9553 | "Connection: keep-alive\r\n\r\n"), |
| 9554 | }; |
| 9555 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9556 | std::string alternate_protocol_http_header = |
| 9557 | GetAlternateProtocolHttpHeader(); |
| 9558 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9559 | MockRead data_reads[] = { |
| 9560 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9561 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9562 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9563 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9564 | }; |
| 9565 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9566 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9567 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 9568 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 9569 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9570 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9572 | |
| 9573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9574 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9577 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9578 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9579 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9580 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9582 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9583 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9584 | |
| 9585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9586 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9587 | |
| 9588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9589 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9590 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9591 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9592 | |
| 9593 | std::string response_data; |
| 9594 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9595 | EXPECT_EQ("hello world", response_data); |
| 9596 | |
| 9597 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9598 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9599 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9600 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9601 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9602 | // Simulate the SSL handshake completing with an NPN negotiation |
| 9603 | // followed by an immediate server closing of the socket. |
| 9604 | // Fix crash: http://crbug.com/46369 |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9605 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 9606 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9607 | |
| 9608 | HttpRequestInfo request; |
| 9609 | request.method = "GET"; |
| 9610 | request.url = GURL("https://www.google.com/"); |
| 9611 | request.load_flags = 0; |
| 9612 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9613 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9614 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9616 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9617 | scoped_ptr<SpdyFrame> req( |
| 9618 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9619 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9620 | |
| 9621 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9622 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9623 | }; |
| 9624 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9625 | DelayedSocketData spdy_data( |
| 9626 | 0, // don't wait in this case, immediate hangup. |
| 9627 | spdy_reads, arraysize(spdy_reads), |
| 9628 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9629 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9631 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9632 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9633 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9634 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9635 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9637 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9638 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9639 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 9640 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9641 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9642 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 9643 | // it gets it. This is needed since the auth handler may get destroyed |
| 9644 | // before we get a chance to query it. |
| 9645 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 9646 | public: |
| 9647 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 9648 | |
| 9649 | virtual ~UrlRecordingHttpAuthHandlerMock() {} |
| 9650 | |
| 9651 | protected: |
| 9652 | virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 9653 | const HttpRequestInfo* request, |
| 9654 | const CompletionCallback& callback, |
| 9655 | std::string* auth_token) OVERRIDE { |
| 9656 | *url_ = request->url; |
| 9657 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 9658 | credentials, request, callback, auth_token); |
| 9659 | } |
| 9660 | |
| 9661 | private: |
| 9662 | GURL* url_; |
| 9663 | }; |
| 9664 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9665 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9666 | // This test ensures that the URL passed into the proxy is upgraded |
| 9667 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9668 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9669 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9670 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9671 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9672 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 9673 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9674 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9675 | GURL request_url; |
| 9676 | { |
| 9677 | HttpAuthHandlerMock::Factory* auth_factory = |
| 9678 | new HttpAuthHandlerMock::Factory(); |
| 9679 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 9680 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 9681 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9682 | auth_factory->set_do_init_from_challenge(true); |
| 9683 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9684 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9685 | |
| 9686 | HttpRequestInfo request; |
| 9687 | request.method = "GET"; |
| 9688 | request.url = GURL("http://www.google.com"); |
| 9689 | request.load_flags = 0; |
| 9690 | |
| 9691 | // First round goes unauthenticated through the proxy. |
| 9692 | MockWrite data_writes_1[] = { |
| 9693 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 9694 | "Host: www.google.com\r\n" |
| 9695 | "Proxy-Connection: keep-alive\r\n" |
| 9696 | "\r\n"), |
| 9697 | }; |
| 9698 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9699 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9700 | MockRead("HTTP/1.1 200 OK\r\n" |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9701 | "Alternate-Protocol: 443:npn-spdy/2\r\n" |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9702 | "Proxy-Connection: close\r\n" |
| 9703 | "\r\n"), |
| 9704 | }; |
| 9705 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 9706 | data_writes_1, arraysize(data_writes_1)); |
| 9707 | |
| 9708 | // Second round tries to tunnel to www.google.com due to the |
| 9709 | // Alternate-Protocol announcement in the first round. It fails due |
| 9710 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9711 | // After the failure, a tunnel is established to www.google.com using |
| 9712 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 9713 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9714 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 9715 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 9716 | // does a Disconnect and Connect on the same socket, rather than trying |
| 9717 | // to obtain a new one. |
| 9718 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9719 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 9720 | // simply returned another 407 so the unit test could skip the SSL connection |
| 9721 | // establishment and SPDY framing issues. Alas, the |
| 9722 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9723 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9724 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9725 | scoped_ptr<SpdyFrame> req( |
| 9726 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9727 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9728 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9729 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9730 | MockWrite data_writes_2[] = { |
| 9731 | // First connection attempt without Proxy-Authorization. |
| 9732 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9733 | "Host: www.google.com\r\n" |
| 9734 | "Proxy-Connection: keep-alive\r\n" |
| 9735 | "\r\n"), |
| 9736 | |
| 9737 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9738 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9739 | "Host: www.google.com\r\n" |
| 9740 | "Proxy-Connection: keep-alive\r\n" |
| 9741 | "Proxy-Authorization: auth_token\r\n" |
| 9742 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9743 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9744 | // SPDY request |
| 9745 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9746 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9747 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 9748 | "Proxy-Authenticate: Mock\r\n" |
| 9749 | "Proxy-Connection: close\r\n" |
| 9750 | "\r\n"); |
| 9751 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9752 | MockRead data_reads_2[] = { |
| 9753 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9754 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 9755 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9756 | arraysize(kRejectConnectResponse) - 1, 1), |
| 9757 | |
| 9758 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9759 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9760 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9761 | |
| 9762 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9763 | CreateMockRead(*resp.get(), 6), |
| 9764 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9765 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 9766 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9767 | OrderedSocketData data_2( |
| 9768 | data_reads_2, arraysize(data_reads_2), |
| 9769 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9770 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9771 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9772 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9773 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9774 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9775 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9776 | NULL, 0, NULL, 0); |
| 9777 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9778 | never_finishing_connect); |
| 9779 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9780 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 9781 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 9782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9783 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9784 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9786 | |
| 9787 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9788 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9789 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9790 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9791 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9792 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9793 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 9794 | |
| 9795 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9796 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9797 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9798 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9799 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9801 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 9802 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9803 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9804 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 9805 | |
| 9806 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9807 | TestCompletionCallback callback_3; |
| 9808 | rv = trans_2->RestartWithAuth( |
| 9809 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9811 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 9812 | |
| 9813 | // After all that work, these two lines (or actually, just the scheme) are |
| 9814 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9815 | EXPECT_EQ("https", request_url.scheme()); |
| 9816 | EXPECT_EQ("www.google.com", request_url.host()); |
| 9817 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9818 | LoadTimingInfo load_timing_info; |
| 9819 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 9820 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9821 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9822 | } |
| 9823 | |
| 9824 | // Test that if we cancel the transaction as the connection is completing, that |
| 9825 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9826 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9827 | // Setup everything about the connection to complete synchronously, so that |
| 9828 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 9829 | // for is the callback from the HttpStreamRequest. |
| 9830 | // Then cancel the transaction. |
| 9831 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9832 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9833 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9834 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 9835 | MockRead(SYNCHRONOUS, "hello world"), |
| 9836 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9837 | }; |
| 9838 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9839 | HttpRequestInfo request; |
| 9840 | request.method = "GET"; |
| 9841 | request.url = GURL("http://www.google.com/"); |
| 9842 | request.load_flags = 0; |
| 9843 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9844 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9845 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9846 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9847 | CreateSession(&session_deps_))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9848 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9849 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9850 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9853 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9854 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9855 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9856 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 9857 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9858 | trans.reset(); // Cancel the transaction here. |
| 9859 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 9860 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 9861 | } |
| 9862 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9863 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9864 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9865 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9866 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9867 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9868 | session_deps_.net_log = log.bound().net_log(); |
| 9869 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9870 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9871 | HttpRequestInfo request; |
| 9872 | request.method = "GET"; |
| 9873 | request.url = GURL("http://www.google.com/"); |
| 9874 | |
| 9875 | MockWrite data_writes1[] = { |
| 9876 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 9877 | "Host: www.google.com\r\n" |
| 9878 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9879 | }; |
| 9880 | |
| 9881 | MockRead data_reads1[] = { |
| 9882 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9883 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9884 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9885 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9886 | }; |
| 9887 | |
| 9888 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9889 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9890 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9892 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9893 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9894 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9897 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9899 | |
| 9900 | rv = callback1.WaitForResult(); |
| 9901 | EXPECT_EQ(OK, rv); |
| 9902 | |
| 9903 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9904 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9905 | |
| 9906 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9907 | EXPECT_EQ(200, response->headers->response_code()); |
| 9908 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9909 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 9910 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9911 | |
| 9912 | LoadTimingInfo load_timing_info; |
| 9913 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9914 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9915 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9916 | } |
| 9917 | |
| 9918 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9919 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9920 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9921 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9922 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9923 | session_deps_.net_log = log.bound().net_log(); |
| 9924 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9925 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9926 | HttpRequestInfo request; |
| 9927 | request.method = "GET"; |
| 9928 | request.url = GURL("https://www.google.com/"); |
| 9929 | |
| 9930 | // Since we have proxy, should try to establish tunnel. |
| 9931 | MockWrite data_writes1[] = { |
| 9932 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9933 | "Host: www.google.com\r\n" |
| 9934 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9935 | |
| 9936 | MockWrite("GET / HTTP/1.1\r\n" |
| 9937 | "Host: www.google.com\r\n" |
| 9938 | "Connection: keep-alive\r\n\r\n"), |
| 9939 | }; |
| 9940 | |
| 9941 | MockRead data_reads1[] = { |
| 9942 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 9943 | |
| 9944 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9945 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9946 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9948 | }; |
| 9949 | |
| 9950 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9951 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9953 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9956 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9957 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9958 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9959 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9961 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9962 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9963 | |
| 9964 | rv = callback1.WaitForResult(); |
| 9965 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 9966 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9967 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9968 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9969 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9970 | NetLog::PHASE_NONE); |
| 9971 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 9972 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9973 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9974 | NetLog::PHASE_NONE); |
| 9975 | |
| 9976 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9977 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9978 | |
| 9979 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9980 | EXPECT_EQ(200, response->headers->response_code()); |
| 9981 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9982 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9983 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9984 | |
| 9985 | LoadTimingInfo load_timing_info; |
| 9986 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9987 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9988 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9989 | } |
| 9990 | |
| 9991 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 9992 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9993 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9994 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 9995 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9996 | session_deps_.net_log = log.bound().net_log(); |
| 9997 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9998 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9999 | HttpRequestInfo request; |
| 10000 | request.method = "GET"; |
| 10001 | request.url = GURL("https://www.google.com/"); |
| 10002 | |
| 10003 | // Since we have proxy, should try to establish tunnel. |
| 10004 | MockWrite data_writes1[] = { |
| 10005 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10006 | "Host: www.google.com\r\n" |
| 10007 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10008 | |
| 10009 | MockWrite("GET / HTTP/1.1\r\n" |
| 10010 | "Host: www.google.com\r\n" |
| 10011 | "Connection: keep-alive\r\n\r\n"), |
| 10012 | }; |
| 10013 | |
| 10014 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10015 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10016 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10017 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10018 | }; |
| 10019 | |
| 10020 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10021 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10022 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10023 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10026 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10027 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10028 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10031 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10033 | |
| 10034 | rv = callback1.WaitForResult(); |
| 10035 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10036 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10037 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10038 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10039 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10040 | NetLog::PHASE_NONE); |
| 10041 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10042 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10043 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10044 | NetLog::PHASE_NONE); |
| 10045 | } |
| 10046 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10047 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10048 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10049 | scoped_ptr<SpdyFrame> req( |
| 10050 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10051 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10052 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10053 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10054 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10055 | MockRead spdy_reads[] = { |
| 10056 | CreateMockRead(*resp), |
| 10057 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10058 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10059 | }; |
| 10060 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10061 | DelayedSocketData spdy_data( |
| 10062 | 1, // wait for one write to finish before reading. |
| 10063 | spdy_reads, arraysize(spdy_reads), |
| 10064 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10065 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10066 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10067 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10068 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10070 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10071 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10072 | |
| 10073 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10074 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10075 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 10076 | kPrivacyModeDisabled); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10077 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10078 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10079 | |
| 10080 | HttpRequestInfo request; |
| 10081 | request.method = "GET"; |
| 10082 | request.url = GURL("https://www.google.com/"); |
| 10083 | request.load_flags = 0; |
| 10084 | |
| 10085 | // This is the important line that marks this as a preconnect. |
| 10086 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10087 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10088 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10089 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10090 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10091 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10092 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10093 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10094 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10095 | } |
| 10096 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10097 | // Given a net error, cause that error to be returned from the first Write() |
| 10098 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10099 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10100 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10101 | net::HttpRequestInfo request_info; |
| 10102 | request_info.url = GURL("https://www.example.com/"); |
| 10103 | request_info.method = "GET"; |
| 10104 | request_info.load_flags = net::LOAD_NORMAL; |
| 10105 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10106 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10107 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10108 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10109 | }; |
| 10110 | net::StaticSocketDataProvider data(NULL, 0, |
| 10111 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10114 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10115 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10116 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10117 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10119 | TestCompletionCallback callback; |
| 10120 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10121 | if (rv == net::ERR_IO_PENDING) |
| 10122 | rv = callback.WaitForResult(); |
| 10123 | ASSERT_EQ(error, rv); |
| 10124 | } |
| 10125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10126 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10127 | // Just check a grab bag of cert errors. |
| 10128 | static const int kErrors[] = { |
| 10129 | ERR_CERT_COMMON_NAME_INVALID, |
| 10130 | ERR_CERT_AUTHORITY_INVALID, |
| 10131 | ERR_CERT_DATE_INVALID, |
| 10132 | }; |
| 10133 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10134 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10135 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10136 | } |
| 10137 | } |
| 10138 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10139 | // Ensure that a client certificate is removed from the SSL client auth |
| 10140 | // cache when: |
| 10141 | // 1) No proxy is involved. |
| 10142 | // 2) TLS False Start is disabled. |
| 10143 | // 3) The initial TLS handshake requests a client certificate. |
| 10144 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10145 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10146 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10147 | net::HttpRequestInfo request_info; |
| 10148 | request_info.url = GURL("https://www.example.com/"); |
| 10149 | request_info.method = "GET"; |
| 10150 | request_info.load_flags = net::LOAD_NORMAL; |
| 10151 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10152 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10153 | cert_request->host_and_port = "www.example.com:443"; |
| 10154 | |
| 10155 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10156 | // CertificateRequest is received for the first time, the handshake will |
| 10157 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10158 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10159 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10161 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10162 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10163 | |
| 10164 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10165 | // False Start is not being used, the result of the SSL handshake will be |
| 10166 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10167 | // matches the result of a server sending a handshake_failure alert, |
| 10168 | // rather than a Finished message, because it requires a client |
| 10169 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10170 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10171 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10173 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10174 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10175 | |
| 10176 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10177 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10178 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10179 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10180 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10181 | // requiring a client certificate, this fallback handshake should also |
| 10182 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10183 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10184 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10185 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10186 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10187 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10188 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10189 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10190 | // connection to a server fails during an SSL handshake, |
| 10191 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10192 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10193 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10194 | // requiring a client certificate, this fallback handshake should also |
| 10195 | // fail. |
| 10196 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10197 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10199 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10200 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10201 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10202 | // Need one more if TLSv1.2 is enabled. |
| 10203 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10204 | ssl_data5.cert_request_info = cert_request.get(); |
| 10205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10206 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10207 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10208 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10209 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10210 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10212 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10213 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10214 | TestCompletionCallback callback; |
| 10215 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10216 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10217 | |
| 10218 | // Complete the SSL handshake, which should abort due to requiring a |
| 10219 | // client certificate. |
| 10220 | rv = callback.WaitForResult(); |
| 10221 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10222 | |
| 10223 | // Indicate that no certificate should be supplied. From the perspective |
| 10224 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10225 | // certificate, so this is the same as supply a |
| 10226 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10227 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10228 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10229 | |
| 10230 | // Ensure the certificate was added to the client auth cache before |
| 10231 | // allowing the connection to continue restarting. |
| 10232 | scoped_refptr<X509Certificate> client_cert; |
| 10233 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10234 | &client_cert)); |
| 10235 | ASSERT_EQ(NULL, client_cert.get()); |
| 10236 | |
| 10237 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10238 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10239 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10240 | rv = callback.WaitForResult(); |
| 10241 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10242 | |
| 10243 | // Ensure that the client certificate is removed from the cache on a |
| 10244 | // handshake failure. |
| 10245 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10246 | &client_cert)); |
| 10247 | } |
| 10248 | |
| 10249 | // Ensure that a client certificate is removed from the SSL client auth |
| 10250 | // cache when: |
| 10251 | // 1) No proxy is involved. |
| 10252 | // 2) TLS False Start is enabled. |
| 10253 | // 3) The initial TLS handshake requests a client certificate. |
| 10254 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10255 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10256 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10257 | net::HttpRequestInfo request_info; |
| 10258 | request_info.url = GURL("https://www.example.com/"); |
| 10259 | request_info.method = "GET"; |
| 10260 | request_info.load_flags = net::LOAD_NORMAL; |
| 10261 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10262 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10263 | cert_request->host_and_port = "www.example.com:443"; |
| 10264 | |
| 10265 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 10266 | // return successfully after reading up to the peer's Certificate message. |
| 10267 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 10268 | // enqueue application data to be sent in the same packet as the |
| 10269 | // ChangeCipherSpec and Finished messages. |
| 10270 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 10271 | // called, which expects to process the peer's ChangeCipherSpec and |
| 10272 | // Finished messages. If there was an error negotiating with the peer, |
| 10273 | // such as due to the peer requiring a client certificate when none was |
| 10274 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 10275 | // called. |
| 10276 | |
| 10277 | // Like the non-False Start case, when a client certificate is requested by |
| 10278 | // the peer, the handshake is aborted during the Connect() call. |
| 10279 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10280 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10281 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10283 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10284 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10285 | |
| 10286 | // When a client certificate is supplied, Connect() will not be aborted |
| 10287 | // when the peer requests the certificate. Instead, the handshake will |
| 10288 | // artificially succeed, allowing the caller to write the HTTP request to |
| 10289 | // the socket. The handshake messages are not processed until Read() is |
| 10290 | // called, which then detects that the handshake was aborted, due to the |
| 10291 | // peer sending a handshake_failure because it requires a client |
| 10292 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10293 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10294 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10296 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10297 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10298 | }; |
| 10299 | net::StaticSocketDataProvider data2( |
| 10300 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10301 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10302 | |
| 10303 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10304 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 10305 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10306 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10307 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10309 | net::StaticSocketDataProvider data3( |
| 10310 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10311 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10312 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10313 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 10314 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 10315 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 10316 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10318 | net::StaticSocketDataProvider data4( |
| 10319 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10320 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10321 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10322 | // Need one more if TLSv1.2 is enabled. |
| 10323 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 10324 | ssl_data5.cert_request_info = cert_request.get(); |
| 10325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10326 | net::StaticSocketDataProvider data5( |
| 10327 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 10328 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10329 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10331 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10333 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10334 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10335 | TestCompletionCallback callback; |
| 10336 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10337 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10338 | |
| 10339 | // Complete the SSL handshake, which should abort due to requiring a |
| 10340 | // client certificate. |
| 10341 | rv = callback.WaitForResult(); |
| 10342 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10343 | |
| 10344 | // Indicate that no certificate should be supplied. From the perspective |
| 10345 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10346 | // certificate, so this is the same as supply a |
| 10347 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10348 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10349 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10350 | |
| 10351 | // Ensure the certificate was added to the client auth cache before |
| 10352 | // allowing the connection to continue restarting. |
| 10353 | scoped_refptr<X509Certificate> client_cert; |
| 10354 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10355 | &client_cert)); |
| 10356 | ASSERT_EQ(NULL, client_cert.get()); |
| 10357 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10358 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10359 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10360 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10361 | rv = callback.WaitForResult(); |
| 10362 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10363 | |
| 10364 | // Ensure that the client certificate is removed from the cache on a |
| 10365 | // handshake failure. |
| 10366 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10367 | &client_cert)); |
| 10368 | } |
| 10369 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10370 | // Ensure that a client certificate is removed from the SSL client auth |
| 10371 | // cache when: |
| 10372 | // 1) An HTTPS proxy is involved. |
| 10373 | // 3) The HTTPS proxy requests a client certificate. |
| 10374 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 10375 | // proxy. |
| 10376 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 10377 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10378 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10379 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10380 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10381 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10382 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10383 | |
| 10384 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
| 10385 | cert_request->host_and_port = "proxy:70"; |
| 10386 | |
| 10387 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 10388 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 10389 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 10390 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10391 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10392 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10394 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10395 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10396 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10397 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10398 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10400 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10401 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10402 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10403 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 10404 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10405 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10406 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10408 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10409 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10410 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10411 | |
| 10412 | net::HttpRequestInfo requests[2]; |
| 10413 | requests[0].url = GURL("https://www.example.com/"); |
| 10414 | requests[0].method = "GET"; |
| 10415 | requests[0].load_flags = net::LOAD_NORMAL; |
| 10416 | |
| 10417 | requests[1].url = GURL("http://www.example.com/"); |
| 10418 | requests[1].method = "GET"; |
| 10419 | requests[1].load_flags = net::LOAD_NORMAL; |
| 10420 | |
| 10421 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10422 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 10423 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10424 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10425 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10426 | |
| 10427 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10428 | TestCompletionCallback callback; |
| 10429 | int rv = trans->Start( |
| 10430 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10431 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10432 | |
| 10433 | // Complete the SSL handshake, which should abort due to requiring a |
| 10434 | // client certificate. |
| 10435 | rv = callback.WaitForResult(); |
| 10436 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10437 | |
| 10438 | // Indicate that no certificate should be supplied. From the perspective |
| 10439 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10440 | // certificate, so this is the same as supply a |
| 10441 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10442 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10443 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10444 | |
| 10445 | // Ensure the certificate was added to the client auth cache before |
| 10446 | // allowing the connection to continue restarting. |
| 10447 | scoped_refptr<X509Certificate> client_cert; |
| 10448 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("proxy:70", |
| 10449 | &client_cert)); |
| 10450 | ASSERT_EQ(NULL, client_cert.get()); |
| 10451 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 10452 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
| 10453 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10454 | &client_cert)); |
| 10455 | |
| 10456 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 10457 | // then consume ssl_data3, which should also fail. The result code is |
| 10458 | // checked against what ssl_data3 should return. |
| 10459 | rv = callback.WaitForResult(); |
| 10460 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 10461 | |
| 10462 | // Now that the new handshake has failed, ensure that the client |
| 10463 | // certificate was removed from the client auth cache. |
| 10464 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", |
| 10465 | &client_cert)); |
| 10466 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", |
| 10467 | &client_cert)); |
| 10468 | } |
| 10469 | } |
| 10470 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10471 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 10472 | // TEST_P is a macro that expands directly to code that stringizes the |
| 10473 | // arguments. As a result, macros passed as parameters (such as prefix |
| 10474 | // or test_case_name) will not be expanded by the preprocessor. To |
| 10475 | // work around this, indirect the macro for TEST_P, so that the |
| 10476 | // pre-processor will expand macros such as MAYBE_test_name before |
| 10477 | // instantiating the test. |
| 10478 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 10479 | TEST_P(test_case_name, test_name) |
| 10480 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10481 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10482 | #if defined(OS_WIN) |
| 10483 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 10484 | #else |
| 10485 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 10486 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10487 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10488 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 10489 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10490 | |
| 10491 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10493 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10494 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10495 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10496 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10497 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10498 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10500 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10501 | scoped_ptr<SpdyFrame> host1_req( |
| 10502 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10503 | scoped_ptr<SpdyFrame> host2_req( |
| 10504 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10505 | MockWrite spdy_writes[] = { |
| 10506 | CreateMockWrite(*host1_req, 1), |
| 10507 | CreateMockWrite(*host2_req, 4), |
| 10508 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10509 | scoped_ptr<SpdyFrame> host1_resp( |
| 10510 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10511 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10512 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10513 | scoped_ptr<SpdyFrame> host2_resp( |
| 10514 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10515 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10516 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10517 | MockRead spdy_reads[] = { |
| 10518 | CreateMockRead(*host1_resp, 2), |
| 10519 | CreateMockRead(*host1_resp_body, 3), |
| 10520 | CreateMockRead(*host2_resp, 5), |
| 10521 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10522 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10523 | }; |
| 10524 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10525 | IPAddressNumber ip; |
| 10526 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10527 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10528 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10529 | OrderedSocketData spdy_data( |
| 10530 | connect, |
| 10531 | spdy_reads, arraysize(spdy_reads), |
| 10532 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10533 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10534 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10535 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10536 | HttpRequestInfo request1; |
| 10537 | request1.method = "GET"; |
| 10538 | request1.url = GURL("https://www.google.com/"); |
| 10539 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10540 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10541 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10542 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10543 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10544 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10545 | |
| 10546 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10547 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10548 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10549 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10550 | |
| 10551 | std::string response_data; |
| 10552 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10553 | EXPECT_EQ("hello!", response_data); |
| 10554 | |
| 10555 | // Preload www.gmail.com into HostCache. |
| 10556 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10557 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10558 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10559 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 10560 | DEFAULT_PRIORITY, |
| 10561 | &ignored, |
| 10562 | callback.callback(), |
| 10563 | NULL, |
| 10564 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10565 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10566 | rv = callback.WaitForResult(); |
| 10567 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10568 | |
| 10569 | HttpRequestInfo request2; |
| 10570 | request2.method = "GET"; |
| 10571 | request2.url = GURL("https://www.gmail.com/"); |
| 10572 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10573 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10574 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10575 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10576 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10577 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10578 | |
| 10579 | response = trans2.GetResponseInfo(); |
| 10580 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10581 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10582 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10583 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10584 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10585 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10586 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10587 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10588 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10589 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10590 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10591 | HttpStreamFactory::set_use_alternate_protocols(true); |
| 10592 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
| 10593 | |
| 10594 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10595 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10596 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10597 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10598 | pool_peer.DisableDomainAuthenticationVerification(); |
| 10599 | |
| 10600 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10601 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10603 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10604 | scoped_ptr<SpdyFrame> host1_req( |
| 10605 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10606 | scoped_ptr<SpdyFrame> host2_req( |
| 10607 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10608 | MockWrite spdy_writes[] = { |
| 10609 | CreateMockWrite(*host1_req, 1), |
| 10610 | CreateMockWrite(*host2_req, 4), |
| 10611 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10612 | scoped_ptr<SpdyFrame> host1_resp( |
| 10613 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10614 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10615 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10616 | scoped_ptr<SpdyFrame> host2_resp( |
| 10617 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10618 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10619 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10620 | MockRead spdy_reads[] = { |
| 10621 | CreateMockRead(*host1_resp, 2), |
| 10622 | CreateMockRead(*host1_resp_body, 3), |
| 10623 | CreateMockRead(*host2_resp, 5), |
| 10624 | CreateMockRead(*host2_resp_body, 6), |
| 10625 | MockRead(ASYNC, 0, 7), |
| 10626 | }; |
| 10627 | |
| 10628 | IPAddressNumber ip; |
| 10629 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10630 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10631 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10632 | OrderedSocketData spdy_data( |
| 10633 | connect, |
| 10634 | spdy_reads, arraysize(spdy_reads), |
| 10635 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10637 | |
| 10638 | TestCompletionCallback callback; |
| 10639 | HttpRequestInfo request1; |
| 10640 | request1.method = "GET"; |
| 10641 | request1.url = GURL("https://www.google.com/"); |
| 10642 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10643 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10644 | |
| 10645 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 10646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10647 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10648 | |
| 10649 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10650 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10651 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10652 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10653 | |
| 10654 | std::string response_data; |
| 10655 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10656 | EXPECT_EQ("hello!", response_data); |
| 10657 | |
| 10658 | HttpRequestInfo request2; |
| 10659 | request2.method = "GET"; |
| 10660 | request2.url = GURL("https://www.gmail.com/"); |
| 10661 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10662 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10663 | |
| 10664 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 10665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10666 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10667 | |
| 10668 | response = trans2.GetResponseInfo(); |
| 10669 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10670 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10671 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10672 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10673 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10674 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10675 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10676 | } |
| 10677 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10678 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 10679 | public: |
| 10680 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 10681 | : host_port_(host_port) {} |
| 10682 | virtual ~OneTimeCachingHostResolver() {} |
| 10683 | |
| 10684 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 10685 | |
| 10686 | // HostResolver methods: |
| 10687 | virtual int Resolve(const RequestInfo& info, |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10688 | RequestPriority priority, |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10689 | AddressList* addresses, |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10690 | const CompletionCallback& callback, |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10691 | RequestHandle* out_req, |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10692 | const BoundNetLog& net_log) OVERRIDE { |
| 10693 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10694 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10695 | } |
| 10696 | |
| 10697 | virtual int ResolveFromCache(const RequestInfo& info, |
| 10698 | AddressList* addresses, |
| 10699 | const BoundNetLog& net_log) OVERRIDE { |
| 10700 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 10701 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 10702 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10703 | return rv; |
| 10704 | } |
| 10705 | |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 10706 | virtual void CancelRequest(RequestHandle req) OVERRIDE { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10707 | host_resolver_.CancelRequest(req); |
| 10708 | } |
| 10709 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 10710 | MockCachingHostResolver* GetMockHostResolver() { |
| 10711 | return &host_resolver_; |
| 10712 | } |
| 10713 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10714 | private: |
| 10715 | MockCachingHostResolver host_resolver_; |
| 10716 | const HostPortPair host_port_; |
| 10717 | }; |
| 10718 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10719 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10720 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10721 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 10722 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10723 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10724 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 10725 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10726 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10727 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 10728 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10729 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 10730 | // prefix doesn't work with parametrized tests). |
| 10731 | #if defined(OS_WIN) |
| 10732 | return; |
| 10733 | #endif |
| 10734 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10735 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 10736 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10737 | |
| 10738 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10739 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 10740 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10741 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10742 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10743 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10744 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10745 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10746 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10747 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10748 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10750 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10751 | scoped_ptr<SpdyFrame> host1_req( |
| 10752 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10753 | scoped_ptr<SpdyFrame> host2_req( |
| 10754 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10755 | MockWrite spdy_writes[] = { |
| 10756 | CreateMockWrite(*host1_req, 1), |
| 10757 | CreateMockWrite(*host2_req, 4), |
| 10758 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10759 | scoped_ptr<SpdyFrame> host1_resp( |
| 10760 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10761 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10762 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10763 | scoped_ptr<SpdyFrame> host2_resp( |
| 10764 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10765 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10766 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10767 | MockRead spdy_reads[] = { |
| 10768 | CreateMockRead(*host1_resp, 2), |
| 10769 | CreateMockRead(*host1_resp_body, 3), |
| 10770 | CreateMockRead(*host2_resp, 5), |
| 10771 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10772 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10773 | }; |
| 10774 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10775 | IPAddressNumber ip; |
| 10776 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10777 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10778 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10779 | OrderedSocketData spdy_data( |
| 10780 | connect, |
| 10781 | spdy_reads, arraysize(spdy_reads), |
| 10782 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10783 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10784 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10785 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10786 | HttpRequestInfo request1; |
| 10787 | request1.method = "GET"; |
| 10788 | request1.url = GURL("https://www.google.com/"); |
| 10789 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10790 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10792 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10794 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10795 | |
| 10796 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10797 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10798 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10799 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10800 | |
| 10801 | std::string response_data; |
| 10802 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10803 | EXPECT_EQ("hello!", response_data); |
| 10804 | |
| 10805 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10806 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10807 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 10808 | rv = host_resolver.Resolve(resolve_info, |
| 10809 | DEFAULT_PRIORITY, |
| 10810 | &ignored, |
| 10811 | callback.callback(), |
| 10812 | NULL, |
| 10813 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10815 | rv = callback.WaitForResult(); |
| 10816 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10817 | |
| 10818 | HttpRequestInfo request2; |
| 10819 | request2.method = "GET"; |
| 10820 | request2.url = GURL("https://www.gmail.com/"); |
| 10821 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10822 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10824 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10826 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10827 | |
| 10828 | response = trans2.GetResponseInfo(); |
| 10829 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10830 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10831 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10832 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10833 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10834 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10835 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10836 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10837 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10838 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10839 | TEST_P(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10840 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10841 | MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10842 | }; |
| 10843 | MockRead data_reads2[] = { |
| 10844 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10845 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10847 | }; |
| 10848 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); |
| 10849 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); |
| 10850 | StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 10851 | |
| 10852 | SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 10853 | |
| 10854 | EXPECT_EQ(OK, out.rv); |
| 10855 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 10856 | EXPECT_EQ("hello world", out.response_data); |
| 10857 | } |
| 10858 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10859 | TEST_P(HttpNetworkTransactionTest, SendPipelineEvictionFallback) { |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10860 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10861 | MockWrite(SYNCHRONOUS, ERR_PIPELINE_EVICTION), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10862 | }; |
| 10863 | MockWrite data_writes2[] = { |
| 10864 | MockWrite("GET / HTTP/1.1\r\n" |
| 10865 | "Host: www.google.com\r\n" |
| 10866 | "Connection: keep-alive\r\n\r\n"), |
| 10867 | }; |
| 10868 | MockRead data_reads2[] = { |
| 10869 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10870 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 10872 | }; |
| 10873 | StaticSocketDataProvider data1(NULL, 0, |
| 10874 | data_writes1, arraysize(data_writes1)); |
| 10875 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10876 | data_writes2, arraysize(data_writes2)); |
| 10877 | StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 10878 | |
| 10879 | SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 10880 | |
| 10881 | EXPECT_EQ(OK, out.rv); |
| 10882 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 10883 | EXPECT_EQ("hello world", out.response_data); |
| 10884 | } |
| 10885 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10886 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10887 | const std::string https_url = "https://www.google.com/"; |
| 10888 | const std::string http_url = "http://www.google.com:443/"; |
| 10889 | |
| 10890 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10891 | scoped_ptr<SpdyFrame> req1( |
| 10892 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10893 | |
| 10894 | MockWrite writes1[] = { |
| 10895 | CreateMockWrite(*req1, 0), |
| 10896 | }; |
| 10897 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10898 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10899 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10900 | MockRead reads1[] = { |
| 10901 | CreateMockRead(*resp1, 1), |
| 10902 | CreateMockRead(*body1, 2), |
| 10903 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 10904 | }; |
| 10905 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10906 | DelayedSocketData data1( |
| 10907 | 1, reads1, arraysize(reads1), |
| 10908 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10909 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10910 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10911 | |
| 10912 | // HTTP GET for the HTTP URL |
| 10913 | MockWrite writes2[] = { |
| 10914 | MockWrite(ASYNC, 4, |
| 10915 | "GET / HTTP/1.1\r\n" |
| 10916 | "Host: www.google.com:443\r\n" |
| 10917 | "Connection: keep-alive\r\n\r\n"), |
| 10918 | }; |
| 10919 | |
| 10920 | MockRead reads2[] = { |
| 10921 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 10922 | MockRead(ASYNC, 6, "hello"), |
| 10923 | MockRead(ASYNC, 7, OK), |
| 10924 | }; |
| 10925 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10926 | DelayedSocketData data2( |
| 10927 | 1, reads2, arraysize(reads2), |
| 10928 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10929 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10930 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10931 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10933 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10935 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10936 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10937 | |
| 10938 | // Start the first transaction to set up the SpdySession |
| 10939 | HttpRequestInfo request1; |
| 10940 | request1.method = "GET"; |
| 10941 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10942 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10943 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10944 | TestCompletionCallback callback1; |
| 10945 | EXPECT_EQ(ERR_IO_PENDING, |
| 10946 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10947 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10948 | |
| 10949 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10950 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 10951 | |
| 10952 | // Now, start the HTTP request |
| 10953 | HttpRequestInfo request2; |
| 10954 | request2.method = "GET"; |
| 10955 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10956 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10957 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10958 | TestCompletionCallback callback2; |
| 10959 | EXPECT_EQ(ERR_IO_PENDING, |
| 10960 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10961 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10962 | |
| 10963 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10964 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 10965 | } |
| 10966 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10967 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10968 | const std::string https_url = "https://www.google.com/"; |
| 10969 | const std::string http_url = "http://www.google.com:443/"; |
| 10970 | |
| 10971 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 10972 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 10973 | LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10974 | scoped_ptr<SpdyFrame> req1( |
| 10975 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10976 | |
| 10977 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10978 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 10979 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10980 | const char* const headers[] = { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10981 | spdy_util_.GetMethodKey(), "GET", |
| 10982 | spdy_util_.GetPathKey(), spdy_util_.is_spdy2() ? http_url.c_str() : "/", |
| 10983 | spdy_util_.GetHostKey(), "www.google.com:443", |
| 10984 | spdy_util_.GetSchemeKey(), "http", |
| 10985 | spdy_util_.GetVersionKey(), "HTTP/1.1" |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10986 | }; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 10987 | scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyControlFrame( |
| 10988 | NULL, 0, false, 3, MEDIUM, SYN_STREAM, CONTROL_FLAG_FIN, |
| 10989 | headers, arraysize(headers), 0)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 10990 | |
| 10991 | MockWrite writes1[] = { |
| 10992 | CreateMockWrite(*connect, 0), |
| 10993 | CreateMockWrite(*wrapped_req1, 2), |
| 10994 | CreateMockWrite(*req2, 5), |
| 10995 | }; |
| 10996 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10997 | scoped_ptr<SpdyFrame> conn_resp( |
| 10998 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10999 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11000 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11001 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11002 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11003 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11004 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11005 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11006 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11007 | MockRead reads1[] = { |
| 11008 | CreateMockRead(*conn_resp, 1), |
| 11009 | CreateMockRead(*wrapped_resp1, 3), |
| 11010 | CreateMockRead(*wrapped_body1, 4), |
| 11011 | CreateMockRead(*resp2, 6), |
| 11012 | CreateMockRead(*body2, 7), |
| 11013 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11014 | }; |
| 11015 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11016 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11017 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11018 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11019 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11020 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11021 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11022 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 11023 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11024 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11025 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11026 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11027 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11028 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11029 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11030 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11031 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11032 | |
| 11033 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11034 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11035 | |
| 11036 | // Start the first transaction to set up the SpdySession |
| 11037 | HttpRequestInfo request1; |
| 11038 | request1.method = "GET"; |
| 11039 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11040 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11041 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11042 | TestCompletionCallback callback1; |
| 11043 | EXPECT_EQ(ERR_IO_PENDING, |
| 11044 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11045 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11046 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11047 | |
| 11048 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11049 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11050 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11051 | LoadTimingInfo load_timing_info1; |
| 11052 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11053 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11054 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11055 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11056 | // Now, start the HTTP request |
| 11057 | HttpRequestInfo request2; |
| 11058 | request2.method = "GET"; |
| 11059 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11060 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11061 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11062 | TestCompletionCallback callback2; |
| 11063 | EXPECT_EQ(ERR_IO_PENDING, |
| 11064 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11065 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11066 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11067 | |
| 11068 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11069 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11070 | |
| 11071 | LoadTimingInfo load_timing_info2; |
| 11072 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11073 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11074 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11075 | // HTTP requests over a SPDY session should have a different connection |
| 11076 | // socket_log_id than requests over a tunnel. |
| 11077 | 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] | 11078 | } |
| 11079 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11080 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11081 | HttpStreamFactory::set_force_spdy_always(true); |
| 11082 | const std::string https_url = "https://www.google.com/"; |
| 11083 | const std::string http_url = "http://www.google.com:443/"; |
| 11084 | |
| 11085 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11086 | scoped_ptr<SpdyFrame> req1( |
| 11087 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11088 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11089 | scoped_ptr<SpdyFrame> req2( |
| 11090 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11091 | |
| 11092 | MockWrite writes[] = { |
| 11093 | CreateMockWrite(*req1, 1), |
| 11094 | CreateMockWrite(*req2, 4), |
| 11095 | }; |
| 11096 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11097 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11098 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11099 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11100 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11101 | MockRead reads[] = { |
| 11102 | CreateMockRead(*resp1, 2), |
| 11103 | CreateMockRead(*body1, 3), |
| 11104 | CreateMockRead(*resp2, 5), |
| 11105 | CreateMockRead(*body2, 6), |
| 11106 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11107 | }; |
| 11108 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11109 | OrderedSocketData data(reads, arraysize(reads), |
| 11110 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11111 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11112 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11113 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11116 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11117 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11118 | |
| 11119 | // Start the first transaction to set up the SpdySession |
| 11120 | HttpRequestInfo request1; |
| 11121 | request1.method = "GET"; |
| 11122 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11123 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11124 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11125 | TestCompletionCallback callback1; |
| 11126 | EXPECT_EQ(ERR_IO_PENDING, |
| 11127 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11128 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11129 | |
| 11130 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11131 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11132 | |
| 11133 | // Now, start the HTTP request |
| 11134 | HttpRequestInfo request2; |
| 11135 | request2.method = "GET"; |
| 11136 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11137 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11138 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11139 | TestCompletionCallback callback2; |
| 11140 | EXPECT_EQ(ERR_IO_PENDING, |
| 11141 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11142 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11143 | |
| 11144 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11145 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11146 | } |
| 11147 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11148 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11149 | // that we do not pool other origins that resolve to the same IP when |
| 11150 | // the certificate does not match the new origin. |
| 11151 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11152 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11153 | const std::string url1 = "http://www.google.com/"; |
| 11154 | const std::string url2 = "https://mail.google.com/"; |
| 11155 | const std::string ip_addr = "1.2.3.4"; |
| 11156 | |
| 11157 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11158 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11159 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 11160 | scoped_ptr<SpdyFrame> req1(spdy_util_.ConstructSpdyControlFrame( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11161 | headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11162 | |
| 11163 | MockWrite writes1[] = { |
| 11164 | CreateMockWrite(*req1, 0), |
| 11165 | }; |
| 11166 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11167 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11168 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11169 | MockRead reads1[] = { |
| 11170 | CreateMockRead(*resp1, 1), |
| 11171 | CreateMockRead(*body1, 2), |
| 11172 | MockRead(ASYNC, OK, 3) // EOF |
| 11173 | }; |
| 11174 | |
| 11175 | scoped_ptr<DeterministicSocketData> data1( |
| 11176 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11177 | writes1, arraysize(writes1))); |
| 11178 | IPAddressNumber ip; |
| 11179 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11180 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11181 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11182 | data1->set_connect_data(connect_data1); |
| 11183 | |
| 11184 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11185 | scoped_ptr<SpdyFrame> req2( |
| 11186 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11187 | |
| 11188 | MockWrite writes2[] = { |
| 11189 | CreateMockWrite(*req2, 0), |
| 11190 | }; |
| 11191 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11192 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11193 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11194 | MockRead reads2[] = { |
| 11195 | CreateMockRead(*resp2, 1), |
| 11196 | CreateMockRead(*body2, 2), |
| 11197 | MockRead(ASYNC, OK, 3) // EOF |
| 11198 | }; |
| 11199 | |
| 11200 | scoped_ptr<DeterministicSocketData> data2( |
| 11201 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11202 | writes2, arraysize(writes2))); |
| 11203 | MockConnect connect_data2(ASYNC, OK); |
| 11204 | data2->set_connect_data(connect_data2); |
| 11205 | |
| 11206 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11207 | // all others direct. |
| 11208 | ProxyConfig proxy_config; |
| 11209 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11210 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11211 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11212 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11213 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11214 | NULL)); |
| 11215 | |
| 11216 | // Load a valid cert. Note, that this does not need to |
| 11217 | // be valid for proxy because the MockSSLClientSocket does |
| 11218 | // not actually verify it. But SpdySession will use this |
| 11219 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11220 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11221 | scoped_refptr<X509Certificate> server_cert( |
| 11222 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
| 11223 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 11224 | |
| 11225 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11226 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11227 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11228 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11229 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11230 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11231 | |
| 11232 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11233 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11234 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11235 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11236 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11237 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11238 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11239 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11240 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11241 | |
| 11242 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11243 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11244 | |
| 11245 | // Start the first transaction to set up the SpdySession |
| 11246 | HttpRequestInfo request1; |
| 11247 | request1.method = "GET"; |
| 11248 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11249 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11250 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11251 | TestCompletionCallback callback1; |
| 11252 | ASSERT_EQ(ERR_IO_PENDING, |
| 11253 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11254 | data1->RunFor(3); |
| 11255 | |
| 11256 | ASSERT_TRUE(callback1.have_result()); |
| 11257 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11258 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11259 | |
| 11260 | // Now, start the HTTP request |
| 11261 | HttpRequestInfo request2; |
| 11262 | request2.method = "GET"; |
| 11263 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11264 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11265 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11266 | TestCompletionCallback callback2; |
| 11267 | EXPECT_EQ(ERR_IO_PENDING, |
| 11268 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11269 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11270 | data2->RunFor(3); |
| 11271 | |
| 11272 | ASSERT_TRUE(callback2.have_result()); |
| 11273 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11274 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11275 | } |
| 11276 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11277 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11278 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11279 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11280 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11281 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11282 | const std::string https_url = "https://www.google.com/"; |
| 11283 | |
| 11284 | MockRead reads1[] = { |
| 11285 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11286 | }; |
| 11287 | |
| 11288 | scoped_ptr<DeterministicSocketData> data1( |
| 11289 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11290 | data1->SetStop(1); |
| 11291 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11292 | scoped_ptr<SpdyFrame> req2( |
| 11293 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11294 | MockWrite writes2[] = { |
| 11295 | CreateMockWrite(*req2, 0), |
| 11296 | }; |
| 11297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11298 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11299 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11300 | MockRead reads2[] = { |
| 11301 | CreateMockRead(*resp2, 1), |
| 11302 | CreateMockRead(*body2, 2), |
| 11303 | MockRead(ASYNC, OK, 3) // EOF |
| 11304 | }; |
| 11305 | |
| 11306 | scoped_ptr<DeterministicSocketData> data2( |
| 11307 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11308 | writes2, arraysize(writes2))); |
| 11309 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11310 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11311 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11312 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11313 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11314 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11315 | |
| 11316 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11317 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11318 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11319 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11320 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11321 | |
| 11322 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11323 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11324 | |
| 11325 | // Start the first transaction to set up the SpdySession and verify that |
| 11326 | // connection was closed. |
| 11327 | HttpRequestInfo request1; |
| 11328 | request1.method = "GET"; |
| 11329 | request1.url = GURL(https_url); |
| 11330 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11331 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11332 | TestCompletionCallback callback1; |
| 11333 | EXPECT_EQ(ERR_IO_PENDING, |
| 11334 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11335 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11336 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11337 | |
| 11338 | // Now, start the second request and make sure it succeeds. |
| 11339 | HttpRequestInfo request2; |
| 11340 | request2.method = "GET"; |
| 11341 | request2.url = GURL(https_url); |
| 11342 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11343 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11344 | TestCompletionCallback callback2; |
| 11345 | EXPECT_EQ(ERR_IO_PENDING, |
| 11346 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11347 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11348 | data2->RunFor(3); |
| 11349 | |
| 11350 | ASSERT_TRUE(callback2.have_result()); |
| 11351 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11352 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11353 | } |
| 11354 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11355 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11356 | HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
| 11357 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 11358 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11359 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 11360 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11361 | |
| 11362 | // Use two different hosts with different IPs so they don't get pooled. |
| 11363 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 11364 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 11365 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11366 | |
| 11367 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11368 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11369 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11370 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11373 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11374 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11375 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 11376 | MockWrite spdy1_writes[] = { |
| 11377 | CreateMockWrite(*host1_req, 1), |
| 11378 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11379 | scoped_ptr<SpdyFrame> host1_resp( |
| 11380 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11381 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11382 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11383 | MockRead spdy1_reads[] = { |
| 11384 | CreateMockRead(*host1_resp, 2), |
| 11385 | CreateMockRead(*host1_resp_body, 3), |
| 11386 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11387 | }; |
| 11388 | |
| 11389 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 11390 | new OrderedSocketData( |
| 11391 | spdy1_reads, arraysize(spdy1_reads), |
| 11392 | spdy1_writes, arraysize(spdy1_writes))); |
| 11393 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 11394 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11395 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11396 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 11397 | MockWrite spdy2_writes[] = { |
| 11398 | CreateMockWrite(*host2_req, 1), |
| 11399 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11400 | scoped_ptr<SpdyFrame> host2_resp( |
| 11401 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11402 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11403 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11404 | MockRead spdy2_reads[] = { |
| 11405 | CreateMockRead(*host2_resp, 2), |
| 11406 | CreateMockRead(*host2_resp_body, 3), |
| 11407 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11408 | }; |
| 11409 | |
| 11410 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 11411 | new OrderedSocketData( |
| 11412 | spdy2_reads, arraysize(spdy2_reads), |
| 11413 | spdy2_writes, arraysize(spdy2_writes))); |
| 11414 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 11415 | |
| 11416 | MockWrite http_write[] = { |
| 11417 | MockWrite("GET / HTTP/1.1\r\n" |
| 11418 | "Host: www.a.com\r\n" |
| 11419 | "Connection: keep-alive\r\n\r\n"), |
| 11420 | }; |
| 11421 | |
| 11422 | MockRead http_read[] = { |
| 11423 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11424 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11425 | MockRead("Content-Length: 6\r\n\r\n"), |
| 11426 | MockRead("hello!"), |
| 11427 | }; |
| 11428 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 11429 | http_write, arraysize(http_write)); |
| 11430 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11431 | |
| 11432 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11433 | SpdySessionKey spdy_session_key_a( |
| 11434 | host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11435 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11436 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11437 | |
| 11438 | TestCompletionCallback callback; |
| 11439 | HttpRequestInfo request1; |
| 11440 | request1.method = "GET"; |
| 11441 | request1.url = GURL("https://www.a.com/"); |
| 11442 | request1.load_flags = 0; |
| 11443 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11445 | |
| 11446 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 11447 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11448 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11449 | |
| 11450 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11451 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11452 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11453 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11454 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11455 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11456 | |
| 11457 | std::string response_data; |
| 11458 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11459 | EXPECT_EQ("hello!", response_data); |
| 11460 | trans.reset(); |
| 11461 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11462 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11463 | |
| 11464 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11465 | SpdySessionKey spdy_session_key_b( |
| 11466 | host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11467 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11468 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11469 | HttpRequestInfo request2; |
| 11470 | request2.method = "GET"; |
| 11471 | request2.url = GURL("https://www.b.com/"); |
| 11472 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11473 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11474 | |
| 11475 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 11476 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11477 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11478 | |
| 11479 | response = trans->GetResponseInfo(); |
| 11480 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11481 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11482 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11483 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11484 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11485 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11486 | EXPECT_EQ("hello!", response_data); |
| 11487 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11488 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11489 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11490 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11491 | |
| 11492 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11493 | SpdySessionKey spdy_session_key_a1( |
| 11494 | host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11495 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11496 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11497 | HttpRequestInfo request3; |
| 11498 | request3.method = "GET"; |
| 11499 | request3.url = GURL("http://www.a.com/"); |
| 11500 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11501 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11502 | |
| 11503 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 11504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11505 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11506 | |
| 11507 | response = trans->GetResponseInfo(); |
| 11508 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11509 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11510 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11511 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11512 | EXPECT_FALSE(response->was_npn_negotiated); |
| 11513 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11514 | EXPECT_EQ("hello!", response_data); |
| 11515 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11516 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11517 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11518 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11519 | } |
| 11520 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11521 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 11522 | HttpRequestInfo request; |
| 11523 | request.method = "GET"; |
| 11524 | request.url = GURL("http://www.google.com/"); |
| 11525 | request.load_flags = 0; |
| 11526 | |
| 11527 | scoped_ptr<HttpTransaction> trans( |
| 11528 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11529 | CreateSession(&session_deps_))); |
| 11530 | |
| 11531 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 11532 | StaticSocketDataProvider data; |
| 11533 | data.set_connect_data(mock_connect); |
| 11534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11535 | |
| 11536 | TestCompletionCallback callback; |
| 11537 | |
| 11538 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11539 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11540 | |
| 11541 | rv = callback.WaitForResult(); |
| 11542 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11543 | |
| 11544 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11545 | |
| 11546 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11547 | HttpRequestHeaders request_headers; |
| 11548 | trans->GetFullRequestHeaders(&request_headers); |
| 11549 | } |
| 11550 | |
| 11551 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 11552 | HttpRequestInfo request; |
| 11553 | request.method = "GET"; |
| 11554 | request.url = GURL("http://www.google.com/"); |
| 11555 | request.load_flags = 0; |
| 11556 | |
| 11557 | scoped_ptr<HttpTransaction> trans( |
| 11558 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11559 | CreateSession(&session_deps_))); |
| 11560 | |
| 11561 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11562 | StaticSocketDataProvider data; |
| 11563 | data.set_connect_data(mock_connect); |
| 11564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11565 | |
| 11566 | TestCompletionCallback callback; |
| 11567 | |
| 11568 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11569 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11570 | |
| 11571 | rv = callback.WaitForResult(); |
| 11572 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11573 | |
| 11574 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11575 | |
| 11576 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11577 | HttpRequestHeaders request_headers; |
| 11578 | trans->GetFullRequestHeaders(&request_headers); |
| 11579 | } |
| 11580 | |
| 11581 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 11582 | HttpRequestInfo request; |
| 11583 | request.method = "GET"; |
| 11584 | request.url = GURL("http://www.google.com/"); |
| 11585 | request.load_flags = 0; |
| 11586 | |
| 11587 | scoped_ptr<HttpTransaction> trans( |
| 11588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11589 | CreateSession(&session_deps_))); |
| 11590 | |
| 11591 | MockWrite data_writes[] = { |
| 11592 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 11593 | }; |
| 11594 | MockRead data_reads[] = { |
| 11595 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 11596 | }; |
| 11597 | |
| 11598 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11599 | data_writes, arraysize(data_writes)); |
| 11600 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11601 | |
| 11602 | TestCompletionCallback callback; |
| 11603 | |
| 11604 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11605 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11606 | |
| 11607 | rv = callback.WaitForResult(); |
| 11608 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11609 | |
| 11610 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11611 | |
| 11612 | HttpRequestHeaders request_headers; |
| 11613 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11614 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11615 | } |
| 11616 | |
| 11617 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 11618 | HttpRequestInfo request; |
| 11619 | request.method = "GET"; |
| 11620 | request.url = GURL("http://www.google.com/"); |
| 11621 | request.load_flags = 0; |
| 11622 | |
| 11623 | scoped_ptr<HttpTransaction> trans( |
| 11624 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11625 | CreateSession(&session_deps_))); |
| 11626 | |
| 11627 | MockWrite data_writes[] = { |
| 11628 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 11629 | }; |
| 11630 | MockRead data_reads[] = { |
| 11631 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 11632 | }; |
| 11633 | |
| 11634 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11635 | data_writes, arraysize(data_writes)); |
| 11636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11637 | |
| 11638 | TestCompletionCallback callback; |
| 11639 | |
| 11640 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11642 | |
| 11643 | rv = callback.WaitForResult(); |
| 11644 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11645 | |
| 11646 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11647 | |
| 11648 | HttpRequestHeaders request_headers; |
| 11649 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11650 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11651 | } |
| 11652 | |
| 11653 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 11654 | HttpRequestInfo request; |
| 11655 | request.method = "GET"; |
| 11656 | request.url = GURL("http://www.google.com/"); |
| 11657 | request.load_flags = 0; |
| 11658 | |
| 11659 | scoped_ptr<HttpTransaction> trans( |
| 11660 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11661 | CreateSession(&session_deps_))); |
| 11662 | |
| 11663 | MockWrite data_writes[] = { |
| 11664 | MockWrite("GET / HTTP/1.1\r\n" |
| 11665 | "Host: www.google.com\r\n" |
| 11666 | "Connection: keep-alive\r\n\r\n"), |
| 11667 | }; |
| 11668 | MockRead data_reads[] = { |
| 11669 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 11670 | }; |
| 11671 | |
| 11672 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11673 | data_writes, arraysize(data_writes)); |
| 11674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11675 | |
| 11676 | TestCompletionCallback callback; |
| 11677 | |
| 11678 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11680 | |
| 11681 | rv = callback.WaitForResult(); |
| 11682 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11683 | |
| 11684 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11685 | |
| 11686 | HttpRequestHeaders request_headers; |
| 11687 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11688 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11689 | } |
| 11690 | |
| 11691 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 11692 | HttpRequestInfo request; |
| 11693 | request.method = "GET"; |
| 11694 | request.url = GURL("http://www.google.com/"); |
| 11695 | request.load_flags = 0; |
| 11696 | |
| 11697 | scoped_ptr<HttpTransaction> trans( |
| 11698 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11699 | CreateSession(&session_deps_))); |
| 11700 | |
| 11701 | MockWrite data_writes[] = { |
| 11702 | MockWrite("GET / HTTP/1.1\r\n" |
| 11703 | "Host: www.google.com\r\n" |
| 11704 | "Connection: keep-alive\r\n\r\n"), |
| 11705 | }; |
| 11706 | MockRead data_reads[] = { |
| 11707 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 11708 | }; |
| 11709 | |
| 11710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11711 | data_writes, arraysize(data_writes)); |
| 11712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11713 | |
| 11714 | TestCompletionCallback callback; |
| 11715 | |
| 11716 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11718 | |
| 11719 | rv = callback.WaitForResult(); |
| 11720 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 11721 | |
| 11722 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11723 | |
| 11724 | HttpRequestHeaders request_headers; |
| 11725 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11726 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 11727 | } |
| 11728 | |
| 11729 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 11730 | HttpRequestInfo request; |
| 11731 | request.method = "GET"; |
| 11732 | request.url = GURL("http://www.google.com/"); |
| 11733 | request.load_flags = 0; |
| 11734 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 11735 | |
| 11736 | scoped_ptr<HttpTransaction> trans( |
| 11737 | new HttpNetworkTransaction(DEFAULT_PRIORITY, |
| 11738 | CreateSession(&session_deps_))); |
| 11739 | |
| 11740 | MockWrite data_writes[] = { |
| 11741 | MockWrite("GET / HTTP/1.1\r\n" |
| 11742 | "Host: www.google.com\r\n" |
| 11743 | "Connection: keep-alive\r\n" |
| 11744 | "X-Foo: bar\r\n\r\n"), |
| 11745 | }; |
| 11746 | MockRead data_reads[] = { |
| 11747 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11748 | "Content-Length: 5\r\n\r\n" |
| 11749 | "hello"), |
| 11750 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 11751 | }; |
| 11752 | |
| 11753 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11754 | data_writes, arraysize(data_writes)); |
| 11755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11756 | |
| 11757 | TestCompletionCallback callback; |
| 11758 | |
| 11759 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11761 | |
| 11762 | rv = callback.WaitForResult(); |
| 11763 | EXPECT_EQ(OK, rv); |
| 11764 | |
| 11765 | HttpRequestHeaders request_headers; |
| 11766 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 11767 | std::string foo; |
| 11768 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 11769 | EXPECT_EQ("bar", foo); |
| 11770 | } |
| 11771 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11772 | namespace { |
| 11773 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 11774 | // Fake HttpStreamBase that simply records calls to SetPriority(). |
| 11775 | class FakeStream : public HttpStreamBase, |
| 11776 | public base::SupportsWeakPtr<FakeStream> { |
| 11777 | public: |
| 11778 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
| 11779 | virtual ~FakeStream() {} |
| 11780 | |
| 11781 | RequestPriority priority() const { return priority_; } |
| 11782 | |
| 11783 | virtual int InitializeStream(const HttpRequestInfo* request_info, |
| 11784 | RequestPriority priority, |
| 11785 | const BoundNetLog& net_log, |
| 11786 | const CompletionCallback& callback) OVERRIDE { |
| 11787 | return ERR_IO_PENDING; |
| 11788 | } |
| 11789 | |
| 11790 | virtual int SendRequest(const HttpRequestHeaders& request_headers, |
| 11791 | HttpResponseInfo* response, |
| 11792 | const CompletionCallback& callback) OVERRIDE { |
| 11793 | ADD_FAILURE(); |
| 11794 | return ERR_UNEXPECTED; |
| 11795 | } |
| 11796 | |
| 11797 | virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE { |
| 11798 | ADD_FAILURE(); |
| 11799 | return ERR_UNEXPECTED; |
| 11800 | } |
| 11801 | |
| 11802 | virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE { |
| 11803 | ADD_FAILURE(); |
| 11804 | return NULL; |
| 11805 | } |
| 11806 | |
| 11807 | virtual int ReadResponseBody(IOBuffer* buf, int buf_len, |
| 11808 | const CompletionCallback& callback) OVERRIDE { |
| 11809 | ADD_FAILURE(); |
| 11810 | return ERR_UNEXPECTED; |
| 11811 | } |
| 11812 | |
| 11813 | virtual void Close(bool not_reusable) OVERRIDE {} |
| 11814 | |
| 11815 | virtual bool IsResponseBodyComplete() const OVERRIDE { |
| 11816 | ADD_FAILURE(); |
| 11817 | return false; |
| 11818 | } |
| 11819 | |
| 11820 | virtual bool CanFindEndOfResponse() const OVERRIDE { |
| 11821 | return false; |
| 11822 | } |
| 11823 | |
| 11824 | virtual bool IsConnectionReused() const OVERRIDE { |
| 11825 | ADD_FAILURE(); |
| 11826 | return false; |
| 11827 | } |
| 11828 | |
| 11829 | virtual void SetConnectionReused() OVERRIDE { |
| 11830 | ADD_FAILURE(); |
| 11831 | } |
| 11832 | |
| 11833 | virtual bool IsConnectionReusable() const OVERRIDE { |
| 11834 | ADD_FAILURE(); |
| 11835 | return false; |
| 11836 | } |
| 11837 | |
| 11838 | virtual bool GetLoadTimingInfo( |
| 11839 | LoadTimingInfo* load_timing_info) const OVERRIDE { |
| 11840 | ADD_FAILURE(); |
| 11841 | return false; |
| 11842 | } |
| 11843 | |
| 11844 | virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { |
| 11845 | ADD_FAILURE(); |
| 11846 | } |
| 11847 | |
| 11848 | virtual void GetSSLCertRequestInfo( |
| 11849 | SSLCertRequestInfo* cert_request_info) OVERRIDE { |
| 11850 | ADD_FAILURE(); |
| 11851 | } |
| 11852 | |
| 11853 | virtual bool IsSpdyHttpStream() const OVERRIDE { |
| 11854 | ADD_FAILURE(); |
| 11855 | return false; |
| 11856 | } |
| 11857 | |
| 11858 | virtual void Drain(HttpNetworkSession* session) OVERRIDE { |
| 11859 | ADD_FAILURE(); |
| 11860 | } |
| 11861 | |
| 11862 | virtual void SetPriority(RequestPriority priority) OVERRIDE { |
| 11863 | priority_ = priority; |
| 11864 | } |
| 11865 | |
| 11866 | private: |
| 11867 | RequestPriority priority_; |
| 11868 | |
| 11869 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 11870 | }; |
| 11871 | |
| 11872 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 11873 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11874 | class FakeStreamRequest : public HttpStreamRequest, |
| 11875 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 11876 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 11877 | FakeStreamRequest(RequestPriority priority, |
| 11878 | HttpStreamRequest::Delegate* delegate) |
| 11879 | : priority_(priority), |
| 11880 | delegate_(delegate) {} |
| 11881 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11882 | virtual ~FakeStreamRequest() {} |
| 11883 | |
| 11884 | RequestPriority priority() const { return priority_; } |
| 11885 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 11886 | // Create a new FakeStream and pass it to the request's |
| 11887 | // delegate. Returns a weak pointer to the FakeStream. |
| 11888 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 11889 | FakeStream* fake_stream = new FakeStream(priority_); |
| 11890 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 11891 | // immediately delete |fake_stream|. |
| 11892 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 11893 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 11894 | return weak_stream; |
| 11895 | } |
| 11896 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11897 | virtual int RestartTunnelWithProxyAuth( |
| 11898 | const AuthCredentials& credentials) OVERRIDE { |
| 11899 | ADD_FAILURE(); |
| 11900 | return ERR_UNEXPECTED; |
| 11901 | } |
| 11902 | |
| 11903 | virtual LoadState GetLoadState() const OVERRIDE { |
| 11904 | ADD_FAILURE(); |
| 11905 | return LoadState(); |
| 11906 | } |
| 11907 | |
| 11908 | virtual void SetPriority(RequestPriority priority) OVERRIDE { |
| 11909 | priority_ = priority; |
| 11910 | } |
| 11911 | |
| 11912 | virtual bool was_npn_negotiated() const OVERRIDE { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11913 | return false; |
| 11914 | } |
| 11915 | |
| 11916 | virtual NextProto protocol_negotiated() const OVERRIDE { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11917 | return kProtoUnknown; |
| 11918 | } |
| 11919 | |
| 11920 | virtual bool using_spdy() const OVERRIDE { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11921 | return false; |
| 11922 | } |
| 11923 | |
| 11924 | private: |
| 11925 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 11926 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11927 | |
| 11928 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 11929 | }; |
| 11930 | |
| 11931 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 11932 | class FakeStreamFactory : public HttpStreamFactory { |
| 11933 | public: |
| 11934 | FakeStreamFactory() {} |
| 11935 | virtual ~FakeStreamFactory() {} |
| 11936 | |
| 11937 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 11938 | // RequestStream() (which may be NULL if it was destroyed already). |
| 11939 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 11940 | return last_stream_request_; |
| 11941 | } |
| 11942 | |
| 11943 | virtual HttpStreamRequest* RequestStream( |
| 11944 | const HttpRequestInfo& info, |
| 11945 | RequestPriority priority, |
| 11946 | const SSLConfig& server_ssl_config, |
| 11947 | const SSLConfig& proxy_ssl_config, |
| 11948 | HttpStreamRequest::Delegate* delegate, |
| 11949 | const BoundNetLog& net_log) OVERRIDE { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 11950 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 11951 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 11952 | return fake_request; |
| 11953 | } |
| 11954 | |
| 11955 | virtual HttpStreamRequest* RequestWebSocketStream( |
| 11956 | const HttpRequestInfo& info, |
| 11957 | RequestPriority priority, |
| 11958 | const SSLConfig& server_ssl_config, |
| 11959 | const SSLConfig& proxy_ssl_config, |
| 11960 | HttpStreamRequest::Delegate* delegate, |
| 11961 | WebSocketStreamBase::Factory* factory, |
| 11962 | const BoundNetLog& net_log) OVERRIDE { |
| 11963 | ADD_FAILURE(); |
| 11964 | return NULL; |
| 11965 | } |
| 11966 | |
| 11967 | virtual void PreconnectStreams(int num_streams, |
| 11968 | const HttpRequestInfo& info, |
| 11969 | RequestPriority priority, |
| 11970 | const SSLConfig& server_ssl_config, |
| 11971 | const SSLConfig& proxy_ssl_config) OVERRIDE { |
| 11972 | ADD_FAILURE(); |
| 11973 | } |
| 11974 | |
| 11975 | virtual base::Value* PipelineInfoToValue() const OVERRIDE { |
| 11976 | ADD_FAILURE(); |
| 11977 | return NULL; |
| 11978 | } |
| 11979 | |
| 11980 | virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE { |
| 11981 | ADD_FAILURE(); |
| 11982 | return NULL; |
| 11983 | } |
| 11984 | |
| 11985 | private: |
| 11986 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 11987 | |
| 11988 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 11989 | }; |
| 11990 | |
| 11991 | } // namespace |
| 11992 | |
| 11993 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 11994 | // stream request on start. |
| 11995 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 11996 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11997 | HttpNetworkSessionPeer peer(session); |
| 11998 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 11999 | peer.SetHttpStreamFactory(fake_factory); |
| 12000 | |
| 12001 | HttpNetworkTransaction trans(LOW, session); |
| 12002 | |
| 12003 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12004 | |
| 12005 | HttpRequestInfo request; |
| 12006 | TestCompletionCallback callback; |
| 12007 | EXPECT_EQ(ERR_IO_PENDING, |
| 12008 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12009 | |
| 12010 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12011 | fake_factory->last_stream_request(); |
| 12012 | ASSERT_TRUE(fake_request != NULL); |
| 12013 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12014 | } |
| 12015 | |
| 12016 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12017 | // updates to its stream request. |
| 12018 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12019 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12020 | HttpNetworkSessionPeer peer(session); |
| 12021 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12022 | peer.SetHttpStreamFactory(fake_factory); |
| 12023 | |
| 12024 | HttpNetworkTransaction trans(LOW, session); |
| 12025 | |
| 12026 | HttpRequestInfo request; |
| 12027 | TestCompletionCallback callback; |
| 12028 | EXPECT_EQ(ERR_IO_PENDING, |
| 12029 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12030 | |
| 12031 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12032 | fake_factory->last_stream_request(); |
| 12033 | ASSERT_TRUE(fake_request != NULL); |
| 12034 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12035 | |
| 12036 | trans.SetPriority(LOWEST); |
| 12037 | ASSERT_TRUE(fake_request != NULL); |
| 12038 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12039 | } |
| 12040 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12041 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12042 | // updates to its stream. |
| 12043 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12044 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12045 | HttpNetworkSessionPeer peer(session); |
| 12046 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12047 | peer.SetHttpStreamFactory(fake_factory); |
| 12048 | |
| 12049 | HttpNetworkTransaction trans(LOW, session); |
| 12050 | |
| 12051 | HttpRequestInfo request; |
| 12052 | TestCompletionCallback callback; |
| 12053 | EXPECT_EQ(ERR_IO_PENDING, |
| 12054 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12055 | |
| 12056 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12057 | fake_factory->last_stream_request(); |
| 12058 | ASSERT_TRUE(fake_request != NULL); |
| 12059 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12060 | ASSERT_TRUE(fake_stream != NULL); |
| 12061 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12062 | |
| 12063 | trans.SetPriority(LOWEST); |
| 12064 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12065 | } |
| 12066 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12067 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12068 | // if the transport socket pool is stalled on the global socket limit. |
| 12069 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12070 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12071 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12072 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12073 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12074 | |
| 12075 | // Set up SSL request. |
| 12076 | |
| 12077 | HttpRequestInfo ssl_request; |
| 12078 | ssl_request.method = "GET"; |
| 12079 | ssl_request.url = GURL("https://www.google.com/"); |
| 12080 | |
| 12081 | MockWrite ssl_writes[] = { |
| 12082 | MockWrite("GET / HTTP/1.1\r\n" |
| 12083 | "Host: www.google.com\r\n" |
| 12084 | "Connection: keep-alive\r\n\r\n"), |
| 12085 | }; |
| 12086 | MockRead ssl_reads[] = { |
| 12087 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12088 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12089 | MockRead("hello world"), |
| 12090 | MockRead(SYNCHRONOUS, OK), |
| 12091 | }; |
| 12092 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12093 | ssl_writes, arraysize(ssl_writes)); |
| 12094 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12095 | |
| 12096 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12098 | |
| 12099 | // Set up HTTP request. |
| 12100 | |
| 12101 | HttpRequestInfo http_request; |
| 12102 | http_request.method = "GET"; |
| 12103 | http_request.url = GURL("http://www.google.com/"); |
| 12104 | |
| 12105 | MockWrite http_writes[] = { |
| 12106 | MockWrite("GET / HTTP/1.1\r\n" |
| 12107 | "Host: www.google.com\r\n" |
| 12108 | "Connection: keep-alive\r\n\r\n"), |
| 12109 | }; |
| 12110 | MockRead http_reads[] = { |
| 12111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12112 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12113 | MockRead("falafel"), |
| 12114 | MockRead(SYNCHRONOUS, OK), |
| 12115 | }; |
| 12116 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12117 | http_writes, arraysize(http_writes)); |
| 12118 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12119 | |
| 12120 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12121 | |
| 12122 | // Start the SSL request. |
| 12123 | TestCompletionCallback ssl_callback; |
| 12124 | scoped_ptr<HttpTransaction> ssl_trans( |
| 12125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12126 | ASSERT_EQ(ERR_IO_PENDING, |
| 12127 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 12128 | BoundNetLog())); |
| 12129 | |
| 12130 | // Start the HTTP request. Pool should stall. |
| 12131 | TestCompletionCallback http_callback; |
| 12132 | scoped_ptr<HttpTransaction> http_trans( |
| 12133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12134 | ASSERT_EQ(ERR_IO_PENDING, |
| 12135 | http_trans->Start(&http_request, http_callback.callback(), |
| 12136 | BoundNetLog())); |
| 12137 | EXPECT_TRUE(IsTransportSocketPoolStalled(session)); |
| 12138 | |
| 12139 | // Wait for response from SSL request. |
| 12140 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 12141 | std::string response_data; |
| 12142 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 12143 | EXPECT_EQ("hello world", response_data); |
| 12144 | |
| 12145 | // The SSL socket should automatically be closed, so the HTTP request can |
| 12146 | // start. |
| 12147 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session)); |
| 12148 | ASSERT_FALSE(IsTransportSocketPoolStalled(session)); |
| 12149 | |
| 12150 | // The HTTP request can now complete. |
| 12151 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12152 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12153 | EXPECT_EQ("falafel", response_data); |
| 12154 | |
| 12155 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
| 12156 | } |
| 12157 | |
| 12158 | // Tests that when a SSL connection is established but there's no corresponding |
| 12159 | // request that needs it, the new socket is closed if the transport socket pool |
| 12160 | // is stalled on the global socket limit. |
| 12161 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 12162 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12163 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12164 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12165 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12166 | |
| 12167 | // Set up an ssl request. |
| 12168 | |
| 12169 | HttpRequestInfo ssl_request; |
| 12170 | ssl_request.method = "GET"; |
| 12171 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 12172 | |
| 12173 | // No data will be sent on the SSL socket. |
| 12174 | StaticSocketDataProvider ssl_data; |
| 12175 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12176 | |
| 12177 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12179 | |
| 12180 | // Set up HTTP request. |
| 12181 | |
| 12182 | HttpRequestInfo http_request; |
| 12183 | http_request.method = "GET"; |
| 12184 | http_request.url = GURL("http://www.google.com/"); |
| 12185 | |
| 12186 | MockWrite http_writes[] = { |
| 12187 | MockWrite("GET / HTTP/1.1\r\n" |
| 12188 | "Host: www.google.com\r\n" |
| 12189 | "Connection: keep-alive\r\n\r\n"), |
| 12190 | }; |
| 12191 | MockRead http_reads[] = { |
| 12192 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12193 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12194 | MockRead("falafel"), |
| 12195 | MockRead(SYNCHRONOUS, OK), |
| 12196 | }; |
| 12197 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12198 | http_writes, arraysize(http_writes)); |
| 12199 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12200 | |
| 12201 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12202 | |
| 12203 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 12204 | // cancelled when a normal transaction is cancelled. |
| 12205 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 12206 | net::SSLConfig ssl_config; |
| 12207 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 12208 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 12209 | ssl_config, ssl_config); |
| 12210 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session)); |
| 12211 | |
| 12212 | // Start the HTTP request. Pool should stall. |
| 12213 | TestCompletionCallback http_callback; |
| 12214 | scoped_ptr<HttpTransaction> http_trans( |
| 12215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12216 | ASSERT_EQ(ERR_IO_PENDING, |
| 12217 | http_trans->Start(&http_request, http_callback.callback(), |
| 12218 | BoundNetLog())); |
| 12219 | EXPECT_TRUE(IsTransportSocketPoolStalled(session)); |
| 12220 | |
| 12221 | // The SSL connection will automatically be closed once the connection is |
| 12222 | // established, to let the HTTP request start. |
| 12223 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12224 | std::string response_data; |
| 12225 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12226 | EXPECT_EQ("falafel", response_data); |
| 12227 | |
| 12228 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
| 12229 | } |
| 12230 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 12231 | } // namespace net |