[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 23 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 25 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 26 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 27 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 28 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 29 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 30 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 31 | #include "net/base/load_timing_info.h" |
| 32 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 33 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 34 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 35 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 36 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 37 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 38 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 39 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 40 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 41 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 42 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 46 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 81 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 82 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 83 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 84 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 85 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 86 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 87 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 89 | using base::ASCIIToUTF16; |
| 90 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 91 | //----------------------------------------------------------------------------- |
| 92 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 93 | namespace net { |
| 94 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 95 | namespace { |
| 96 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 97 | enum TestCase { |
| 98 | // Test using the SPDY/3.1 protocol. |
| 99 | kTestCaseSPDY31, |
| 100 | |
| 101 | // Test using the HTTP/2 protocol, without specifying a stream |
| 102 | // dependency based on the RequestPriority. |
| 103 | kTestCaseHTTP2NoPriorityDependencies, |
| 104 | |
| 105 | // Test using the HTTP/2 protocol, specifying a stream |
| 106 | // dependency based on the RequestPriority. |
| 107 | kTestCaseHTTP2PriorityDependencies |
| 108 | }; |
| 109 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 110 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 111 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 112 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 113 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 114 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 115 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 116 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 117 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 118 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 119 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 120 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 121 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 122 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 123 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 124 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 125 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 126 | } |
| 127 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 128 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 129 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 130 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 131 | } |
| 132 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 133 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 134 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 135 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 138 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 139 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 140 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 141 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 142 | if (!params) |
| 143 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 144 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 145 | if (!params->GetList("headers", &header_list)) |
| 146 | return false; |
| 147 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 148 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 149 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 153 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 154 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 155 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 158 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 160 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 161 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 162 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 163 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 164 | |
| 165 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 166 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 167 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 168 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 169 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 170 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 173 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 174 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 175 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 176 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 178 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | |
| 180 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 181 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 182 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 184 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 186 | load_timing_info.send_start); |
| 187 | |
| 188 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 190 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 192 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 197 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 198 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 200 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 201 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | |
| 204 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 205 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 206 | load_timing_info.proxy_resolve_end); |
| 207 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 208 | load_timing_info.send_start); |
| 209 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 211 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 213 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 214 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 218 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 219 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | int connect_timing_flags) { |
| 221 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 222 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | |
| 224 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 225 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 226 | load_timing_info.proxy_resolve_end); |
| 227 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 228 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 229 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 230 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 232 | load_timing_info.send_start); |
| 233 | |
| 234 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 236 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 238 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 239 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 240 | } |
| 241 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 242 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 243 | headers->SetHeader("Connection", "Upgrade"); |
| 244 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 245 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 246 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 247 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 248 | } |
| 249 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 250 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 251 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 252 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 255 | } // namespace |
| 256 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 257 | class HttpNetworkTransactionTest |
| 258 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 259 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 260 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 261 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 262 | // Important to restore the per-pool limit first, since the pool limit must |
| 263 | // always be greater than group limit, and the tests reduce both limits. |
| 264 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 265 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 266 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 267 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 268 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 271 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 272 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 273 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 274 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 275 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 276 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 277 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 278 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 279 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 280 | GetDependenciesFromPriority()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 281 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 282 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 283 | struct SimpleGetHelperResult { |
| 284 | int rv; |
| 285 | std::string status_line; |
| 286 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 287 | int64_t total_received_bytes; |
| 288 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 289 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 290 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 291 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 292 | }; |
| 293 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 294 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 295 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 296 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 297 | } |
| 298 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 299 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 300 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 301 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 302 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 303 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 304 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 305 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 306 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 307 | } |
| 308 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 309 | NextProto GetProtocol() const { |
| 310 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 311 | } |
| 312 | |
| 313 | bool GetDependenciesFromPriority() const { |
| 314 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 315 | } |
| 316 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 317 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 318 | return AlternateProtocolToString( |
| 319 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 320 | } |
| 321 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 322 | std::string GetAlternativeServiceHttpHeader() { |
| 323 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 324 | "=\"www.example.com:443\"\r\n"; |
| 325 | } |
| 326 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 327 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 328 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 329 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 332 | // Either |write_failure| specifies a write failure or |read_failure| |
| 333 | // specifies a read failure when using a reused socket. In either case, the |
| 334 | // failure should cause the network transaction to resend the request, and the |
| 335 | // other argument should be NULL. |
| 336 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 337 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 338 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 339 | // Either |write_failure| specifies a write failure or |read_failure| |
| 340 | // specifies a read failure when using a reused socket. In either case, the |
| 341 | // failure should cause the network transaction to resend the request, and the |
| 342 | // other argument should be NULL. |
| 343 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 344 | const MockRead* read_failure, |
| 345 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 346 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 347 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 348 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 349 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 350 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 351 | HttpRequestInfo request; |
| 352 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 353 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 354 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 355 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 356 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 357 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 358 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 359 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 361 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 362 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 363 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 364 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 366 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 367 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 368 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 369 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 371 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 372 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 373 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 374 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 375 | |
| 376 | // Even in the failure cases that use this function, connections are always |
| 377 | // successfully established before the error. |
| 378 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 379 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 380 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 381 | if (out.rv != OK) |
| 382 | return out; |
| 383 | |
| 384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 385 | // Can't use ASSERT_* inside helper functions like this, so |
| 386 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 387 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 388 | out.rv = ERR_UNEXPECTED; |
| 389 | return out; |
| 390 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 391 | out.status_line = response->headers->GetStatusLine(); |
| 392 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 393 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 394 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 395 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 396 | bool got_endpoint = |
| 397 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 398 | EXPECT_EQ(got_endpoint, |
| 399 | out.remote_endpoint_after_start.address().size() > 0); |
| 400 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 401 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 402 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 403 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 404 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 405 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 406 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 408 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 409 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 410 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 411 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 412 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 413 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 414 | std::string line; |
| 415 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 416 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 417 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 418 | HttpRequestHeaders request_headers; |
| 419 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 420 | std::string value; |
| 421 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 422 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 423 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 424 | EXPECT_EQ("keep-alive", value); |
| 425 | |
| 426 | std::string response_headers; |
| 427 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 428 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 429 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 430 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 431 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 432 | // The total number of sent bytes should not have changed. |
| 433 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 434 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 435 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 436 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 437 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 438 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 439 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 440 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 441 | MockWrite data_writes[] = { |
| 442 | MockWrite("GET / HTTP/1.1\r\n" |
| 443 | "Host: www.example.org\r\n" |
| 444 | "Connection: keep-alive\r\n\r\n"), |
| 445 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 446 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 447 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 448 | arraysize(data_writes)); |
| 449 | StaticSocketDataProvider* data[] = {&reads}; |
| 450 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 451 | |
| 452 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 453 | out.total_sent_bytes); |
| 454 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 457 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 458 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 461 | |
| 462 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 463 | |
| 464 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 465 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 466 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 467 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 468 | |
| 469 | // Original socket limits. Some tests set these. Safest to always restore |
| 470 | // them once each test has been run. |
| 471 | int old_max_group_sockets_; |
| 472 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 473 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 474 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 475 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 476 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 477 | testing::Values(kTestCaseSPDY31, |
| 478 | kTestCaseHTTP2NoPriorityDependencies, |
| 479 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 480 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 481 | namespace { |
| 482 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 483 | class BeforeNetworkStartHandler { |
| 484 | public: |
| 485 | explicit BeforeNetworkStartHandler(bool defer) |
| 486 | : defer_on_before_network_start_(defer), |
| 487 | observed_before_network_start_(false) {} |
| 488 | |
| 489 | void OnBeforeNetworkStart(bool* defer) { |
| 490 | *defer = defer_on_before_network_start_; |
| 491 | observed_before_network_start_ = true; |
| 492 | } |
| 493 | |
| 494 | bool observed_before_network_start() const { |
| 495 | return observed_before_network_start_; |
| 496 | } |
| 497 | |
| 498 | private: |
| 499 | const bool defer_on_before_network_start_; |
| 500 | bool observed_before_network_start_; |
| 501 | |
| 502 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 503 | }; |
| 504 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 505 | class BeforeProxyHeadersSentHandler { |
| 506 | public: |
| 507 | BeforeProxyHeadersSentHandler() |
| 508 | : observed_before_proxy_headers_sent_(false) {} |
| 509 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 510 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 511 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 512 | observed_before_proxy_headers_sent_ = true; |
| 513 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 514 | } |
| 515 | |
| 516 | bool observed_before_proxy_headers_sent() const { |
| 517 | return observed_before_proxy_headers_sent_; |
| 518 | } |
| 519 | |
| 520 | std::string observed_proxy_server_uri() const { |
| 521 | return observed_proxy_server_uri_; |
| 522 | } |
| 523 | |
| 524 | private: |
| 525 | bool observed_before_proxy_headers_sent_; |
| 526 | std::string observed_proxy_server_uri_; |
| 527 | |
| 528 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 529 | }; |
| 530 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 531 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 532 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 533 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 534 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 535 | const int sizeof_row = strlen(row); |
| 536 | const int num_rows = static_cast<int>( |
| 537 | ceil(static_cast<float>(size) / sizeof_row)); |
| 538 | const int sizeof_data = num_rows * sizeof_row; |
| 539 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 540 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 541 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 542 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 543 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 544 | } |
| 545 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 546 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 547 | // Alternative functions that eliminate randomness and dependency on the local |
| 548 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 549 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 550 | static const uint8 bytes[] = { |
| 551 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 552 | }; |
| 553 | static size_t current_byte = 0; |
| 554 | for (size_t i = 0; i < n; ++i) { |
| 555 | output[i] = bytes[current_byte++]; |
| 556 | current_byte %= arraysize(bytes); |
| 557 | } |
| 558 | } |
| 559 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 560 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 561 | static const uint8 bytes[] = { |
| 562 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 563 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 564 | }; |
| 565 | static size_t current_byte = 0; |
| 566 | for (size_t i = 0; i < n; ++i) { |
| 567 | output[i] = bytes[current_byte++]; |
| 568 | current_byte %= arraysize(bytes); |
| 569 | } |
| 570 | } |
| 571 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 572 | std::string MockGetHostName() { |
| 573 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 574 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 575 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 576 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 577 | template<typename ParentPool> |
| 578 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 579 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 580 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 581 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 582 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 583 | const std::string last_group_name_received() const { |
| 584 | return last_group_name_; |
| 585 | } |
| 586 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 587 | int RequestSocket(const std::string& group_name, |
| 588 | const void* socket_params, |
| 589 | RequestPriority priority, |
| 590 | ClientSocketHandle* handle, |
| 591 | const CompletionCallback& callback, |
| 592 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 593 | last_group_name_ = group_name; |
| 594 | return ERR_IO_PENDING; |
| 595 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 596 | void CancelRequest(const std::string& group_name, |
| 597 | ClientSocketHandle* handle) override {} |
| 598 | void ReleaseSocket(const std::string& group_name, |
| 599 | scoped_ptr<StreamSocket> socket, |
| 600 | int id) override {} |
| 601 | void CloseIdleSockets() override {} |
| 602 | int IdleSocketCount() const override { return 0; } |
| 603 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 604 | return 0; |
| 605 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 606 | LoadState GetLoadState(const std::string& group_name, |
| 607 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 608 | return LOAD_STATE_IDLE; |
| 609 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 610 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 611 | return base::TimeDelta(); |
| 612 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 613 | |
| 614 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 615 | std::string last_group_name_; |
| 616 | }; |
| 617 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 618 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 619 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 620 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 621 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 622 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 623 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 624 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 625 | CaptureGroupNameSSLSocketPool; |
| 626 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 627 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 628 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 629 | HostResolver* host_resolver, |
| 630 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 631 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 632 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 633 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 634 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 635 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 636 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 637 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 638 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 639 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 640 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 641 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 642 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 643 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 644 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 645 | : SSLClientSocketPool(0, |
| 646 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 647 | cert_verifier, |
| 648 | NULL, |
| 649 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 650 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 651 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 652 | std::string(), |
| 653 | NULL, |
| 654 | NULL, |
| 655 | NULL, |
| 656 | NULL, |
| 657 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 658 | NULL) { |
| 659 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 660 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 661 | //----------------------------------------------------------------------------- |
| 662 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 663 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 664 | // configured for common cases. |
| 665 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 666 | if (!auth_challenge) |
| 667 | return false; |
| 668 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 669 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 670 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 671 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 672 | return true; |
| 673 | } |
| 674 | |
| 675 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 676 | if (!auth_challenge) |
| 677 | return false; |
| 678 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 679 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 680 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 681 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 682 | return true; |
| 683 | } |
| 684 | |
| 685 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 686 | if (!auth_challenge) |
| 687 | return false; |
| 688 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 689 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 690 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 691 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 692 | return true; |
| 693 | } |
| 694 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 695 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 696 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 697 | if (!auth_challenge) |
| 698 | return false; |
| 699 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 700 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 701 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 702 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 703 | return true; |
| 704 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 705 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 706 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 707 | } // namespace |
| 708 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 709 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 711 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 712 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 713 | } |
| 714 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 715 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 716 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 717 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 718 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 719 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 720 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 721 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 722 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 723 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 725 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 726 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 727 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 728 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 729 | |
| 730 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 734 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 736 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 737 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 738 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 739 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 740 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 741 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 742 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 743 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 744 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 745 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 749 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 750 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 751 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 752 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 754 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 755 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 756 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 757 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 758 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 759 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 760 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 764 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 765 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 766 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 767 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 769 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 770 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 771 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 772 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 773 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 774 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 775 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | // 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] | 779 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 780 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 781 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 784 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 785 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 786 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 787 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 788 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 789 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 790 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 794 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 796 | MockRead("\n"), |
| 797 | MockRead("\n"), |
| 798 | MockRead("Q"), |
| 799 | MockRead("J"), |
| 800 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 803 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 804 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 805 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 807 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 808 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 809 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 813 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 815 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 816 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 818 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 819 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 820 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 822 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 823 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 824 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 825 | } |
| 826 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 827 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 828 | // persistent connection. The response should still terminate since a 204 |
| 829 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 830 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 831 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 832 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 833 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 834 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 835 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 836 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 837 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 838 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 839 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 840 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 841 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 842 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 843 | int64_t response_size = reads_size - strlen(junk); |
| 844 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 845 | } |
| 846 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 847 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 848 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 849 | std::string final_chunk = "0\r\n\r\n"; |
| 850 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 851 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 852 | MockRead data_reads[] = { |
| 853 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 854 | MockRead("5\r\nHello\r\n"), |
| 855 | MockRead("1\r\n"), |
| 856 | MockRead(" \r\n"), |
| 857 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 858 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 859 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 860 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 861 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 862 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 863 | EXPECT_EQ(OK, out.rv); |
| 864 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 865 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 866 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 867 | int64_t response_size = reads_size - extra_data.size(); |
| 868 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 869 | } |
| 870 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 871 | // Next tests deal with http://crbug.com/56344. |
| 872 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 873 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 874 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 875 | MockRead data_reads[] = { |
| 876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 877 | MockRead("Content-Length: 10\r\n"), |
| 878 | MockRead("Content-Length: 5\r\n\r\n"), |
| 879 | }; |
| 880 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 881 | arraysize(data_reads)); |
| 882 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 883 | } |
| 884 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 885 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 886 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 889 | MockRead("Content-Length: 5\r\n"), |
| 890 | MockRead("Content-Length: 5\r\n\r\n"), |
| 891 | MockRead("Hello"), |
| 892 | }; |
| 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 894 | arraysize(data_reads)); |
| 895 | EXPECT_EQ(OK, out.rv); |
| 896 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 897 | EXPECT_EQ("Hello", out.response_data); |
| 898 | } |
| 899 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 900 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 901 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 902 | // More than 2 dupes. |
| 903 | { |
| 904 | MockRead data_reads[] = { |
| 905 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 906 | MockRead("Content-Length: 5\r\n"), |
| 907 | MockRead("Content-Length: 5\r\n"), |
| 908 | MockRead("Content-Length: 5\r\n\r\n"), |
| 909 | MockRead("Hello"), |
| 910 | }; |
| 911 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 912 | arraysize(data_reads)); |
| 913 | EXPECT_EQ(OK, out.rv); |
| 914 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 915 | EXPECT_EQ("Hello", out.response_data); |
| 916 | } |
| 917 | // HTTP/1.0 |
| 918 | { |
| 919 | MockRead data_reads[] = { |
| 920 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 921 | MockRead("Content-Length: 5\r\n"), |
| 922 | MockRead("Content-Length: 5\r\n"), |
| 923 | MockRead("Content-Length: 5\r\n\r\n"), |
| 924 | MockRead("Hello"), |
| 925 | }; |
| 926 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 927 | arraysize(data_reads)); |
| 928 | EXPECT_EQ(OK, out.rv); |
| 929 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 930 | EXPECT_EQ("Hello", out.response_data); |
| 931 | } |
| 932 | // 2 dupes and one mismatched. |
| 933 | { |
| 934 | MockRead data_reads[] = { |
| 935 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 936 | MockRead("Content-Length: 10\r\n"), |
| 937 | MockRead("Content-Length: 10\r\n"), |
| 938 | MockRead("Content-Length: 5\r\n\r\n"), |
| 939 | }; |
| 940 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 941 | arraysize(data_reads)); |
| 942 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 943 | } |
| 944 | } |
| 945 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 946 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 947 | MultipleContentLengthHeadersTransferEncoding) { |
| 948 | MockRead data_reads[] = { |
| 949 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 950 | MockRead("Content-Length: 666\r\n"), |
| 951 | MockRead("Content-Length: 1337\r\n"), |
| 952 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 953 | MockRead("5\r\nHello\r\n"), |
| 954 | MockRead("1\r\n"), |
| 955 | MockRead(" \r\n"), |
| 956 | MockRead("5\r\nworld\r\n"), |
| 957 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 959 | }; |
| 960 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 961 | arraysize(data_reads)); |
| 962 | EXPECT_EQ(OK, out.rv); |
| 963 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 964 | EXPECT_EQ("Hello world", out.response_data); |
| 965 | } |
| 966 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 967 | // Next tests deal with http://crbug.com/98895. |
| 968 | |
| 969 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 970 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | MockRead data_reads[] = { |
| 972 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 973 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 974 | MockRead("Content-Length: 5\r\n\r\n"), |
| 975 | MockRead("Hello"), |
| 976 | }; |
| 977 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 978 | arraysize(data_reads)); |
| 979 | EXPECT_EQ(OK, out.rv); |
| 980 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 981 | EXPECT_EQ("Hello", out.response_data); |
| 982 | } |
| 983 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 984 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 985 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 986 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 987 | MockRead data_reads[] = { |
| 988 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 989 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 990 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 991 | MockRead("Content-Length: 5\r\n\r\n"), |
| 992 | MockRead("Hello"), |
| 993 | }; |
| 994 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 995 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 996 | EXPECT_EQ(OK, out.rv); |
| 997 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 998 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1002 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1003 | MockRead data_reads[] = { |
| 1004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1005 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1006 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1007 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1008 | MockRead("Hello"), |
| 1009 | }; |
| 1010 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1011 | arraysize(data_reads)); |
| 1012 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1013 | } |
| 1014 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1015 | // Checks that two identical Location headers result in no error. |
| 1016 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1017 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1018 | MockRead data_reads[] = { |
| 1019 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1020 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1021 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1022 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1023 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | HttpRequestInfo request; |
| 1027 | request.method = "GET"; |
| 1028 | request.url = GURL("http://redirect.com/"); |
| 1029 | request.load_flags = 0; |
| 1030 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1031 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1032 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1034 | |
| 1035 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1038 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1040 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1042 | |
| 1043 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1044 | |
| 1045 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1046 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1047 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1048 | std::string url; |
| 1049 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1050 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1051 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1052 | } |
| 1053 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1054 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1055 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1056 | MockRead data_reads[] = { |
| 1057 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1058 | MockRead("Location: http://good.com/\r\n"), |
| 1059 | MockRead("Location: http://evil.com/\r\n"), |
| 1060 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1062 | }; |
| 1063 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1064 | arraysize(data_reads)); |
| 1065 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1066 | } |
| 1067 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1069 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1070 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1071 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1072 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1073 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1074 | request.load_flags = 0; |
| 1075 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1076 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1077 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1079 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1080 | trans->SetBeforeProxyHeadersSentCallback( |
| 1081 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1082 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1083 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1085 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1086 | "Host: www.example.org\r\n" |
| 1087 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1088 | }; |
| 1089 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 1090 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1091 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1092 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 1093 | // No response body because the test stops reading here. |
| 1094 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1095 | }; |
| 1096 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1097 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1098 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1099 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1101 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1103 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1104 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1105 | |
| 1106 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1108 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1109 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1110 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1111 | |
| 1112 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1113 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1114 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1115 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1116 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1117 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1118 | |
| 1119 | std::string server_header; |
| 1120 | void* iter = NULL; |
| 1121 | bool has_server_header = response->headers->EnumerateHeader( |
| 1122 | &iter, "Server", &server_header); |
| 1123 | EXPECT_TRUE(has_server_header); |
| 1124 | EXPECT_EQ("Blah", server_header); |
| 1125 | |
| 1126 | // Reading should give EOF right away, since there is no message body |
| 1127 | // (despite non-zero content-length). |
| 1128 | std::string response_data; |
| 1129 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1130 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1131 | EXPECT_EQ("", response_data); |
| 1132 | } |
| 1133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1134 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1135 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1136 | |
| 1137 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1138 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1139 | MockRead("hello"), |
| 1140 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1141 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1142 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1144 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1147 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1148 | "hello", "world" |
| 1149 | }; |
| 1150 | |
| 1151 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1152 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1154 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1155 | request.load_flags = 0; |
| 1156 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1157 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1158 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1160 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1162 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1163 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | |
| 1165 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1169 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1171 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1172 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1173 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1174 | |
| 1175 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1176 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1178 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1182 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1183 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1184 | element_readers.push_back( |
| 1185 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 1186 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1187 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1188 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | request.method = "POST"; |
| 1190 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1191 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | request.load_flags = 0; |
| 1193 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1194 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1195 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1196 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1197 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1198 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1199 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1200 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1201 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1202 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1203 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1204 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1207 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1209 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1211 | |
| 1212 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1213 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1214 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1215 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1216 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1217 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1218 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1219 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1220 | |
| 1221 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1222 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1223 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1224 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1225 | } |
| 1226 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1227 | // This test is almost the same as Ignores100 above, but the response contains |
| 1228 | // 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] | 1229 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1230 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1231 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1232 | request.method = "GET"; |
| 1233 | request.url = GURL("http://www.foo.com/"); |
| 1234 | request.load_flags = 0; |
| 1235 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1236 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1237 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1239 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1240 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1241 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1242 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1243 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1244 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1245 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1246 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1247 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1249 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1251 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1253 | |
| 1254 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1255 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1256 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1258 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1259 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1260 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1261 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1262 | |
| 1263 | std::string response_data; |
| 1264 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1265 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1266 | EXPECT_EQ("hello world", response_data); |
| 1267 | } |
| 1268 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1269 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1270 | HttpRequestInfo request; |
| 1271 | request.method = "POST"; |
| 1272 | request.url = GURL("http://www.foo.com/"); |
| 1273 | request.load_flags = 0; |
| 1274 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1275 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1276 | scoped_ptr<HttpTransaction> trans( |
| 1277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1278 | |
| 1279 | MockRead data_reads[] = { |
| 1280 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1281 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1282 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1283 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1285 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1286 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1287 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1288 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1290 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1291 | rv = callback.WaitForResult(); |
| 1292 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1293 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1294 | std::string response_data; |
| 1295 | rv = ReadTransaction(trans.get(), &response_data); |
| 1296 | EXPECT_EQ(OK, rv); |
| 1297 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1298 | } |
| 1299 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1300 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1301 | HttpRequestInfo request; |
| 1302 | request.method = "POST"; |
| 1303 | request.url = GURL("http://www.foo.com/"); |
| 1304 | request.load_flags = 0; |
| 1305 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1306 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1307 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1308 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1309 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1310 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1311 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1312 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1313 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1316 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1318 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1320 | |
| 1321 | rv = callback.WaitForResult(); |
| 1322 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1323 | } |
| 1324 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1325 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1326 | const MockWrite* write_failure, |
| 1327 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1328 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | request.method = "GET"; |
| 1330 | request.url = GURL("http://www.foo.com/"); |
| 1331 | request.load_flags = 0; |
| 1332 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1333 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1334 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1335 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1336 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1337 | // Written data for successfully sending both requests. |
| 1338 | MockWrite data1_writes[] = { |
| 1339 | MockWrite("GET / HTTP/1.1\r\n" |
| 1340 | "Host: www.foo.com\r\n" |
| 1341 | "Connection: keep-alive\r\n\r\n"), |
| 1342 | MockWrite("GET / HTTP/1.1\r\n" |
| 1343 | "Host: www.foo.com\r\n" |
| 1344 | "Connection: keep-alive\r\n\r\n") |
| 1345 | }; |
| 1346 | |
| 1347 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1349 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1350 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1351 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1353 | |
| 1354 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1355 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1356 | data1_writes[1] = *write_failure; |
| 1357 | } else { |
| 1358 | ASSERT_TRUE(read_failure); |
| 1359 | data1_reads[2] = *read_failure; |
| 1360 | } |
| 1361 | |
| 1362 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1363 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1364 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
| 1366 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1367 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1368 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1369 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1371 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1373 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1374 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | "hello", "world" |
| 1376 | }; |
| 1377 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1378 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1379 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1380 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1382 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1385 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1387 | |
| 1388 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1390 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1391 | LoadTimingInfo load_timing_info; |
| 1392 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1393 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1394 | if (i == 0) { |
| 1395 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1396 | } else { |
| 1397 | // The second request should be using a new socket. |
| 1398 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1399 | } |
| 1400 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1401 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1402 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1404 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1405 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1406 | |
| 1407 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1408 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1409 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1410 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1411 | } |
| 1412 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1413 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1414 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1415 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1416 | const MockRead* read_failure, |
| 1417 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1418 | HttpRequestInfo request; |
| 1419 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1420 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | request.load_flags = 0; |
| 1422 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1423 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1424 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1425 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1426 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1427 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1428 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1429 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1430 | ssl1.SetNextProto(GetProtocol()); |
| 1431 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1432 | } |
| 1433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1435 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1436 | // SPDY versions of the request and response. |
| 1437 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1438 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1439 | scoped_ptr<SpdyFrame> spdy_response( |
| 1440 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1441 | scoped_ptr<SpdyFrame> spdy_data( |
| 1442 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1443 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1444 | // HTTP/1.1 versions of the request and response. |
| 1445 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1446 | "Host: www.foo.com\r\n" |
| 1447 | "Connection: keep-alive\r\n\r\n"; |
| 1448 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1449 | const char kHttpData[] = "hello"; |
| 1450 | |
| 1451 | std::vector<MockRead> data1_reads; |
| 1452 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1453 | if (write_failure) { |
| 1454 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1455 | data1_writes.push_back(*write_failure); |
| 1456 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1457 | } else { |
| 1458 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1459 | if (use_spdy) { |
| 1460 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1461 | } else { |
| 1462 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1463 | } |
| 1464 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1465 | } |
| 1466 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1467 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1468 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1469 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1470 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1471 | std::vector<MockRead> data2_reads; |
| 1472 | std::vector<MockWrite> data2_writes; |
| 1473 | |
| 1474 | if (use_spdy) { |
| 1475 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1476 | |
| 1477 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1478 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1479 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1480 | } else { |
| 1481 | data2_writes.push_back( |
| 1482 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1483 | |
| 1484 | data2_reads.push_back( |
| 1485 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1486 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1487 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1488 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1489 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1490 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1491 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1492 | |
| 1493 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1494 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1495 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1496 | session->GetAlpnProtos(&ssl_config.alpn_protos); |
| 1497 | session->GetNpnProtos(&ssl_config.npn_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1498 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1499 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1500 | // Wait for the preconnect to complete. |
| 1501 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1502 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1503 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | |
| 1505 | // Make the request. |
| 1506 | TestCompletionCallback callback; |
| 1507 | |
| 1508 | scoped_ptr<HttpTransaction> trans( |
| 1509 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1510 | |
| 1511 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1513 | |
| 1514 | rv = callback.WaitForResult(); |
| 1515 | EXPECT_EQ(OK, rv); |
| 1516 | |
| 1517 | LoadTimingInfo load_timing_info; |
| 1518 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1519 | TestLoadTimingNotReused( |
| 1520 | load_timing_info, |
| 1521 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1522 | |
| 1523 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1524 | ASSERT_TRUE(response != NULL); |
| 1525 | |
| 1526 | EXPECT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1527 | if (response->was_fetched_via_spdy) { |
| 1528 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1529 | } else { |
| 1530 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1531 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1532 | |
| 1533 | std::string response_data; |
| 1534 | rv = ReadTransaction(trans.get(), &response_data); |
| 1535 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1536 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1537 | } |
| 1538 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1539 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1540 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1541 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1542 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1543 | } |
| 1544 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1545 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1546 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1547 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1550 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1551 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1552 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1553 | } |
| 1554 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1555 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1556 | // if the socket was a reused keep alive socket. |
| 1557 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1558 | MockRead read_failure(SYNCHRONOUS, |
| 1559 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1560 | "Connection: Keep-Alive\r\n" |
| 1561 | "Content-Length: 6\r\n\r\n" |
| 1562 | "Pickle"); |
| 1563 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1564 | } |
| 1565 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1566 | TEST_P(HttpNetworkTransactionTest, |
| 1567 | PreconnectErrorNotConnectedOnWrite) { |
| 1568 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1569 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1573 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1574 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1578 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1579 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1580 | } |
| 1581 | |
| 1582 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1583 | MockRead read_failure(ASYNC, OK); // EOF |
| 1584 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1585 | } |
| 1586 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1587 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1588 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1589 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1590 | MockRead read_failure(SYNCHRONOUS, |
| 1591 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1592 | "Connection: Keep-Alive\r\n" |
| 1593 | "Content-Length: 6\r\n\r\n" |
| 1594 | "Pickle"); |
| 1595 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1596 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1597 | } |
| 1598 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1599 | TEST_P(HttpNetworkTransactionTest, |
| 1600 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1601 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1602 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1603 | } |
| 1604 | |
| 1605 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1606 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1607 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1608 | } |
| 1609 | |
| 1610 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1611 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1612 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1613 | } |
| 1614 | |
| 1615 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1616 | MockRead read_failure(ASYNC, OK); // EOF |
| 1617 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1618 | } |
| 1619 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1620 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1621 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1622 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1623 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1624 | request.load_flags = 0; |
| 1625 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1626 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1627 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1629 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1630 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1631 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1632 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1633 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1634 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1635 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1636 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1637 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1639 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1641 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1643 | |
| 1644 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1645 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1646 | |
| 1647 | IPEndPoint endpoint; |
| 1648 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1649 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | // What do various browsers do when the server closes a non-keepalive |
| 1653 | // connection without sending any response header or body? |
| 1654 | // |
| 1655 | // IE7: error page |
| 1656 | // Safari 3.1.2 (Windows): error page |
| 1657 | // Firefox 3.0.1: blank page |
| 1658 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1659 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1660 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1661 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1662 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1663 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1664 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1665 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1667 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1668 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1669 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1670 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1671 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1672 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1673 | // Test that network access can be deferred and resumed. |
| 1674 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1675 | HttpRequestInfo request; |
| 1676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1677 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1678 | request.load_flags = 0; |
| 1679 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1680 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1681 | scoped_ptr<HttpTransaction> trans( |
| 1682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1683 | |
| 1684 | // Defer on OnBeforeNetworkStart. |
| 1685 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1686 | trans->SetBeforeNetworkStartCallback( |
| 1687 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1688 | base::Unretained(&net_start_handler))); |
| 1689 | |
| 1690 | MockRead data_reads[] = { |
| 1691 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1692 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1693 | MockRead("hello"), |
| 1694 | MockRead(SYNCHRONOUS, 0), |
| 1695 | }; |
| 1696 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1698 | |
| 1699 | TestCompletionCallback callback; |
| 1700 | |
| 1701 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1703 | base::MessageLoop::current()->RunUntilIdle(); |
| 1704 | |
| 1705 | // Should have deferred for network start. |
| 1706 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1707 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1708 | |
| 1709 | trans->ResumeNetworkStart(); |
| 1710 | rv = callback.WaitForResult(); |
| 1711 | EXPECT_EQ(OK, rv); |
| 1712 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1713 | |
| 1714 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1715 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1716 | if (rv == ERR_IO_PENDING) |
| 1717 | rv = callback.WaitForResult(); |
| 1718 | EXPECT_EQ(5, rv); |
| 1719 | trans.reset(); |
| 1720 | } |
| 1721 | |
| 1722 | // Test that network use can be deferred and canceled. |
| 1723 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1724 | HttpRequestInfo request; |
| 1725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1726 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1727 | request.load_flags = 0; |
| 1728 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1729 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1730 | scoped_ptr<HttpTransaction> trans( |
| 1731 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1732 | |
| 1733 | // Defer on OnBeforeNetworkStart. |
| 1734 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1735 | trans->SetBeforeNetworkStartCallback( |
| 1736 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1737 | base::Unretained(&net_start_handler))); |
| 1738 | |
| 1739 | TestCompletionCallback callback; |
| 1740 | |
| 1741 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1743 | base::MessageLoop::current()->RunUntilIdle(); |
| 1744 | |
| 1745 | // Should have deferred for network start. |
| 1746 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1747 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1748 | } |
| 1749 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1750 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1751 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1752 | // destructor in such situations. |
| 1753 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1754 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1755 | HttpRequestInfo request; |
| 1756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1757 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1758 | request.load_flags = 0; |
| 1759 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1760 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | |
| 1764 | MockRead data_reads[] = { |
| 1765 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1766 | MockRead("Connection: keep-alive\r\n"), |
| 1767 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1768 | MockRead("hello"), |
| 1769 | MockRead(SYNCHRONOUS, 0), |
| 1770 | }; |
| 1771 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1773 | |
| 1774 | TestCompletionCallback callback; |
| 1775 | |
| 1776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1778 | |
| 1779 | rv = callback.WaitForResult(); |
| 1780 | EXPECT_EQ(OK, rv); |
| 1781 | |
| 1782 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1783 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1784 | if (rv == ERR_IO_PENDING) |
| 1785 | rv = callback.WaitForResult(); |
| 1786 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1787 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1788 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1789 | |
| 1790 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1791 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1792 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1793 | } |
| 1794 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1795 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1796 | HttpRequestInfo request; |
| 1797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1798 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1799 | request.load_flags = 0; |
| 1800 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1801 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1802 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1803 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | |
| 1805 | MockRead data_reads[] = { |
| 1806 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1807 | MockRead("Connection: keep-alive\r\n"), |
| 1808 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1809 | MockRead(SYNCHRONOUS, 0), |
| 1810 | }; |
| 1811 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1812 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1813 | |
| 1814 | TestCompletionCallback callback; |
| 1815 | |
| 1816 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1817 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1818 | |
| 1819 | rv = callback.WaitForResult(); |
| 1820 | EXPECT_EQ(OK, rv); |
| 1821 | |
| 1822 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1823 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1824 | if (rv == ERR_IO_PENDING) |
| 1825 | rv = callback.WaitForResult(); |
| 1826 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1827 | |
| 1828 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1829 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1830 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1831 | } |
| 1832 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1833 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1834 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1835 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1836 | HttpRequestInfo request; |
| 1837 | request.method = "GET"; |
| 1838 | request.url = GURL("http://www.foo.com/"); |
| 1839 | request.load_flags = 0; |
| 1840 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1841 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1842 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1843 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1844 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1845 | const char* request_data = |
| 1846 | "GET / HTTP/1.1\r\n" |
| 1847 | "Host: www.foo.com\r\n" |
| 1848 | "Connection: keep-alive\r\n\r\n"; |
| 1849 | MockWrite data_writes[] = { |
| 1850 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1851 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1852 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1853 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1854 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1855 | }; |
| 1856 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1857 | // Note that because all these reads happen in the same |
| 1858 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1859 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1860 | MockRead data_reads[] = { |
| 1861 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1862 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1863 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1864 | MockRead(ASYNC, 7, |
| 1865 | "HTTP/1.1 302 Found\r\n" |
| 1866 | "Content-Length: 0\r\n\r\n"), |
| 1867 | MockRead(ASYNC, 9, |
| 1868 | "HTTP/1.1 302 Found\r\n" |
| 1869 | "Content-Length: 5\r\n\r\n" |
| 1870 | "hello"), |
| 1871 | MockRead(ASYNC, 11, |
| 1872 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1873 | "Content-Length: 0\r\n\r\n"), |
| 1874 | MockRead(ASYNC, 13, |
| 1875 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1876 | "Content-Length: 5\r\n\r\n" |
| 1877 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1878 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1879 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1880 | // the set_busy_before_sync_reads(true) call, while the |
| 1881 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1882 | // reuseable. See http://crbug.com/544255. |
| 1883 | MockRead(ASYNC, 15, |
| 1884 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1885 | "Content-Length: 5\r\n\r\n"), |
| 1886 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1887 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1888 | MockRead(ASYNC, 18, |
| 1889 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1890 | "Content-Length: 5\r\n\r\n" |
| 1891 | "he"), |
| 1892 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1893 | |
| 1894 | // The body of the final request is actually read. |
| 1895 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1896 | MockRead(ASYNC, 22, "hello"), |
| 1897 | }; |
| 1898 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1899 | arraysize(data_writes)); |
| 1900 | data.set_busy_before_sync_reads(true); |
| 1901 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1902 | |
| 1903 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1904 | std::string response_lines[kNumUnreadBodies]; |
| 1905 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1906 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1907 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1908 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1910 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1913 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1914 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1915 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1916 | LoadTimingInfo load_timing_info; |
| 1917 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1918 | if (i == 0) { |
| 1919 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1920 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1921 | } else { |
| 1922 | TestLoadTimingReused(load_timing_info); |
| 1923 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1924 | } |
| 1925 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1926 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1927 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1928 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1929 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1930 | response_lines[i] = response->headers->GetStatusLine(); |
| 1931 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1932 | // Delete the transaction without reading the response bodies. Then spin |
| 1933 | // the message loop, so the response bodies are drained. |
| 1934 | trans.reset(); |
| 1935 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1936 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1937 | |
| 1938 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1939 | "HTTP/1.1 204 No Content", |
| 1940 | "HTTP/1.1 205 Reset Content", |
| 1941 | "HTTP/1.1 304 Not Modified", |
| 1942 | "HTTP/1.1 302 Found", |
| 1943 | "HTTP/1.1 302 Found", |
| 1944 | "HTTP/1.1 301 Moved Permanently", |
| 1945 | "HTTP/1.1 301 Moved Permanently", |
| 1946 | "HTTP/1.1 200 Hunky-Dory", |
| 1947 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1948 | }; |
| 1949 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1950 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1951 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1952 | |
| 1953 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1954 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1956 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1957 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1958 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1959 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1960 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1961 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1962 | ASSERT_TRUE(response); |
| 1963 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1964 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1965 | std::string response_data; |
| 1966 | rv = ReadTransaction(trans.get(), &response_data); |
| 1967 | EXPECT_EQ(OK, rv); |
| 1968 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1971 | // Test the request-challenge-retry sequence for basic auth. |
| 1972 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1973 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1974 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1975 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1976 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1977 | request.load_flags = 0; |
| 1978 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1979 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1980 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1981 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1982 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1984 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1985 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1986 | MockWrite( |
| 1987 | "GET / HTTP/1.1\r\n" |
| 1988 | "Host: www.example.org\r\n" |
| 1989 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1990 | }; |
| 1991 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1992 | MockRead data_reads1[] = { |
| 1993 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1994 | // Give a couple authenticate options (only the middle one is actually |
| 1995 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1996 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1997 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1998 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1999 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2000 | // Large content-length -- won't matter, as connection will be reset. |
| 2001 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2002 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2003 | }; |
| 2004 | |
| 2005 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2006 | // be issuing -- the final header line contains the credentials. |
| 2007 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2008 | MockWrite( |
| 2009 | "GET / HTTP/1.1\r\n" |
| 2010 | "Host: www.example.org\r\n" |
| 2011 | "Connection: keep-alive\r\n" |
| 2012 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2013 | }; |
| 2014 | |
| 2015 | // Lastly, the server responds with the actual content. |
| 2016 | MockRead data_reads2[] = { |
| 2017 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2019 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2020 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2021 | }; |
| 2022 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2023 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2024 | data_writes1, arraysize(data_writes1)); |
| 2025 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2026 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2027 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2028 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2030 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2032 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2034 | |
| 2035 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2036 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2037 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2038 | LoadTimingInfo load_timing_info1; |
| 2039 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2040 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2041 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2042 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2043 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2044 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2045 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2046 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2047 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2048 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2049 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2051 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2053 | rv = trans->RestartWithAuth( |
| 2054 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2055 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2056 | |
| 2057 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2058 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2059 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2060 | LoadTimingInfo load_timing_info2; |
| 2061 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2062 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2063 | // The load timing after restart should have a new socket ID, and times after |
| 2064 | // those of the first load timing. |
| 2065 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2066 | load_timing_info2.connect_timing.connect_start); |
| 2067 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2068 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2069 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2070 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2071 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2072 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2073 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2074 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2075 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2076 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2077 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2078 | } |
| 2079 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2080 | // Test the request-challenge-retry sequence for basic auth. |
| 2081 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2082 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2083 | HttpRequestInfo request; |
| 2084 | request.method = "GET"; |
| 2085 | request.url = GURL("http://www.example.org/"); |
| 2086 | request.load_flags = 0; |
| 2087 | |
| 2088 | TestNetLog log; |
| 2089 | MockHostResolver* resolver = new MockHostResolver(); |
| 2090 | session_deps_.net_log = &log; |
| 2091 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2092 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2093 | scoped_ptr<HttpTransaction> trans( |
| 2094 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2095 | |
| 2096 | resolver->rules()->ClearRules(); |
| 2097 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2098 | |
| 2099 | MockWrite data_writes1[] = { |
| 2100 | MockWrite("GET / HTTP/1.1\r\n" |
| 2101 | "Host: www.example.org\r\n" |
| 2102 | "Connection: keep-alive\r\n\r\n"), |
| 2103 | }; |
| 2104 | |
| 2105 | MockRead data_reads1[] = { |
| 2106 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2107 | // Give a couple authenticate options (only the middle one is actually |
| 2108 | // supported). |
| 2109 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2110 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2111 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2112 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2113 | // Large content-length -- won't matter, as connection will be reset. |
| 2114 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2115 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2116 | }; |
| 2117 | |
| 2118 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2119 | // be issuing -- the final header line contains the credentials. |
| 2120 | MockWrite data_writes2[] = { |
| 2121 | MockWrite("GET / HTTP/1.1\r\n" |
| 2122 | "Host: www.example.org\r\n" |
| 2123 | "Connection: keep-alive\r\n" |
| 2124 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2125 | }; |
| 2126 | |
| 2127 | // Lastly, the server responds with the actual content. |
| 2128 | MockRead data_reads2[] = { |
| 2129 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2130 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2131 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2132 | }; |
| 2133 | |
| 2134 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2135 | data_writes1, arraysize(data_writes1)); |
| 2136 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2137 | data_writes2, arraysize(data_writes2)); |
| 2138 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2139 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2140 | |
| 2141 | TestCompletionCallback callback1; |
| 2142 | |
| 2143 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2144 | BoundNetLog()))); |
| 2145 | |
| 2146 | LoadTimingInfo load_timing_info1; |
| 2147 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2148 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2149 | |
| 2150 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2151 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2152 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2153 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2154 | |
| 2155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2156 | ASSERT_TRUE(response); |
| 2157 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2158 | |
| 2159 | IPEndPoint endpoint; |
| 2160 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2161 | ASSERT_FALSE(endpoint.address().empty()); |
| 2162 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2163 | |
| 2164 | resolver->rules()->ClearRules(); |
| 2165 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2166 | |
| 2167 | TestCompletionCallback callback2; |
| 2168 | |
| 2169 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2170 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2171 | |
| 2172 | LoadTimingInfo load_timing_info2; |
| 2173 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2174 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2175 | // The load timing after restart should have a new socket ID, and times after |
| 2176 | // those of the first load timing. |
| 2177 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2178 | load_timing_info2.connect_timing.connect_start); |
| 2179 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2180 | |
| 2181 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2182 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2183 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2184 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2185 | |
| 2186 | response = trans->GetResponseInfo(); |
| 2187 | ASSERT_TRUE(response); |
| 2188 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2189 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2190 | |
| 2191 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2192 | ASSERT_FALSE(endpoint.address().empty()); |
| 2193 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2194 | } |
| 2195 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2196 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2197 | HttpRequestInfo request; |
| 2198 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2199 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2200 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2201 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2202 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2203 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2205 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2206 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2207 | MockWrite( |
| 2208 | "GET / HTTP/1.1\r\n" |
| 2209 | "Host: www.example.org\r\n" |
| 2210 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2211 | }; |
| 2212 | |
| 2213 | MockRead data_reads[] = { |
| 2214 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2215 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2216 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2217 | // Large content-length -- won't matter, as connection will be reset. |
| 2218 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2219 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2220 | }; |
| 2221 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2222 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2223 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2225 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2226 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2227 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2228 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2229 | |
| 2230 | rv = callback.WaitForResult(); |
| 2231 | EXPECT_EQ(0, rv); |
| 2232 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2233 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2234 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2235 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2236 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2237 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2238 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2239 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2240 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2241 | } |
| 2242 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2243 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2244 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2245 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2246 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2247 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2248 | // reused. See http://crbug.com/544255. |
| 2249 | for (int i = 0; i < 2; ++i) { |
| 2250 | HttpRequestInfo request; |
| 2251 | request.method = "GET"; |
| 2252 | request.url = GURL("http://www.example.org/"); |
| 2253 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2255 | TestNetLog log; |
| 2256 | session_deps_.net_log = &log; |
| 2257 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2258 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2259 | MockWrite data_writes[] = { |
| 2260 | MockWrite(ASYNC, 0, |
| 2261 | "GET / HTTP/1.1\r\n" |
| 2262 | "Host: www.example.org\r\n" |
| 2263 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2264 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2265 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2266 | // be issuing -- the final header line contains the credentials. |
| 2267 | MockWrite(ASYNC, 6, |
| 2268 | "GET / HTTP/1.1\r\n" |
| 2269 | "Host: www.example.org\r\n" |
| 2270 | "Connection: keep-alive\r\n" |
| 2271 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2272 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2274 | MockRead data_reads[] = { |
| 2275 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2276 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2277 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2278 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2279 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2280 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2281 | // Lastly, the server responds with the actual content. |
| 2282 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2283 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2284 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2285 | MockRead(ASYNC, 10, "Hello"), |
| 2286 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2287 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2288 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2289 | arraysize(data_writes)); |
| 2290 | data.set_busy_before_sync_reads(true); |
| 2291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2292 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2293 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2294 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2295 | scoped_ptr<HttpTransaction> trans( |
| 2296 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2297 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 2298 | ASSERT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2299 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2300 | LoadTimingInfo load_timing_info1; |
| 2301 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2302 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2303 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2304 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2305 | ASSERT_TRUE(response); |
| 2306 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2307 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2308 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2309 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2310 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2311 | callback2.callback()); |
| 2312 | ASSERT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2313 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2314 | LoadTimingInfo load_timing_info2; |
| 2315 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2316 | TestLoadTimingReused(load_timing_info2); |
| 2317 | // The load timing after restart should have the same socket ID, and times |
| 2318 | // those of the first load timing. |
| 2319 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2320 | load_timing_info2.send_start); |
| 2321 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2322 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2323 | response = trans->GetResponseInfo(); |
| 2324 | ASSERT_TRUE(response); |
| 2325 | EXPECT_FALSE(response->auth_challenge); |
| 2326 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2327 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2328 | std::string response_data; |
| 2329 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2330 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2331 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2332 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2333 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 2334 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2335 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2339 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2340 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2341 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2343 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2344 | request.load_flags = 0; |
| 2345 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2346 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2347 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2348 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2349 | MockWrite( |
| 2350 | "GET / HTTP/1.1\r\n" |
| 2351 | "Host: www.example.org\r\n" |
| 2352 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2353 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2354 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2355 | // be issuing -- the final header line contains the credentials. |
| 2356 | MockWrite( |
| 2357 | "GET / HTTP/1.1\r\n" |
| 2358 | "Host: www.example.org\r\n" |
| 2359 | "Connection: keep-alive\r\n" |
| 2360 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2361 | }; |
| 2362 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2363 | MockRead data_reads1[] = { |
| 2364 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2365 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2366 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2367 | |
| 2368 | // Lastly, the server responds with the actual content. |
| 2369 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2370 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2371 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2372 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2373 | }; |
| 2374 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2375 | // An incorrect reconnect would cause this to be read. |
| 2376 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2377 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2378 | }; |
| 2379 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2380 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2381 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2382 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2383 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2385 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2387 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2388 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2389 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2391 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2392 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2393 | |
| 2394 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2395 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2396 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2398 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2399 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2401 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2403 | rv = trans->RestartWithAuth( |
| 2404 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2405 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2406 | |
| 2407 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2408 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2409 | |
| 2410 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2411 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2412 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2413 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2417 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2418 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2419 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2420 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2421 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2422 | request.load_flags = 0; |
| 2423 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2424 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2425 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2426 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2427 | MockWrite( |
| 2428 | "GET / HTTP/1.1\r\n" |
| 2429 | "Host: www.example.org\r\n" |
| 2430 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2431 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2432 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2433 | // be issuing -- the final header line contains the credentials. |
| 2434 | MockWrite( |
| 2435 | "GET / HTTP/1.1\r\n" |
| 2436 | "Host: www.example.org\r\n" |
| 2437 | "Connection: keep-alive\r\n" |
| 2438 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2439 | }; |
| 2440 | |
| 2441 | // Respond with 5 kb of response body. |
| 2442 | std::string large_body_string("Unauthorized"); |
| 2443 | large_body_string.append(5 * 1024, ' '); |
| 2444 | large_body_string.append("\r\n"); |
| 2445 | |
| 2446 | MockRead data_reads1[] = { |
| 2447 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2448 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2449 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2450 | // 5134 = 12 + 5 * 1024 + 2 |
| 2451 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2452 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2453 | |
| 2454 | // Lastly, the server responds with the actual content. |
| 2455 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2456 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2457 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2458 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2459 | }; |
| 2460 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2461 | // An incorrect reconnect would cause this to be read. |
| 2462 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2463 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2464 | }; |
| 2465 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2467 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2468 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2469 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2473 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2474 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2475 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2477 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2478 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2479 | |
| 2480 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2481 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2482 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2483 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2484 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2485 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2486 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2487 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2489 | rv = trans->RestartWithAuth( |
| 2490 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2491 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2492 | |
| 2493 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2494 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2495 | |
| 2496 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2497 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2498 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2499 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2503 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2504 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2505 | HttpRequestInfo request; |
| 2506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2507 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2508 | request.load_flags = 0; |
| 2509 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2510 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2511 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2512 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2513 | MockWrite( |
| 2514 | "GET / HTTP/1.1\r\n" |
| 2515 | "Host: www.example.org\r\n" |
| 2516 | "Connection: keep-alive\r\n\r\n"), |
| 2517 | // This simulates the seemingly successful write to a closed connection |
| 2518 | // if the bug is not fixed. |
| 2519 | MockWrite( |
| 2520 | "GET / HTTP/1.1\r\n" |
| 2521 | "Host: www.example.org\r\n" |
| 2522 | "Connection: keep-alive\r\n" |
| 2523 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2524 | }; |
| 2525 | |
| 2526 | MockRead data_reads1[] = { |
| 2527 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2528 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2530 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2531 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2532 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2533 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2534 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2535 | }; |
| 2536 | |
| 2537 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2538 | // be issuing -- the final header line contains the credentials. |
| 2539 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2540 | MockWrite( |
| 2541 | "GET / HTTP/1.1\r\n" |
| 2542 | "Host: www.example.org\r\n" |
| 2543 | "Connection: keep-alive\r\n" |
| 2544 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2545 | }; |
| 2546 | |
| 2547 | // Lastly, the server responds with the actual content. |
| 2548 | MockRead data_reads2[] = { |
| 2549 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2551 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2552 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2553 | }; |
| 2554 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2555 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2556 | data_writes1, arraysize(data_writes1)); |
| 2557 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2558 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2560 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2561 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2562 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2563 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2564 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2565 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2566 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2568 | |
| 2569 | rv = callback1.WaitForResult(); |
| 2570 | EXPECT_EQ(OK, rv); |
| 2571 | |
| 2572 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2573 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2574 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2576 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2578 | rv = trans->RestartWithAuth( |
| 2579 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2581 | |
| 2582 | rv = callback2.WaitForResult(); |
| 2583 | EXPECT_EQ(OK, rv); |
| 2584 | |
| 2585 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2586 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2587 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2588 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2589 | } |
| 2590 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2591 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2592 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2593 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2594 | HttpRequestInfo request; |
| 2595 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2596 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2597 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2598 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2599 | |
| 2600 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2601 | session_deps_.proxy_service = |
| 2602 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2603 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2604 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2605 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2606 | |
| 2607 | // Since we have proxy, should try to establish tunnel. |
| 2608 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2609 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2610 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2611 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2612 | }; |
| 2613 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2614 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2615 | // connection. |
| 2616 | MockRead data_reads1[] = { |
| 2617 | // No credentials. |
| 2618 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2619 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2620 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2621 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2622 | // Since the first connection couldn't be reused, need to establish another |
| 2623 | // once given credentials. |
| 2624 | MockWrite data_writes2[] = { |
| 2625 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2626 | // be issuing -- the final header line contains the credentials. |
| 2627 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2628 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2629 | "Proxy-Connection: keep-alive\r\n" |
| 2630 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2631 | |
| 2632 | MockWrite("GET / HTTP/1.1\r\n" |
| 2633 | "Host: www.example.org\r\n" |
| 2634 | "Connection: keep-alive\r\n\r\n"), |
| 2635 | }; |
| 2636 | |
| 2637 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2638 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2639 | |
| 2640 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2641 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2642 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2643 | MockRead(SYNCHRONOUS, "hello"), |
| 2644 | }; |
| 2645 | |
| 2646 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2647 | data_writes1, arraysize(data_writes1)); |
| 2648 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2649 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2650 | data_writes2, arraysize(data_writes2)); |
| 2651 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2652 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2654 | |
| 2655 | TestCompletionCallback callback1; |
| 2656 | |
| 2657 | scoped_ptr<HttpTransaction> trans( |
| 2658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2659 | |
| 2660 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2662 | |
| 2663 | rv = callback1.WaitForResult(); |
| 2664 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2665 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2666 | log.GetEntries(&entries); |
| 2667 | size_t pos = ExpectLogContainsSomewhere( |
| 2668 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2669 | NetLog::PHASE_NONE); |
| 2670 | ExpectLogContainsSomewhere( |
| 2671 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2672 | NetLog::PHASE_NONE); |
| 2673 | |
| 2674 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2675 | ASSERT_TRUE(response != NULL); |
| 2676 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2677 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2678 | EXPECT_EQ(407, response->headers->response_code()); |
| 2679 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2680 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2681 | |
| 2682 | LoadTimingInfo load_timing_info; |
| 2683 | // CONNECT requests and responses are handled at the connect job level, so |
| 2684 | // the transaction does not yet have a connection. |
| 2685 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2686 | |
| 2687 | TestCompletionCallback callback2; |
| 2688 | |
| 2689 | rv = |
| 2690 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2691 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2692 | |
| 2693 | rv = callback2.WaitForResult(); |
| 2694 | EXPECT_EQ(OK, rv); |
| 2695 | |
| 2696 | response = trans->GetResponseInfo(); |
| 2697 | ASSERT_TRUE(response != NULL); |
| 2698 | |
| 2699 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2700 | EXPECT_EQ(200, response->headers->response_code()); |
| 2701 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2702 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2703 | |
| 2704 | // The password prompt info should not be set. |
| 2705 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2706 | |
| 2707 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2708 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2709 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2710 | |
| 2711 | trans.reset(); |
| 2712 | session->CloseAllConnections(); |
| 2713 | } |
| 2714 | |
| 2715 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2716 | // that requires a restart when setting up an SSL tunnel. |
| 2717 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2718 | HttpRequestInfo request; |
| 2719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2720 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2721 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2722 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2723 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2724 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2725 | session_deps_.proxy_service = |
| 2726 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2727 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2728 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2729 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2730 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2731 | // Since we have proxy, should try to establish tunnel. |
| 2732 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2733 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2734 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2736 | }; |
| 2737 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2738 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2739 | // connection. |
| 2740 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2741 | // No credentials. |
| 2742 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2743 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2744 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2745 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2746 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2747 | MockWrite data_writes2[] = { |
| 2748 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2749 | // be issuing -- the final header line contains the credentials. |
| 2750 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2751 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2752 | "Proxy-Connection: keep-alive\r\n" |
| 2753 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2754 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2755 | MockWrite("GET / HTTP/1.1\r\n" |
| 2756 | "Host: www.example.org\r\n" |
| 2757 | "Connection: keep-alive\r\n\r\n"), |
| 2758 | }; |
| 2759 | |
| 2760 | MockRead data_reads2[] = { |
| 2761 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2762 | |
| 2763 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2764 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2765 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2766 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2767 | }; |
| 2768 | |
| 2769 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2770 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2771 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2772 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2773 | data_writes2, arraysize(data_writes2)); |
| 2774 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2775 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2778 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2779 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2780 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2783 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2784 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2785 | |
| 2786 | rv = callback1.WaitForResult(); |
| 2787 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2788 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2789 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2790 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2791 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2792 | NetLog::PHASE_NONE); |
| 2793 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2794 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2795 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2796 | NetLog::PHASE_NONE); |
| 2797 | |
| 2798 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2799 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2800 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2801 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2802 | EXPECT_EQ(407, response->headers->response_code()); |
| 2803 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2804 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2805 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2806 | LoadTimingInfo load_timing_info; |
| 2807 | // CONNECT requests and responses are handled at the connect job level, so |
| 2808 | // the transaction does not yet have a connection. |
| 2809 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2811 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2813 | rv = trans->RestartWithAuth( |
| 2814 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2816 | |
| 2817 | rv = callback2.WaitForResult(); |
| 2818 | EXPECT_EQ(OK, rv); |
| 2819 | |
| 2820 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2821 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2822 | |
| 2823 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2824 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2825 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2826 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2827 | |
| 2828 | // The password prompt info should not be set. |
| 2829 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2830 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2831 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2832 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2833 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2834 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2835 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2836 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2837 | } |
| 2838 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2839 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2840 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2841 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2842 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2843 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2844 | // reused. See http://crbug.com/544255. |
| 2845 | for (int i = 0; i < 2; ++i) { |
| 2846 | HttpRequestInfo request; |
| 2847 | request.method = "GET"; |
| 2848 | request.url = GURL("https://www.example.org/"); |
| 2849 | // Ensure that proxy authentication is attempted even |
| 2850 | // when the no authentication data flag is set. |
| 2851 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2852 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2853 | // Configure against proxy server "myproxy:70". |
| 2854 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2855 | BoundTestNetLog log; |
| 2856 | session_deps_.net_log = log.bound().net_log(); |
| 2857 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2858 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2859 | scoped_ptr<HttpTransaction> trans( |
| 2860 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2861 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2862 | // Since we have proxy, should try to establish tunnel. |
| 2863 | MockWrite data_writes1[] = { |
| 2864 | MockWrite(ASYNC, 0, |
| 2865 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2866 | "Host: www.example.org:443\r\n" |
| 2867 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2868 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2869 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2870 | // be issuing -- the final header line contains the credentials. |
| 2871 | MockWrite(ASYNC, 3, |
| 2872 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2873 | "Host: www.example.org:443\r\n" |
| 2874 | "Proxy-Connection: keep-alive\r\n" |
| 2875 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2876 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2877 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2878 | // The proxy responds to the connect with a 407, using a persistent |
| 2879 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2880 | MockRead data_reads1[] = { |
| 2881 | // No credentials. |
| 2882 | MockRead(ASYNC, 1, |
| 2883 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2884 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2885 | "Proxy-Connection: keep-alive\r\n" |
| 2886 | "Content-Length: 10\r\n\r\n"), |
| 2887 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2888 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2889 | // Wrong credentials (wrong password). |
| 2890 | MockRead(ASYNC, 4, |
| 2891 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2892 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2893 | "Proxy-Connection: keep-alive\r\n" |
| 2894 | "Content-Length: 10\r\n\r\n"), |
| 2895 | // No response body because the test stops reading here. |
| 2896 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 2897 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2898 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2899 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 2900 | arraysize(data_writes1)); |
| 2901 | data1.set_busy_before_sync_reads(true); |
| 2902 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2903 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2904 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2905 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2906 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2907 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2908 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2909 | TestNetLogEntry::List entries; |
| 2910 | log.GetEntries(&entries); |
| 2911 | size_t pos = ExpectLogContainsSomewhere( |
| 2912 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2913 | NetLog::PHASE_NONE); |
| 2914 | ExpectLogContainsSomewhere( |
| 2915 | entries, pos, |
| 2916 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2917 | NetLog::PHASE_NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2918 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2919 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2920 | ASSERT_TRUE(response); |
| 2921 | ASSERT_TRUE(response->headers); |
| 2922 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2923 | EXPECT_EQ(407, response->headers->response_code()); |
| 2924 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2925 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2926 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2927 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2928 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2929 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2930 | // Wrong password (should be "bar"). |
| 2931 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 2932 | callback2.callback()); |
| 2933 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2934 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2935 | response = trans->GetResponseInfo(); |
| 2936 | ASSERT_TRUE(response); |
| 2937 | ASSERT_TRUE(response->headers); |
| 2938 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2939 | EXPECT_EQ(407, response->headers->response_code()); |
| 2940 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2941 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2942 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2943 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2944 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2945 | // out of scope. |
| 2946 | session->CloseAllConnections(); |
| 2947 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2951 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2952 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 2953 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2954 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2955 | // reused. See http://crbug.com/544255. |
| 2956 | for (int i = 0; i < 2; ++i) { |
| 2957 | HttpRequestInfo request; |
| 2958 | request.method = "GET"; |
| 2959 | request.url = GURL("https://www.example.org/"); |
| 2960 | // Ensure that proxy authentication is attempted even |
| 2961 | // when the no authentication data flag is set. |
| 2962 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2963 | |
| 2964 | // Configure against proxy server "myproxy:70". |
| 2965 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2966 | BoundTestNetLog log; |
| 2967 | session_deps_.net_log = log.bound().net_log(); |
| 2968 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2969 | |
| 2970 | scoped_ptr<HttpTransaction> trans( |
| 2971 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2972 | |
| 2973 | // Since we have proxy, should try to establish tunnel. |
| 2974 | MockWrite data_writes1[] = { |
| 2975 | MockWrite(ASYNC, 0, |
| 2976 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2977 | "Host: www.example.org:443\r\n" |
| 2978 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2979 | |
| 2980 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2981 | // be issuing -- the final header line contains the credentials. |
| 2982 | MockWrite(ASYNC, 3, |
| 2983 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2984 | "Host: www.example.org:443\r\n" |
| 2985 | "Proxy-Connection: keep-alive\r\n" |
| 2986 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2987 | }; |
| 2988 | |
| 2989 | // The proxy responds to the connect with a 407, using a persistent |
| 2990 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2991 | MockRead data_reads1[] = { |
| 2992 | // No credentials. |
| 2993 | MockRead(ASYNC, 1, |
| 2994 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 2995 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2996 | "Content-Length: 10\r\n\r\n"), |
| 2997 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 2998 | |
| 2999 | // Wrong credentials (wrong password). |
| 3000 | MockRead(ASYNC, 4, |
| 3001 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3002 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3003 | "Content-Length: 10\r\n\r\n"), |
| 3004 | // No response body because the test stops reading here. |
| 3005 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3006 | }; |
| 3007 | |
| 3008 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3009 | arraysize(data_writes1)); |
| 3010 | data1.set_busy_before_sync_reads(true); |
| 3011 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3012 | |
| 3013 | TestCompletionCallback callback1; |
| 3014 | |
| 3015 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3016 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3017 | |
| 3018 | TestNetLogEntry::List entries; |
| 3019 | log.GetEntries(&entries); |
| 3020 | size_t pos = ExpectLogContainsSomewhere( |
| 3021 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3022 | NetLog::PHASE_NONE); |
| 3023 | ExpectLogContainsSomewhere( |
| 3024 | entries, pos, |
| 3025 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3026 | NetLog::PHASE_NONE); |
| 3027 | |
| 3028 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3029 | ASSERT_TRUE(response); |
| 3030 | ASSERT_TRUE(response->headers); |
| 3031 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3032 | EXPECT_EQ(407, response->headers->response_code()); |
| 3033 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3034 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3035 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3036 | |
| 3037 | TestCompletionCallback callback2; |
| 3038 | |
| 3039 | // Wrong password (should be "bar"). |
| 3040 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3041 | callback2.callback()); |
| 3042 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 3043 | |
| 3044 | response = trans->GetResponseInfo(); |
| 3045 | ASSERT_TRUE(response); |
| 3046 | ASSERT_TRUE(response->headers); |
| 3047 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3048 | EXPECT_EQ(407, response->headers->response_code()); |
| 3049 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3050 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3051 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3052 | |
| 3053 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3054 | // out of scope. |
| 3055 | session->CloseAllConnections(); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3060 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3061 | // the case the server sends extra data on the original socket, so it can't be |
| 3062 | // reused. |
| 3063 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3064 | HttpRequestInfo request; |
| 3065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3066 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3067 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3068 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3069 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3070 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3071 | session_deps_.proxy_service = |
| 3072 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3073 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3074 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3075 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3077 | // Since we have proxy, should try to establish tunnel. |
| 3078 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3079 | MockWrite(ASYNC, 0, |
| 3080 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3081 | "Host: www.example.org:443\r\n" |
| 3082 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3083 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3084 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3085 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3086 | // extra data, so the socket cannot be reused. |
| 3087 | MockRead data_reads1[] = { |
| 3088 | // No credentials. |
| 3089 | MockRead(ASYNC, 1, |
| 3090 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3091 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3092 | "Content-Length: 10\r\n\r\n"), |
| 3093 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3094 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3095 | }; |
| 3096 | |
| 3097 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3098 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3099 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3100 | MockWrite(ASYNC, 0, |
| 3101 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3102 | "Host: www.example.org:443\r\n" |
| 3103 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3104 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3105 | |
| 3106 | MockWrite(ASYNC, 2, |
| 3107 | "GET / HTTP/1.1\r\n" |
| 3108 | "Host: www.example.org\r\n" |
| 3109 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3110 | }; |
| 3111 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3112 | MockRead data_reads2[] = { |
| 3113 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3114 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3115 | MockRead(ASYNC, 3, |
| 3116 | "HTTP/1.1 200 OK\r\n" |
| 3117 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3118 | "Content-Length: 5\r\n\r\n"), |
| 3119 | // No response body because the test stops reading here. |
| 3120 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3121 | }; |
| 3122 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3123 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3124 | arraysize(data_writes1)); |
| 3125 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3126 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3127 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3128 | arraysize(data_writes2)); |
| 3129 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3130 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3133 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3134 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3135 | scoped_ptr<HttpTransaction> trans( |
| 3136 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3137 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3138 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3139 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3140 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3141 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3142 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3143 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3144 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3145 | NetLog::PHASE_NONE); |
| 3146 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3147 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3148 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3149 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3150 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3151 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3152 | ASSERT_TRUE(response); |
| 3153 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3154 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3155 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3156 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3157 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3158 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3159 | LoadTimingInfo load_timing_info; |
| 3160 | // CONNECT requests and responses are handled at the connect job level, so |
| 3161 | // the transaction does not yet have a connection. |
| 3162 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3164 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3165 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3166 | rv = |
| 3167 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 3168 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3170 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3171 | EXPECT_EQ(200, response->headers->response_code()); |
| 3172 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3173 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3174 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3175 | // The password prompt info should not be set. |
| 3176 | EXPECT_FALSE(response->auth_challenge); |
| 3177 | |
| 3178 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3179 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3180 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3181 | |
| 3182 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3183 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3184 | } |
| 3185 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3186 | // Test the case a proxy closes a socket while the challenge body is being |
| 3187 | // drained. |
| 3188 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3189 | HttpRequestInfo request; |
| 3190 | request.method = "GET"; |
| 3191 | request.url = GURL("https://www.example.org/"); |
| 3192 | // Ensure that proxy authentication is attempted even |
| 3193 | // when the no authentication data flag is set. |
| 3194 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3195 | |
| 3196 | // Configure against proxy server "myproxy:70". |
| 3197 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3198 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3199 | |
| 3200 | scoped_ptr<HttpTransaction> trans( |
| 3201 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3202 | |
| 3203 | // Since we have proxy, should try to establish tunnel. |
| 3204 | MockWrite data_writes1[] = { |
| 3205 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3206 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3207 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3208 | }; |
| 3209 | |
| 3210 | // The proxy responds to the connect with a 407, using a persistent |
| 3211 | // connection. |
| 3212 | MockRead data_reads1[] = { |
| 3213 | // No credentials. |
| 3214 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3215 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3216 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3217 | // Server hands up in the middle of the body. |
| 3218 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3219 | }; |
| 3220 | |
| 3221 | MockWrite data_writes2[] = { |
| 3222 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3223 | // be issuing -- the final header line contains the credentials. |
| 3224 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3225 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3226 | "Proxy-Connection: keep-alive\r\n" |
| 3227 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3228 | |
| 3229 | MockWrite("GET / HTTP/1.1\r\n" |
| 3230 | "Host: www.example.org\r\n" |
| 3231 | "Connection: keep-alive\r\n\r\n"), |
| 3232 | }; |
| 3233 | |
| 3234 | MockRead data_reads2[] = { |
| 3235 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3236 | |
| 3237 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3238 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3239 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3240 | MockRead(SYNCHRONOUS, "hello"), |
| 3241 | }; |
| 3242 | |
| 3243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3244 | data_writes1, arraysize(data_writes1)); |
| 3245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3246 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3247 | data_writes2, arraysize(data_writes2)); |
| 3248 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3249 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3251 | |
| 3252 | TestCompletionCallback callback; |
| 3253 | |
| 3254 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3255 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3256 | |
| 3257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3258 | ASSERT_TRUE(response); |
| 3259 | ASSERT_TRUE(response->headers); |
| 3260 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3261 | EXPECT_EQ(407, response->headers->response_code()); |
| 3262 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3263 | |
| 3264 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3265 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3266 | |
| 3267 | response = trans->GetResponseInfo(); |
| 3268 | ASSERT_TRUE(response); |
| 3269 | ASSERT_TRUE(response->headers); |
| 3270 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3271 | EXPECT_EQ(200, response->headers->response_code()); |
| 3272 | std::string body; |
| 3273 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3274 | EXPECT_EQ("hello", body); |
| 3275 | } |
| 3276 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3277 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3278 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3279 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3280 | HttpRequestInfo request; |
| 3281 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3282 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3283 | request.load_flags = 0; |
| 3284 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3285 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3286 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3287 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3288 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3289 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3290 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3291 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3292 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3293 | // Since we have proxy, should try to establish tunnel. |
| 3294 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3295 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3296 | "Host: www.example.org:443\r\n" |
| 3297 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3298 | }; |
| 3299 | |
| 3300 | // The proxy responds to the connect with a 407. |
| 3301 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3302 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3303 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3304 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3305 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3306 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3307 | }; |
| 3308 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3309 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3310 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3311 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3313 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3315 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3316 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3317 | |
| 3318 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3319 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3320 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3321 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3322 | ASSERT_TRUE(response); |
| 3323 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3324 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3325 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3326 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3327 | |
| 3328 | std::string response_data; |
| 3329 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3330 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3331 | |
| 3332 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3333 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3334 | } |
| 3335 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3336 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3337 | // caller when the proxy responds to CONNECT with 407. |
| 3338 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3339 | HttpRequestInfo request; |
| 3340 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3341 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3342 | request.load_flags = 0; |
| 3343 | |
| 3344 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3345 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3346 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3347 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3348 | |
| 3349 | scoped_ptr<HttpTransaction> trans( |
| 3350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3351 | |
| 3352 | // Since we have proxy, should try to establish tunnel. |
| 3353 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3354 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3355 | "Host: www.example.org:443\r\n" |
| 3356 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3357 | }; |
| 3358 | |
| 3359 | // The proxy responds to the connect with a 407. |
| 3360 | MockRead data_reads[] = { |
| 3361 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3362 | MockRead("X-Foo: bar\r\n"), |
| 3363 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3364 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3365 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 3366 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3367 | }; |
| 3368 | |
| 3369 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3370 | arraysize(data_writes)); |
| 3371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3372 | |
| 3373 | TestCompletionCallback callback; |
| 3374 | |
| 3375 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3376 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3377 | |
| 3378 | rv = callback.WaitForResult(); |
| 3379 | EXPECT_EQ(OK, rv); |
| 3380 | |
| 3381 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3382 | ASSERT_TRUE(response); |
| 3383 | ASSERT_TRUE(response->headers); |
| 3384 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3385 | EXPECT_EQ(407, response->headers->response_code()); |
| 3386 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3387 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3388 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3389 | |
| 3390 | std::string response_data; |
| 3391 | rv = ReadTransaction(trans.get(), &response_data); |
| 3392 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3393 | |
| 3394 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3395 | session->CloseAllConnections(); |
| 3396 | } |
| 3397 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3398 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3399 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3400 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3401 | HttpRequestInfo request; |
| 3402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3404 | request.load_flags = 0; |
| 3405 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3406 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3407 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3408 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3409 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3410 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3411 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3412 | MockWrite( |
| 3413 | "GET / HTTP/1.1\r\n" |
| 3414 | "Host: www.example.org\r\n" |
| 3415 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3416 | }; |
| 3417 | |
| 3418 | MockRead data_reads1[] = { |
| 3419 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3420 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3421 | // Large content-length -- won't matter, as connection will be reset. |
| 3422 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3423 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3424 | }; |
| 3425 | |
| 3426 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3427 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3428 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3430 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3432 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3433 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3434 | |
| 3435 | rv = callback.WaitForResult(); |
| 3436 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3437 | } |
| 3438 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3439 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3440 | // through a non-authenticating proxy. The request should fail with |
| 3441 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3442 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3443 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3444 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3445 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3446 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3447 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3448 | HttpRequestInfo request; |
| 3449 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3450 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3451 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3452 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3453 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3454 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3455 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3456 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3457 | // Since we have proxy, should try to establish tunnel. |
| 3458 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3460 | "Host: www.example.org:443\r\n" |
| 3461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3462 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3463 | MockWrite("GET / HTTP/1.1\r\n" |
| 3464 | "Host: www.example.org\r\n" |
| 3465 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3466 | }; |
| 3467 | |
| 3468 | MockRead data_reads1[] = { |
| 3469 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3470 | |
| 3471 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3472 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3473 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3474 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3475 | }; |
| 3476 | |
| 3477 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3478 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3479 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3480 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3483 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3484 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3485 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3486 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3488 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3489 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3490 | |
| 3491 | rv = callback1.WaitForResult(); |
| 3492 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3493 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3494 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3495 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3496 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3497 | NetLog::PHASE_NONE); |
| 3498 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3499 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3500 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3501 | NetLog::PHASE_NONE); |
| 3502 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3503 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3504 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3505 | // that uses non-persistent connections. |
| 3506 | TEST_P(HttpNetworkTransactionTest, |
| 3507 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3508 | HttpRequestInfo request; |
| 3509 | request.method = "GET"; |
| 3510 | request.url = GURL("https://www.example.org/"); |
| 3511 | |
| 3512 | // Configure against proxy server "myproxy:70". |
| 3513 | session_deps_.proxy_service = |
| 3514 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3515 | |
| 3516 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3517 | new HttpAuthHandlerMock::Factory()); |
| 3518 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3519 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3520 | mock_handler->set_allows_default_credentials(true); |
| 3521 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3522 | HttpAuth::AUTH_PROXY); |
| 3523 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3524 | |
| 3525 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3526 | NetLog net_log; |
| 3527 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3528 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3529 | |
| 3530 | // Since we have proxy, should try to establish tunnel. |
| 3531 | MockWrite data_writes1[] = { |
| 3532 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3533 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3535 | }; |
| 3536 | |
| 3537 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3538 | // connection. |
| 3539 | MockRead data_reads1[] = { |
| 3540 | // No credentials. |
| 3541 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3542 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3543 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3544 | }; |
| 3545 | |
| 3546 | // Since the first connection couldn't be reused, need to establish another |
| 3547 | // once given credentials. |
| 3548 | MockWrite data_writes2[] = { |
| 3549 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3550 | // be issuing -- the final header line contains the credentials. |
| 3551 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3552 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3553 | "Proxy-Connection: keep-alive\r\n" |
| 3554 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3555 | |
| 3556 | MockWrite("GET / HTTP/1.1\r\n" |
| 3557 | "Host: www.example.org\r\n" |
| 3558 | "Connection: keep-alive\r\n\r\n"), |
| 3559 | }; |
| 3560 | |
| 3561 | MockRead data_reads2[] = { |
| 3562 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3563 | |
| 3564 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3566 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3567 | MockRead(SYNCHRONOUS, "hello"), |
| 3568 | }; |
| 3569 | |
| 3570 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3571 | data_writes1, arraysize(data_writes1)); |
| 3572 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3573 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3574 | data_writes2, arraysize(data_writes2)); |
| 3575 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3576 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3578 | |
| 3579 | scoped_ptr<HttpTransaction> trans( |
| 3580 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3581 | |
| 3582 | TestCompletionCallback callback; |
| 3583 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3584 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3585 | |
| 3586 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3587 | ASSERT_TRUE(response); |
| 3588 | ASSERT_TRUE(response->headers); |
| 3589 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3590 | EXPECT_EQ(407, response->headers->response_code()); |
| 3591 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3592 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3593 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3594 | |
| 3595 | LoadTimingInfo load_timing_info; |
| 3596 | // CONNECT requests and responses are handled at the connect job level, so |
| 3597 | // the transaction does not yet have a connection. |
| 3598 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3599 | |
| 3600 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3601 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3602 | response = trans->GetResponseInfo(); |
| 3603 | ASSERT_TRUE(response); |
| 3604 | ASSERT_TRUE(response->headers); |
| 3605 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3606 | EXPECT_EQ(200, response->headers->response_code()); |
| 3607 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3608 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3609 | |
| 3610 | // The password prompt info should not be set. |
| 3611 | EXPECT_FALSE(response->auth_challenge); |
| 3612 | |
| 3613 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3614 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3615 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3616 | |
| 3617 | trans.reset(); |
| 3618 | session->CloseAllConnections(); |
| 3619 | } |
| 3620 | |
| 3621 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3622 | // that hangs up when credentials are initially sent. |
| 3623 | TEST_P(HttpNetworkTransactionTest, |
| 3624 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3625 | HttpRequestInfo request; |
| 3626 | request.method = "GET"; |
| 3627 | request.url = GURL("https://www.example.org/"); |
| 3628 | |
| 3629 | // Configure against proxy server "myproxy:70". |
| 3630 | session_deps_.proxy_service = |
| 3631 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3632 | |
| 3633 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3634 | new HttpAuthHandlerMock::Factory()); |
| 3635 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3636 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3637 | mock_handler->set_allows_default_credentials(true); |
| 3638 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3639 | HttpAuth::AUTH_PROXY); |
| 3640 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3641 | |
| 3642 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3643 | NetLog net_log; |
| 3644 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3645 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3646 | |
| 3647 | // Should try to establish tunnel. |
| 3648 | MockWrite data_writes1[] = { |
| 3649 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3650 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3651 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3652 | |
| 3653 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3654 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3655 | "Proxy-Connection: keep-alive\r\n" |
| 3656 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3657 | }; |
| 3658 | |
| 3659 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3660 | // connection. |
| 3661 | MockRead data_reads1[] = { |
| 3662 | // No credentials. |
| 3663 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3664 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3665 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3666 | }; |
| 3667 | |
| 3668 | // Since the first connection was closed, need to establish another once given |
| 3669 | // credentials. |
| 3670 | MockWrite data_writes2[] = { |
| 3671 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3672 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3673 | "Proxy-Connection: keep-alive\r\n" |
| 3674 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3675 | |
| 3676 | MockWrite("GET / HTTP/1.1\r\n" |
| 3677 | "Host: www.example.org\r\n" |
| 3678 | "Connection: keep-alive\r\n\r\n"), |
| 3679 | }; |
| 3680 | |
| 3681 | MockRead data_reads2[] = { |
| 3682 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3683 | |
| 3684 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3685 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3686 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3687 | MockRead(SYNCHRONOUS, "hello"), |
| 3688 | }; |
| 3689 | |
| 3690 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3691 | data_writes1, arraysize(data_writes1)); |
| 3692 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3693 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3694 | data_writes2, arraysize(data_writes2)); |
| 3695 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3696 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3697 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3698 | |
| 3699 | scoped_ptr<HttpTransaction> trans( |
| 3700 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3701 | |
| 3702 | TestCompletionCallback callback; |
| 3703 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3704 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3705 | |
| 3706 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3707 | ASSERT_TRUE(response); |
| 3708 | ASSERT_TRUE(response->headers); |
| 3709 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3710 | EXPECT_EQ(407, response->headers->response_code()); |
| 3711 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3712 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3713 | EXPECT_FALSE(response->auth_challenge); |
| 3714 | |
| 3715 | LoadTimingInfo load_timing_info; |
| 3716 | // CONNECT requests and responses are handled at the connect job level, so |
| 3717 | // the transaction does not yet have a connection. |
| 3718 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3719 | |
| 3720 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3721 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3722 | |
| 3723 | response = trans->GetResponseInfo(); |
| 3724 | ASSERT_TRUE(response); |
| 3725 | ASSERT_TRUE(response->headers); |
| 3726 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3727 | EXPECT_EQ(200, response->headers->response_code()); |
| 3728 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3729 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3730 | |
| 3731 | // The password prompt info should not be set. |
| 3732 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3733 | |
| 3734 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3735 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3736 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3737 | |
| 3738 | trans.reset(); |
| 3739 | session->CloseAllConnections(); |
| 3740 | } |
| 3741 | |
| 3742 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3743 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3744 | // they are retried. |
| 3745 | TEST_P(HttpNetworkTransactionTest, |
| 3746 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3747 | HttpRequestInfo request; |
| 3748 | request.method = "GET"; |
| 3749 | request.url = GURL("https://www.example.org/"); |
| 3750 | |
| 3751 | // Configure against proxy server "myproxy:70". |
| 3752 | session_deps_.proxy_service = |
| 3753 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3754 | |
| 3755 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3756 | new HttpAuthHandlerMock::Factory()); |
| 3757 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3758 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3759 | mock_handler->set_allows_default_credentials(true); |
| 3760 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3761 | HttpAuth::AUTH_PROXY); |
| 3762 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3763 | |
| 3764 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3765 | NetLog net_log; |
| 3766 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3767 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3768 | |
| 3769 | // Should try to establish tunnel. |
| 3770 | MockWrite data_writes1[] = { |
| 3771 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3772 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3773 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3774 | |
| 3775 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3776 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3777 | "Proxy-Connection: keep-alive\r\n" |
| 3778 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3779 | }; |
| 3780 | |
| 3781 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3782 | // second request is sent. |
| 3783 | MockRead data_reads1[] = { |
| 3784 | // No credentials. |
| 3785 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3786 | MockRead("Content-Length: 0\r\n"), |
| 3787 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3788 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3789 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3790 | }; |
| 3791 | |
| 3792 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3793 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3794 | // request. |
| 3795 | MockWrite data_writes2[] = { |
| 3796 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3797 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3798 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3799 | }; |
| 3800 | |
| 3801 | // The proxy, having had more than enough of us, just hangs up. |
| 3802 | MockRead data_reads2[] = { |
| 3803 | // No credentials. |
| 3804 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3805 | }; |
| 3806 | |
| 3807 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3808 | data_writes1, arraysize(data_writes1)); |
| 3809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3810 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3811 | data_writes2, arraysize(data_writes2)); |
| 3812 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3813 | |
| 3814 | scoped_ptr<HttpTransaction> trans( |
| 3815 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3816 | |
| 3817 | TestCompletionCallback callback; |
| 3818 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3819 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3820 | |
| 3821 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3822 | ASSERT_TRUE(response); |
| 3823 | ASSERT_TRUE(response->headers); |
| 3824 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3825 | EXPECT_EQ(407, response->headers->response_code()); |
| 3826 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3827 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3828 | EXPECT_FALSE(response->auth_challenge); |
| 3829 | |
| 3830 | LoadTimingInfo load_timing_info; |
| 3831 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3832 | |
| 3833 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3834 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3835 | |
| 3836 | trans.reset(); |
| 3837 | session->CloseAllConnections(); |
| 3838 | } |
| 3839 | |
| 3840 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3841 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3842 | // again they are retried. |
| 3843 | TEST_P(HttpNetworkTransactionTest, |
| 3844 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3845 | HttpRequestInfo request; |
| 3846 | request.method = "GET"; |
| 3847 | request.url = GURL("https://www.example.org/"); |
| 3848 | |
| 3849 | // Configure against proxy server "myproxy:70". |
| 3850 | session_deps_.proxy_service = |
| 3851 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3852 | |
| 3853 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3854 | new HttpAuthHandlerMock::Factory()); |
| 3855 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3856 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3857 | mock_handler->set_allows_default_credentials(true); |
| 3858 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3859 | HttpAuth::AUTH_PROXY); |
| 3860 | // Add another handler for the second challenge. It supports default |
| 3861 | // credentials, but they shouldn't be used, since they were already tried. |
| 3862 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3863 | mock_handler->set_allows_default_credentials(true); |
| 3864 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3865 | HttpAuth::AUTH_PROXY); |
| 3866 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3867 | |
| 3868 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3869 | NetLog net_log; |
| 3870 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3871 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3872 | |
| 3873 | // Should try to establish tunnel. |
| 3874 | MockWrite data_writes1[] = { |
| 3875 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3876 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3877 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3878 | }; |
| 3879 | |
| 3880 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3881 | // connection. |
| 3882 | MockRead data_reads1[] = { |
| 3883 | // No credentials. |
| 3884 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3885 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3886 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3887 | }; |
| 3888 | |
| 3889 | // Since the first connection was closed, need to establish another once given |
| 3890 | // credentials. |
| 3891 | MockWrite data_writes2[] = { |
| 3892 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3893 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3894 | "Proxy-Connection: keep-alive\r\n" |
| 3895 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3896 | }; |
| 3897 | |
| 3898 | MockRead data_reads2[] = { |
| 3899 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3900 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3901 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3902 | }; |
| 3903 | |
| 3904 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3905 | data_writes1, arraysize(data_writes1)); |
| 3906 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3907 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3908 | data_writes2, arraysize(data_writes2)); |
| 3909 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3910 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3911 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3912 | |
| 3913 | scoped_ptr<HttpTransaction> trans( |
| 3914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3915 | |
| 3916 | TestCompletionCallback callback; |
| 3917 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3918 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3919 | |
| 3920 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3921 | ASSERT_TRUE(response); |
| 3922 | ASSERT_TRUE(response->headers); |
| 3923 | EXPECT_EQ(407, response->headers->response_code()); |
| 3924 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3925 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3926 | EXPECT_FALSE(response->auth_challenge); |
| 3927 | |
| 3928 | LoadTimingInfo load_timing_info; |
| 3929 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3930 | |
| 3931 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3932 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3933 | response = trans->GetResponseInfo(); |
| 3934 | ASSERT_TRUE(response); |
| 3935 | ASSERT_TRUE(response->headers); |
| 3936 | EXPECT_EQ(407, response->headers->response_code()); |
| 3937 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3938 | EXPECT_TRUE(response->auth_challenge); |
| 3939 | |
| 3940 | trans.reset(); |
| 3941 | session->CloseAllConnections(); |
| 3942 | } |
| 3943 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3944 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3945 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3946 | HttpRequestInfo request1; |
| 3947 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3948 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3949 | |
| 3950 | HttpRequestInfo request2; |
| 3951 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3952 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3953 | |
| 3954 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3955 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3956 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3957 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3958 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3959 | |
| 3960 | // Since we have proxy, should try to establish tunnel. |
| 3961 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3962 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3963 | "Host: www.example.org:443\r\n" |
| 3964 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3965 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3966 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3967 | "Host: www.example.org\r\n" |
| 3968 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3969 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3970 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3971 | "Host: www.example.org\r\n" |
| 3972 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3973 | }; |
| 3974 | |
| 3975 | // The proxy responds to the connect with a 407, using a persistent |
| 3976 | // connection. |
| 3977 | MockRead data_reads1[] = { |
| 3978 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3979 | |
| 3980 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3981 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3982 | MockRead(SYNCHRONOUS, "1"), |
| 3983 | |
| 3984 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3985 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3986 | MockRead(SYNCHRONOUS, "22"), |
| 3987 | }; |
| 3988 | |
| 3989 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3990 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3992 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3994 | |
| 3995 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3996 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3998 | |
| 3999 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4000 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4001 | |
| 4002 | rv = callback1.WaitForResult(); |
| 4003 | EXPECT_EQ(OK, rv); |
| 4004 | |
| 4005 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4006 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4007 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4008 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4009 | |
| 4010 | LoadTimingInfo load_timing_info1; |
| 4011 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4012 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4013 | |
| 4014 | trans1.reset(); |
| 4015 | |
| 4016 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4017 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4019 | |
| 4020 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4021 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4022 | |
| 4023 | rv = callback2.WaitForResult(); |
| 4024 | EXPECT_EQ(OK, rv); |
| 4025 | |
| 4026 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4027 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4028 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4029 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4030 | |
| 4031 | LoadTimingInfo load_timing_info2; |
| 4032 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4033 | TestLoadTimingReused(load_timing_info2); |
| 4034 | |
| 4035 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4036 | |
| 4037 | trans2.reset(); |
| 4038 | session->CloseAllConnections(); |
| 4039 | } |
| 4040 | |
| 4041 | // 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] | 4042 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4043 | HttpRequestInfo request1; |
| 4044 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4045 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4046 | |
| 4047 | HttpRequestInfo request2; |
| 4048 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4049 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4050 | |
| 4051 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4052 | session_deps_.proxy_service = |
| 4053 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4054 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4055 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4056 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4057 | |
| 4058 | // Since we have proxy, should try to establish tunnel. |
| 4059 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4060 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4061 | "Host: www.example.org:443\r\n" |
| 4062 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4063 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4064 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4065 | "Host: www.example.org\r\n" |
| 4066 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4067 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4068 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4069 | "Host: www.example.org\r\n" |
| 4070 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4071 | }; |
| 4072 | |
| 4073 | // The proxy responds to the connect with a 407, using a persistent |
| 4074 | // connection. |
| 4075 | MockRead data_reads1[] = { |
| 4076 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4077 | |
| 4078 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4079 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4080 | MockRead(SYNCHRONOUS, "1"), |
| 4081 | |
| 4082 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4083 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4084 | MockRead(SYNCHRONOUS, "22"), |
| 4085 | }; |
| 4086 | |
| 4087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4088 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4090 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4092 | |
| 4093 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4094 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4095 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4096 | |
| 4097 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4098 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4099 | |
| 4100 | rv = callback1.WaitForResult(); |
| 4101 | EXPECT_EQ(OK, rv); |
| 4102 | |
| 4103 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4104 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4105 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4106 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4107 | |
| 4108 | LoadTimingInfo load_timing_info1; |
| 4109 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4110 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4111 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4112 | |
| 4113 | trans1.reset(); |
| 4114 | |
| 4115 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4116 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4117 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4118 | |
| 4119 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4121 | |
| 4122 | rv = callback2.WaitForResult(); |
| 4123 | EXPECT_EQ(OK, rv); |
| 4124 | |
| 4125 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4126 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4127 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4128 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4129 | |
| 4130 | LoadTimingInfo load_timing_info2; |
| 4131 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4132 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4133 | |
| 4134 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4135 | |
| 4136 | trans2.reset(); |
| 4137 | session->CloseAllConnections(); |
| 4138 | } |
| 4139 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4140 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4141 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4142 | HttpRequestInfo request; |
| 4143 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4144 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4145 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4146 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4147 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4148 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4149 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4150 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4151 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4152 | // Since we have proxy, should use full url |
| 4153 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4154 | MockWrite( |
| 4155 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4156 | "Host: www.example.org\r\n" |
| 4157 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4158 | }; |
| 4159 | |
| 4160 | MockRead data_reads1[] = { |
| 4161 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4162 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4163 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4165 | }; |
| 4166 | |
| 4167 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4168 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4170 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4173 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4174 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4175 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4178 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4180 | |
| 4181 | rv = callback1.WaitForResult(); |
| 4182 | EXPECT_EQ(OK, rv); |
| 4183 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4184 | LoadTimingInfo load_timing_info; |
| 4185 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4186 | TestLoadTimingNotReused(load_timing_info, |
| 4187 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4188 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4189 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4190 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4191 | |
| 4192 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4193 | EXPECT_EQ(200, response->headers->response_code()); |
| 4194 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4195 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4196 | |
| 4197 | // The password prompt info should not be set. |
| 4198 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4199 | } |
| 4200 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4201 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4202 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4203 | HttpRequestInfo request; |
| 4204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4205 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4206 | request.load_flags = 0; |
| 4207 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4208 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4209 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4210 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4211 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4212 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4213 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4214 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4215 | scoped_ptr<SpdyFrame> req( |
| 4216 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4217 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4218 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4219 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4220 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4221 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4222 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4223 | }; |
| 4224 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4225 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4226 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4227 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4228 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4229 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4230 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4233 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4234 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4235 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4236 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4238 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4239 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4240 | |
| 4241 | rv = callback1.WaitForResult(); |
| 4242 | EXPECT_EQ(OK, rv); |
| 4243 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4244 | LoadTimingInfo load_timing_info; |
| 4245 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4246 | TestLoadTimingNotReused(load_timing_info, |
| 4247 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4248 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4249 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4250 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4251 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4252 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4253 | |
| 4254 | std::string response_data; |
| 4255 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4256 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4257 | } |
| 4258 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4259 | // Verifies that a session which races and wins against the owning transaction |
| 4260 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4261 | // Regression test for crbug.com/334413. |
| 4262 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4263 | HttpRequestInfo request; |
| 4264 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4265 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4266 | request.load_flags = 0; |
| 4267 | |
| 4268 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4269 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4270 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4271 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4272 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4273 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4274 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4275 | scoped_ptr<SpdyFrame> req( |
| 4276 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4277 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4278 | |
| 4279 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4280 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4281 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4282 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4283 | }; |
| 4284 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4285 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4286 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4287 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4288 | |
| 4289 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4290 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4292 | |
| 4293 | TestCompletionCallback callback1; |
| 4294 | |
| 4295 | scoped_ptr<HttpTransaction> trans( |
| 4296 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4297 | |
| 4298 | // Stall the hostname resolution begun by the transaction. |
| 4299 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4300 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4301 | |
| 4302 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4303 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4304 | |
| 4305 | // Race a session to the proxy, which completes first. |
| 4306 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4307 | SpdySessionKey key( |
| 4308 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4309 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4310 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4311 | |
| 4312 | // Unstall the resolution begun by the transaction. |
| 4313 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4314 | session_deps_.host_resolver->ResolveAllPending(); |
| 4315 | |
| 4316 | EXPECT_FALSE(callback1.have_result()); |
| 4317 | rv = callback1.WaitForResult(); |
| 4318 | EXPECT_EQ(OK, rv); |
| 4319 | |
| 4320 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4321 | ASSERT_TRUE(response != NULL); |
| 4322 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4323 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4324 | |
| 4325 | std::string response_data; |
| 4326 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4327 | EXPECT_EQ(kUploadData, response_data); |
| 4328 | } |
| 4329 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4330 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4331 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4332 | HttpRequestInfo request; |
| 4333 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4334 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4335 | request.load_flags = 0; |
| 4336 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4337 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4338 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4339 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4340 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4341 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4342 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4343 | // The first request will be a bare GET, the second request will be a |
| 4344 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4345 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4346 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4347 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4348 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4349 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4350 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4351 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4352 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4353 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4354 | false, |
| 4355 | 3, |
| 4356 | LOWEST, |
| 4357 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4358 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4359 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4360 | }; |
| 4361 | |
| 4362 | // The first response is a 407 proxy authentication challenge, and the second |
| 4363 | // response will be a 200 response since the second request includes a valid |
| 4364 | // Authorization header. |
| 4365 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4366 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4367 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4368 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4369 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4370 | "407 Proxy Authentication Required", |
| 4371 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4372 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4373 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4374 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4375 | scoped_ptr<SpdyFrame> resp_data( |
| 4376 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4377 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4378 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4379 | CreateMockRead(*resp_authentication, 1), |
| 4380 | CreateMockRead(*body_authentication, 2), |
| 4381 | CreateMockRead(*resp_data, 4), |
| 4382 | CreateMockRead(*body_data, 5), |
| 4383 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4384 | }; |
| 4385 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4386 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4387 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4389 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4390 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4391 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4394 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4395 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4396 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4397 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4399 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4401 | |
| 4402 | rv = callback1.WaitForResult(); |
| 4403 | EXPECT_EQ(OK, rv); |
| 4404 | |
| 4405 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4406 | |
| 4407 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4408 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4409 | EXPECT_EQ(407, response->headers->response_code()); |
| 4410 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4411 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4413 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4415 | rv = trans->RestartWithAuth( |
| 4416 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4417 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4418 | |
| 4419 | rv = callback2.WaitForResult(); |
| 4420 | EXPECT_EQ(OK, rv); |
| 4421 | |
| 4422 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4423 | |
| 4424 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4425 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4426 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4427 | // The password prompt info should not be set. |
| 4428 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4429 | } |
| 4430 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4431 | // 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] | 4432 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4433 | HttpRequestInfo request; |
| 4434 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4435 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4436 | request.load_flags = 0; |
| 4437 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4438 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4439 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4440 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4441 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4442 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4443 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4444 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4446 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4447 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4448 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4449 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4450 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4451 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4452 | const char get[] = |
| 4453 | "GET / HTTP/1.1\r\n" |
| 4454 | "Host: www.example.org\r\n" |
| 4455 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4456 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4457 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4458 | scoped_ptr<SpdyFrame> conn_resp( |
| 4459 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4460 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4461 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4462 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4463 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4464 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4465 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4466 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4467 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4468 | |
| 4469 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4470 | CreateMockWrite(*connect, 0), |
| 4471 | CreateMockWrite(*wrapped_get, 2), |
| 4472 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4473 | }; |
| 4474 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4475 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4476 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4477 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4478 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4479 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4480 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4481 | }; |
| 4482 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4483 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4484 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4485 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4486 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4487 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4488 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4490 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4493 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4495 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4496 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4497 | |
| 4498 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4499 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4500 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4501 | LoadTimingInfo load_timing_info; |
| 4502 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4503 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4504 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4505 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4506 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4507 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4508 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4509 | |
| 4510 | std::string response_data; |
| 4511 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4512 | EXPECT_EQ("1234567890", response_data); |
| 4513 | } |
| 4514 | |
| 4515 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4516 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4517 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4518 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4519 | HttpRequestInfo request; |
| 4520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4521 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4522 | request.load_flags = 0; |
| 4523 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4524 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4525 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4526 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4527 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4528 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4529 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4530 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4531 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4532 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4533 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4534 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4535 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4536 | // fetch https://www.example.org/ via SPDY |
| 4537 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4538 | scoped_ptr<SpdyFrame> get( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4539 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4540 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4541 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4542 | scoped_ptr<SpdyFrame> conn_resp( |
| 4543 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4544 | scoped_ptr<SpdyFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4545 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4546 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4547 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4548 | scoped_ptr<SpdyFrame> body(spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4549 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4550 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4551 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4552 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4553 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4554 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4555 | |
| 4556 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4557 | CreateMockWrite(*connect, 0), |
| 4558 | CreateMockWrite(*wrapped_get, 2), |
| 4559 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4560 | CreateMockWrite(*window_update_body, 7), |
| 4561 | }; |
| 4562 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4563 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4564 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4565 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4566 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4567 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4568 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4569 | }; |
| 4570 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4571 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4572 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4573 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4574 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4575 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4576 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4578 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4579 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4582 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4584 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4586 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4587 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4588 | base::MessageLoop::current()->RunUntilIdle(); |
| 4589 | // Now allow the read of the response to complete. |
| 4590 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4591 | rv = callback1.WaitForResult(); |
| 4592 | EXPECT_EQ(OK, rv); |
| 4593 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4594 | LoadTimingInfo load_timing_info; |
| 4595 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4596 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4597 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4598 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4599 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4600 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4601 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4602 | |
| 4603 | std::string response_data; |
| 4604 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4605 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4609 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4610 | HttpRequestInfo request; |
| 4611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4612 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4613 | request.load_flags = 0; |
| 4614 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4615 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4616 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4617 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4618 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4619 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4620 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4621 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4622 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4623 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4624 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4625 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4627 | scoped_ptr<SpdyFrame> get( |
| 4628 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4629 | |
| 4630 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4631 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4632 | }; |
| 4633 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4634 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4635 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4636 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4637 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4638 | }; |
| 4639 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4640 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4641 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4642 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4643 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4644 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4645 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4647 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4648 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4651 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4653 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4654 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4655 | |
| 4656 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4657 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4658 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4659 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4660 | } |
| 4661 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4662 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4663 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4664 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4665 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4666 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4667 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4668 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4669 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4670 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4671 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4672 | |
| 4673 | HttpRequestInfo request1; |
| 4674 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4675 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4676 | request1.load_flags = 0; |
| 4677 | |
| 4678 | HttpRequestInfo request2; |
| 4679 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4680 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4681 | request2.load_flags = 0; |
| 4682 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4683 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4684 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4685 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4686 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4687 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4688 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4689 | // Fetch https://www.example.org/ via HTTP. |
| 4690 | const char get1[] = |
| 4691 | "GET / HTTP/1.1\r\n" |
| 4692 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4693 | "Connection: keep-alive\r\n\r\n"; |
| 4694 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4695 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4696 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4697 | "Content-Length: 1\r\n\r\n"; |
| 4698 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4699 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4700 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4701 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4702 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4703 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4704 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4705 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4706 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4707 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4708 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4709 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4710 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4711 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4712 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4713 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4714 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4715 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4716 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4717 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4718 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4719 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4720 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4721 | // Fetch https://mail.example.org/ via HTTP. |
| 4722 | const char get2[] = |
| 4723 | "GET / HTTP/1.1\r\n" |
| 4724 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4725 | "Connection: keep-alive\r\n\r\n"; |
| 4726 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4727 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4728 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4729 | "Content-Length: 2\r\n\r\n"; |
| 4730 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4731 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4732 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4733 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4734 | |
| 4735 | MockWrite spdy_writes[] = { |
| 4736 | CreateMockWrite(*connect1, 0), |
| 4737 | CreateMockWrite(*wrapped_get1, 2), |
| 4738 | CreateMockWrite(*connect2, 5), |
| 4739 | CreateMockWrite(*wrapped_get2, 7), |
| 4740 | }; |
| 4741 | |
| 4742 | MockRead spdy_reads[] = { |
| 4743 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4744 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4745 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4746 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4747 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4748 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4749 | MockRead(ASYNC, 0, 10), |
| 4750 | }; |
| 4751 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4752 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4753 | arraysize(spdy_writes)); |
| 4754 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4755 | |
| 4756 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4757 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4759 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4761 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4763 | |
| 4764 | TestCompletionCallback callback; |
| 4765 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4766 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4767 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4768 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4769 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4770 | |
| 4771 | LoadTimingInfo load_timing_info; |
| 4772 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4773 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4774 | |
| 4775 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4776 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4777 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4778 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4779 | |
| 4780 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4781 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4782 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4783 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4784 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4785 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4786 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4787 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4788 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4789 | |
| 4790 | LoadTimingInfo load_timing_info2; |
| 4791 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4792 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4793 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4794 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4795 | |
| 4796 | // The requests should have different IDs, since they each are using their own |
| 4797 | // separate stream. |
| 4798 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4799 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4800 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4801 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4805 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4806 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4807 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4808 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4809 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4810 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4811 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4812 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4813 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4814 | |
| 4815 | HttpRequestInfo request1; |
| 4816 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4817 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4818 | request1.load_flags = 0; |
| 4819 | |
| 4820 | HttpRequestInfo request2; |
| 4821 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4822 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4823 | request2.load_flags = 0; |
| 4824 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4825 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4826 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4827 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4828 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4829 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4830 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4831 | // Fetch https://www.example.org/ via HTTP. |
| 4832 | const char get1[] = |
| 4833 | "GET / HTTP/1.1\r\n" |
| 4834 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4835 | "Connection: keep-alive\r\n\r\n"; |
| 4836 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4837 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4838 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4839 | "Content-Length: 1\r\n\r\n"; |
| 4840 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4841 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4842 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4843 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4844 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4845 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4846 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4847 | // Fetch https://www.example.org/2 via HTTP. |
| 4848 | const char get2[] = |
| 4849 | "GET /2 HTTP/1.1\r\n" |
| 4850 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4851 | "Connection: keep-alive\r\n\r\n"; |
| 4852 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4853 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4854 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4855 | "Content-Length: 2\r\n\r\n"; |
| 4856 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4857 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4858 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4859 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4860 | |
| 4861 | MockWrite spdy_writes[] = { |
| 4862 | CreateMockWrite(*connect1, 0), |
| 4863 | CreateMockWrite(*wrapped_get1, 2), |
| 4864 | CreateMockWrite(*wrapped_get2, 5), |
| 4865 | }; |
| 4866 | |
| 4867 | MockRead spdy_reads[] = { |
| 4868 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4869 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4870 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4871 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4872 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4873 | MockRead(ASYNC, 0, 8), |
| 4874 | }; |
| 4875 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4876 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4877 | arraysize(spdy_writes)); |
| 4878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4879 | |
| 4880 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4881 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4883 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4885 | |
| 4886 | TestCompletionCallback callback; |
| 4887 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4888 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4889 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4890 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4891 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4892 | |
| 4893 | rv = callback.WaitForResult(); |
| 4894 | EXPECT_EQ(OK, rv); |
| 4895 | |
| 4896 | LoadTimingInfo load_timing_info; |
| 4897 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4898 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4899 | |
| 4900 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4901 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4902 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4903 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4904 | |
| 4905 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4906 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4907 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4908 | trans.reset(); |
| 4909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4910 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4912 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4913 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4914 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4915 | rv = callback.WaitForResult(); |
| 4916 | EXPECT_EQ(OK, rv); |
| 4917 | |
| 4918 | LoadTimingInfo load_timing_info2; |
| 4919 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4920 | TestLoadTimingReused(load_timing_info2); |
| 4921 | |
| 4922 | // The requests should have the same ID. |
| 4923 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4924 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4925 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4929 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4930 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4931 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4932 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4933 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4934 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4935 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4936 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4937 | |
| 4938 | HttpRequestInfo request1; |
| 4939 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4940 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4941 | request1.load_flags = 0; |
| 4942 | |
| 4943 | HttpRequestInfo request2; |
| 4944 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4945 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4946 | request2.load_flags = 0; |
| 4947 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4948 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4949 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4951 | scoped_ptr<SpdyFrame> get1( |
| 4952 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4953 | scoped_ptr<SpdyFrame> get_resp1( |
| 4954 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4955 | scoped_ptr<SpdyFrame> body1( |
| 4956 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4957 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4958 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4959 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4960 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4961 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4962 | scoped_ptr<SpdyFrame> get2( |
| 4963 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4964 | scoped_ptr<SpdyFrame> get_resp2( |
| 4965 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4966 | scoped_ptr<SpdyFrame> body2( |
| 4967 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4968 | |
| 4969 | MockWrite spdy_writes[] = { |
| 4970 | CreateMockWrite(*get1, 0), |
| 4971 | CreateMockWrite(*get2, 3), |
| 4972 | }; |
| 4973 | |
| 4974 | MockRead spdy_reads[] = { |
| 4975 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4976 | CreateMockRead(*body1, 2, ASYNC), |
| 4977 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4978 | CreateMockRead(*body2, 5, ASYNC), |
| 4979 | MockRead(ASYNC, 0, 6), |
| 4980 | }; |
| 4981 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4982 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4983 | arraysize(spdy_writes)); |
| 4984 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4985 | |
| 4986 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4987 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4989 | |
| 4990 | TestCompletionCallback callback; |
| 4991 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4994 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4995 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4996 | |
| 4997 | LoadTimingInfo load_timing_info; |
| 4998 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4999 | TestLoadTimingNotReused(load_timing_info, |
| 5000 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5001 | |
| 5002 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5003 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5004 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5005 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5006 | |
| 5007 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5008 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5009 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5010 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5011 | // Delete the first request, so the second one can reuse the socket. |
| 5012 | trans.reset(); |
| 5013 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5014 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5016 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5017 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5018 | |
| 5019 | LoadTimingInfo load_timing_info2; |
| 5020 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5021 | TestLoadTimingReused(load_timing_info2); |
| 5022 | |
| 5023 | // The requests should have the same ID. |
| 5024 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5025 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5026 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5027 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5028 | } |
| 5029 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5030 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5031 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5032 | HttpRequestInfo request; |
| 5033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5034 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5035 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5036 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5037 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5038 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5039 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5040 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5041 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5042 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5043 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5044 | // Since we have proxy, should use full url |
| 5045 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5046 | MockWrite( |
| 5047 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5048 | "Host: www.example.org\r\n" |
| 5049 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5050 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5051 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5052 | // be issuing -- the final header line contains the credentials. |
| 5053 | MockWrite( |
| 5054 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5055 | "Host: www.example.org\r\n" |
| 5056 | "Proxy-Connection: keep-alive\r\n" |
| 5057 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5058 | }; |
| 5059 | |
| 5060 | // The proxy responds to the GET with a 407, using a persistent |
| 5061 | // connection. |
| 5062 | MockRead data_reads1[] = { |
| 5063 | // No credentials. |
| 5064 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5065 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5066 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5067 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5068 | |
| 5069 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5070 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5071 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5073 | }; |
| 5074 | |
| 5075 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5076 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5077 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5078 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5081 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5082 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5083 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5084 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5086 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5087 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5088 | |
| 5089 | rv = callback1.WaitForResult(); |
| 5090 | EXPECT_EQ(OK, rv); |
| 5091 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5092 | LoadTimingInfo load_timing_info; |
| 5093 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5094 | TestLoadTimingNotReused(load_timing_info, |
| 5095 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5096 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5098 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5099 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5100 | EXPECT_EQ(407, response->headers->response_code()); |
| 5101 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5102 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5104 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5106 | rv = trans->RestartWithAuth( |
| 5107 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5108 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5109 | |
| 5110 | rv = callback2.WaitForResult(); |
| 5111 | EXPECT_EQ(OK, rv); |
| 5112 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5113 | load_timing_info = LoadTimingInfo(); |
| 5114 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5115 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5116 | TestLoadTimingReused(load_timing_info); |
| 5117 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5118 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5119 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5120 | |
| 5121 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5122 | EXPECT_EQ(200, response->headers->response_code()); |
| 5123 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5124 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5125 | |
| 5126 | // The password prompt info should not be set. |
| 5127 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5128 | } |
| 5129 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5130 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5131 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5132 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5134 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5135 | request.load_flags = 0; |
| 5136 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5137 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5138 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5139 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5140 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5141 | // Since we have proxy, should try to establish tunnel. |
| 5142 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5143 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5144 | "Host: www.example.org:443\r\n" |
| 5145 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5146 | }; |
| 5147 | |
| 5148 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 5149 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5150 | // No response body because the test stops reading here. |
| 5151 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5152 | }; |
| 5153 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5154 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5155 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5156 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5158 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5159 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5160 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5161 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5163 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5165 | |
| 5166 | rv = callback.WaitForResult(); |
| 5167 | EXPECT_EQ(expected_status, rv); |
| 5168 | } |
| 5169 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5170 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5171 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5172 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5173 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5174 | } |
| 5175 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5176 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5177 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5178 | } |
| 5179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5180 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5181 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5182 | } |
| 5183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5184 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5185 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5186 | } |
| 5187 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5188 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5189 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5190 | } |
| 5191 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5192 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5193 | ConnectStatusHelper( |
| 5194 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5195 | } |
| 5196 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5197 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5198 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5199 | } |
| 5200 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5201 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5202 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5203 | } |
| 5204 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5205 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5206 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5207 | } |
| 5208 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5209 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5210 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5211 | } |
| 5212 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5213 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5214 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5215 | } |
| 5216 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5217 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5218 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5219 | } |
| 5220 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5221 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5222 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5223 | } |
| 5224 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5225 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5226 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5227 | } |
| 5228 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5229 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5230 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5231 | } |
| 5232 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5233 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5234 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5235 | } |
| 5236 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5237 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5238 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5239 | } |
| 5240 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5241 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5242 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5243 | } |
| 5244 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5245 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5246 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5247 | } |
| 5248 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5249 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5250 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5251 | } |
| 5252 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5253 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5254 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5255 | } |
| 5256 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5257 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5258 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5259 | } |
| 5260 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5261 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5262 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5263 | } |
| 5264 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5265 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5266 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5267 | } |
| 5268 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5269 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5270 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5271 | } |
| 5272 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5273 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5274 | ConnectStatusHelperWithExpectedStatus( |
| 5275 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5276 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5277 | } |
| 5278 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5279 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5280 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5281 | } |
| 5282 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5283 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5284 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5285 | } |
| 5286 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5287 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5288 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5289 | } |
| 5290 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5291 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5292 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5293 | } |
| 5294 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5295 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5296 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5297 | } |
| 5298 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5299 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5300 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5301 | } |
| 5302 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5303 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5304 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5305 | } |
| 5306 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5307 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5308 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5309 | } |
| 5310 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5311 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5312 | ConnectStatusHelper( |
| 5313 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5314 | } |
| 5315 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5316 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5317 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5318 | } |
| 5319 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5320 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5321 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5322 | } |
| 5323 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5324 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5325 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5326 | } |
| 5327 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5328 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5329 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5330 | } |
| 5331 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5332 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5333 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5334 | } |
| 5335 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5336 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5337 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5338 | } |
| 5339 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5340 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5341 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5342 | } |
| 5343 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5344 | // Test the flow when both the proxy server AND origin server require |
| 5345 | // authentication. Again, this uses basic auth for both since that is |
| 5346 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5347 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5348 | HttpRequestInfo request; |
| 5349 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5350 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5351 | request.load_flags = 0; |
| 5352 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5353 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5354 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5355 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5356 | |
| 5357 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5358 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5359 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5360 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5361 | MockWrite( |
| 5362 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5363 | "Host: www.example.org\r\n" |
| 5364 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5365 | }; |
| 5366 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5367 | MockRead data_reads1[] = { |
| 5368 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5369 | // Give a couple authenticate options (only the middle one is actually |
| 5370 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5371 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5372 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5373 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5374 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5375 | // Large content-length -- won't matter, as connection will be reset. |
| 5376 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5377 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5378 | }; |
| 5379 | |
| 5380 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5381 | // request we should be issuing -- the final header line contains the |
| 5382 | // proxy's credentials. |
| 5383 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5384 | MockWrite( |
| 5385 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5386 | "Host: www.example.org\r\n" |
| 5387 | "Proxy-Connection: keep-alive\r\n" |
| 5388 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5389 | }; |
| 5390 | |
| 5391 | // Now the proxy server lets the request pass through to origin server. |
| 5392 | // The origin server responds with a 401. |
| 5393 | MockRead data_reads2[] = { |
| 5394 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5395 | // Note: We are using the same realm-name as the proxy server. This is |
| 5396 | // completely valid, as realms are unique across hosts. |
| 5397 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5398 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5399 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5400 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5401 | }; |
| 5402 | |
| 5403 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5404 | // the credentials for both the proxy and origin server. |
| 5405 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5406 | MockWrite( |
| 5407 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5408 | "Host: www.example.org\r\n" |
| 5409 | "Proxy-Connection: keep-alive\r\n" |
| 5410 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5411 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5412 | }; |
| 5413 | |
| 5414 | // Lastly we get the desired content. |
| 5415 | MockRead data_reads3[] = { |
| 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] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5420 | }; |
| 5421 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5422 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5423 | data_writes1, arraysize(data_writes1)); |
| 5424 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5425 | data_writes2, arraysize(data_writes2)); |
| 5426 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5427 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5428 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5430 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5432 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5434 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5436 | |
| 5437 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5438 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5439 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5440 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5441 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5442 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5444 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5446 | rv = trans->RestartWithAuth( |
| 5447 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5448 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5449 | |
| 5450 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5451 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5452 | |
| 5453 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5454 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5455 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5457 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5459 | rv = trans->RestartWithAuth( |
| 5460 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5461 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5462 | |
| 5463 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5464 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5465 | |
| 5466 | response = trans->GetResponseInfo(); |
| 5467 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5468 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5469 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5470 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5471 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5472 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5473 | // authorization headers. |
| 5474 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5475 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5476 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5477 | // bytes in the debugger. |
| 5478 | |
| 5479 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5480 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5481 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5482 | request.method = "GET"; |
| 5483 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5484 | |
| 5485 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5486 | // to other auth schemes. |
| 5487 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5488 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5489 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5490 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5491 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5492 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5493 | MockWrite data_writes1[] = { |
| 5494 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5495 | "Host: 172.22.68.17\r\n" |
| 5496 | "Connection: keep-alive\r\n\r\n"), |
| 5497 | }; |
| 5498 | |
| 5499 | MockRead data_reads1[] = { |
| 5500 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5501 | // Negotiate and NTLM are often requested together. However, we only want |
| 5502 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5503 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5504 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5505 | MockRead("Connection: close\r\n"), |
| 5506 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5507 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5508 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5509 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5510 | }; |
| 5511 | |
| 5512 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5513 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5514 | // request we should be issuing -- the final header line contains a Type |
| 5515 | // 1 message. |
| 5516 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5517 | "Host: 172.22.68.17\r\n" |
| 5518 | "Connection: keep-alive\r\n" |
| 5519 | "Authorization: NTLM " |
| 5520 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5521 | |
| 5522 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5523 | // (the credentials for the origin server). The second request continues |
| 5524 | // on the same connection. |
| 5525 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5526 | "Host: 172.22.68.17\r\n" |
| 5527 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5528 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5529 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5530 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5531 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5532 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5533 | }; |
| 5534 | |
| 5535 | MockRead data_reads2[] = { |
| 5536 | // The origin server responds with a Type 2 message. |
| 5537 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5538 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5539 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5540 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5541 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5542 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5543 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5544 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5545 | "BtAAAAAAA=\r\n"), |
| 5546 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5547 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5548 | MockRead("You are not authorized to view this page\r\n"), |
| 5549 | |
| 5550 | // Lastly we get the desired content. |
| 5551 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5552 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5553 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5554 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5555 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5556 | }; |
| 5557 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5559 | data_writes1, arraysize(data_writes1)); |
| 5560 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5561 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5562 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5565 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5566 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5567 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5568 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5570 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5571 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5572 | |
| 5573 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5574 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5575 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5576 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5577 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5578 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5579 | ASSERT_FALSE(response == NULL); |
| 5580 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5582 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5583 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5584 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5585 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5587 | |
| 5588 | rv = callback2.WaitForResult(); |
| 5589 | EXPECT_EQ(OK, rv); |
| 5590 | |
| 5591 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5592 | |
| 5593 | response = trans->GetResponseInfo(); |
| 5594 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5595 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5597 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5599 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5601 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5602 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5603 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5604 | |
| 5605 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5606 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5607 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5608 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5609 | } |
| 5610 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5611 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5612 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5613 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5614 | request.method = "GET"; |
| 5615 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5616 | request.load_flags = 0; |
| 5617 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5618 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5619 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5620 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5621 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5622 | MockWrite data_writes1[] = { |
| 5623 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5624 | "Host: 172.22.68.17\r\n" |
| 5625 | "Connection: keep-alive\r\n\r\n"), |
| 5626 | }; |
| 5627 | |
| 5628 | MockRead data_reads1[] = { |
| 5629 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5630 | // Negotiate and NTLM are often requested together. However, we only want |
| 5631 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5632 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5633 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5634 | MockRead("Connection: close\r\n"), |
| 5635 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5636 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5637 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5638 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5639 | }; |
| 5640 | |
| 5641 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5642 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5643 | // request we should be issuing -- the final header line contains a Type |
| 5644 | // 1 message. |
| 5645 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5646 | "Host: 172.22.68.17\r\n" |
| 5647 | "Connection: keep-alive\r\n" |
| 5648 | "Authorization: NTLM " |
| 5649 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5650 | |
| 5651 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5652 | // (the credentials for the origin server). The second request continues |
| 5653 | // on the same connection. |
| 5654 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5655 | "Host: 172.22.68.17\r\n" |
| 5656 | "Connection: keep-alive\r\n" |
| 5657 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5658 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5659 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5660 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5661 | "4Ww7b7E=\r\n\r\n"), |
| 5662 | }; |
| 5663 | |
| 5664 | MockRead data_reads2[] = { |
| 5665 | // The origin server responds with a Type 2 message. |
| 5666 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5667 | MockRead("WWW-Authenticate: NTLM " |
| 5668 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5669 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5670 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5671 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5672 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5673 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5674 | "BtAAAAAAA=\r\n"), |
| 5675 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5676 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5677 | MockRead("You are not authorized to view this page\r\n"), |
| 5678 | |
| 5679 | // Wrong password. |
| 5680 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5681 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5682 | MockRead("Connection: close\r\n"), |
| 5683 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5684 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5685 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5686 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5687 | }; |
| 5688 | |
| 5689 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5690 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5691 | // request we should be issuing -- the final header line contains a Type |
| 5692 | // 1 message. |
| 5693 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5694 | "Host: 172.22.68.17\r\n" |
| 5695 | "Connection: keep-alive\r\n" |
| 5696 | "Authorization: NTLM " |
| 5697 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5698 | |
| 5699 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5700 | // (the credentials for the origin server). The second request continues |
| 5701 | // on the same connection. |
| 5702 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5703 | "Host: 172.22.68.17\r\n" |
| 5704 | "Connection: keep-alive\r\n" |
| 5705 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5706 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5707 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5708 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5709 | "+4MUm7c=\r\n\r\n"), |
| 5710 | }; |
| 5711 | |
| 5712 | MockRead data_reads3[] = { |
| 5713 | // The origin server responds with a Type 2 message. |
| 5714 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5715 | MockRead("WWW-Authenticate: NTLM " |
| 5716 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5717 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5718 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5719 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5720 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5721 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5722 | "BtAAAAAAA=\r\n"), |
| 5723 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5724 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5725 | MockRead("You are not authorized to view this page\r\n"), |
| 5726 | |
| 5727 | // Lastly we get the desired content. |
| 5728 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5729 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5730 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5731 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5733 | }; |
| 5734 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5735 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5736 | data_writes1, arraysize(data_writes1)); |
| 5737 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5738 | data_writes2, arraysize(data_writes2)); |
| 5739 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5740 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5741 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5742 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5743 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5744 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5745 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5746 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5747 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5748 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5750 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5751 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5752 | |
| 5753 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5754 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5755 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5756 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5757 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5758 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5759 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5760 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5762 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5763 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5764 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5765 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5766 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5767 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5768 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5769 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5770 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5771 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5772 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5773 | TestCompletionCallback callback3; |
| 5774 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5775 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5776 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5777 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5778 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5779 | |
| 5780 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5781 | ASSERT_FALSE(response == NULL); |
| 5782 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5784 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5785 | |
| 5786 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5787 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5788 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5789 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5790 | |
| 5791 | rv = callback4.WaitForResult(); |
| 5792 | EXPECT_EQ(OK, rv); |
| 5793 | |
| 5794 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5796 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5797 | |
| 5798 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5799 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5801 | |
| 5802 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5803 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5804 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5805 | response = trans->GetResponseInfo(); |
| 5806 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5807 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5808 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5809 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5810 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5811 | // Test reading a server response which has only headers, and no body. |
| 5812 | // After some maximum number of bytes is consumed, the transaction should |
| 5813 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5814 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5815 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5817 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5818 | request.load_flags = 0; |
| 5819 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5820 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5821 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5822 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5823 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5824 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5825 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5826 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5827 | |
| 5828 | MockRead data_reads[] = { |
| 5829 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5830 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5831 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5832 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5833 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5834 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5837 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5839 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5840 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5841 | |
| 5842 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5843 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5844 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5845 | |
| 5846 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5847 | // establish tunnel. |
| 5848 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5849 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5850 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5851 | HttpRequestInfo request; |
| 5852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5853 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5854 | request.load_flags = 0; |
| 5855 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5856 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5857 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5858 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5859 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5860 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5861 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5863 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5864 | // Since we have proxy, should try to establish tunnel. |
| 5865 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5866 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5867 | "Host: www.example.org:443\r\n" |
| 5868 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5869 | }; |
| 5870 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5871 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5872 | // connection. Usually a proxy would return 501 (not implemented), |
| 5873 | // or 200 (tunnel established). |
| 5874 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame^] | 5875 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5876 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5877 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5878 | }; |
| 5879 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5880 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5881 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5882 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5884 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5886 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5887 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5888 | |
| 5889 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5890 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5891 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5892 | // Empty the current queue. This is necessary because idle sockets are |
| 5893 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5894 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5895 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5896 | // We now check to make sure the TCPClientSocket was not added back to |
| 5897 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5898 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5899 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5900 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5901 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5902 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5903 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5904 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5905 | // 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] | 5906 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5907 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5909 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5910 | request.load_flags = 0; |
| 5911 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5912 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5913 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5914 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5915 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5916 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5917 | MockRead data_reads[] = { |
| 5918 | // A part of the response body is received with the response headers. |
| 5919 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5920 | // The rest of the response body is received in two parts. |
| 5921 | MockRead("lo"), |
| 5922 | MockRead(" world"), |
| 5923 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5925 | }; |
| 5926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5930 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5932 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5933 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5934 | |
| 5935 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5936 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5937 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5938 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5939 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5940 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5941 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5942 | std::string status_line = response->headers->GetStatusLine(); |
| 5943 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5944 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5945 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5946 | |
| 5947 | std::string response_data; |
| 5948 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5949 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5950 | EXPECT_EQ("hello world", response_data); |
| 5951 | |
| 5952 | // Empty the current queue. This is necessary because idle sockets are |
| 5953 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5954 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5955 | |
| 5956 | // 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] | 5957 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5958 | } |
| 5959 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5960 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5961 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5962 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5963 | HttpRequestInfo request; |
| 5964 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5965 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5966 | request.load_flags = 0; |
| 5967 | |
| 5968 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5969 | MockWrite( |
| 5970 | "GET / HTTP/1.1\r\n" |
| 5971 | "Host: www.example.org\r\n" |
| 5972 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5973 | }; |
| 5974 | |
| 5975 | MockRead data_reads[] = { |
| 5976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5977 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5978 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5980 | }; |
| 5981 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5982 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5984 | |
| 5985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5986 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5989 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5990 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5991 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5995 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5996 | |
| 5997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5998 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5999 | |
| 6000 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6001 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6002 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6003 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6004 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6005 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6006 | |
| 6007 | std::string response_data; |
| 6008 | rv = ReadTransaction(trans.get(), &response_data); |
| 6009 | EXPECT_EQ(OK, rv); |
| 6010 | EXPECT_EQ("hello world", response_data); |
| 6011 | |
| 6012 | // Empty the current queue. This is necessary because idle sockets are |
| 6013 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6014 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6015 | |
| 6016 | // 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] | 6017 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6018 | } |
| 6019 | |
| 6020 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6021 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6022 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6023 | HttpRequestInfo request; |
| 6024 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6025 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6026 | request.load_flags = 0; |
| 6027 | |
| 6028 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6029 | MockWrite( |
| 6030 | "GET / HTTP/1.1\r\n" |
| 6031 | "Host: www.example.org\r\n" |
| 6032 | "Connection: keep-alive\r\n\r\n"), |
| 6033 | MockWrite( |
| 6034 | "GET / HTTP/1.1\r\n" |
| 6035 | "Host: www.example.org\r\n" |
| 6036 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6037 | }; |
| 6038 | |
| 6039 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6040 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6041 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6042 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6043 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6044 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6046 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6047 | |
| 6048 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6049 | data_writes, arraysize(data_writes)); |
| 6050 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6051 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6052 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6053 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6055 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6056 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6057 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6058 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6061 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6062 | |
| 6063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6064 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6065 | |
| 6066 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6067 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6068 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6069 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6070 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6071 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6072 | |
| 6073 | std::string response_data; |
| 6074 | rv = ReadTransaction(trans.get(), &response_data); |
| 6075 | EXPECT_EQ(OK, rv); |
| 6076 | EXPECT_EQ("hello world", response_data); |
| 6077 | |
| 6078 | // Empty the current queue. This is necessary because idle sockets are |
| 6079 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6080 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6081 | |
| 6082 | // 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] | 6083 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6084 | |
| 6085 | // Now start the second transaction, which should reuse the previous socket. |
| 6086 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6087 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6089 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6090 | |
| 6091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6092 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6093 | |
| 6094 | response = trans->GetResponseInfo(); |
| 6095 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6096 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6097 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6098 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6099 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6100 | |
| 6101 | rv = ReadTransaction(trans.get(), &response_data); |
| 6102 | EXPECT_EQ(OK, rv); |
| 6103 | EXPECT_EQ("hello world", response_data); |
| 6104 | |
| 6105 | // Empty the current queue. This is necessary because idle sockets are |
| 6106 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6107 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6108 | |
| 6109 | // 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] | 6110 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6111 | } |
| 6112 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6113 | // Make sure that we recycle a socket after a zero-length response. |
| 6114 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6115 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6116 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6118 | request.url = GURL( |
| 6119 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6120 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6121 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6122 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6123 | request.load_flags = 0; |
| 6124 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6125 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6126 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6127 | MockRead data_reads[] = { |
| 6128 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6129 | "Content-Length: 0\r\n" |
| 6130 | "Content-Type: text/html\r\n\r\n"), |
| 6131 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6132 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6133 | }; |
| 6134 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6135 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6137 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6138 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6139 | // them. |
| 6140 | scoped_ptr<HttpTransaction> trans( |
| 6141 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6143 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6145 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6147 | |
| 6148 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6149 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6150 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6151 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6152 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6153 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6154 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6155 | std::string status_line = response->headers->GetStatusLine(); |
| 6156 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6157 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6158 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6159 | |
| 6160 | std::string response_data; |
| 6161 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6162 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6163 | EXPECT_EQ("", response_data); |
| 6164 | |
| 6165 | // Empty the current queue. This is necessary because idle sockets are |
| 6166 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6167 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6168 | |
| 6169 | // 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] | 6170 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6171 | } |
| 6172 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6173 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6174 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6175 | element_readers.push_back( |
| 6176 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6177 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6178 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6179 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6180 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6181 | // after use. |
| 6182 | request[0].method = "GET"; |
| 6183 | request[0].url = GURL("http://www.google.com/"); |
| 6184 | request[0].load_flags = 0; |
| 6185 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6186 | // transaction 1. The first attempts fails when writing the POST data. |
| 6187 | // This causes the transaction to retry with a new socket. The second |
| 6188 | // attempt succeeds. |
| 6189 | request[1].method = "POST"; |
| 6190 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6191 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6192 | request[1].load_flags = 0; |
| 6193 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6194 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6195 | |
| 6196 | // The first socket is used for transaction 1 and the first attempt of |
| 6197 | // transaction 2. |
| 6198 | |
| 6199 | // The response of transaction 1. |
| 6200 | MockRead data_reads1[] = { |
| 6201 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6202 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6203 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6204 | }; |
| 6205 | // The mock write results of transaction 1 and the first attempt of |
| 6206 | // transaction 2. |
| 6207 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6208 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6209 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6210 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6211 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6212 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6213 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6214 | |
| 6215 | // The second socket is used for the second attempt of transaction 2. |
| 6216 | |
| 6217 | // The response of transaction 2. |
| 6218 | MockRead data_reads2[] = { |
| 6219 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6220 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6221 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6222 | }; |
| 6223 | // The mock write results of the second attempt of transaction 2. |
| 6224 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6225 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6226 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6227 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6228 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6229 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6230 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6232 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6233 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6234 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6235 | "hello world", "welcome" |
| 6236 | }; |
| 6237 | |
| 6238 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6239 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6242 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6244 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6245 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6246 | |
| 6247 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6248 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6249 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6250 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6251 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6252 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6253 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6254 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6255 | |
| 6256 | std::string response_data; |
| 6257 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6258 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6259 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6260 | } |
| 6261 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6262 | |
| 6263 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6264 | // 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] | 6265 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6266 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6267 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6268 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6269 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6270 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6271 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6272 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6273 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6274 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6275 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6276 | // The password contains an escaped character -- for this test to pass it |
| 6277 | // will need to be unescaped by HttpNetworkTransaction. |
| 6278 | EXPECT_EQ("b%40r", request.url.password()); |
| 6279 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6280 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6281 | MockWrite( |
| 6282 | "GET / HTTP/1.1\r\n" |
| 6283 | "Host: www.example.org\r\n" |
| 6284 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6285 | }; |
| 6286 | |
| 6287 | MockRead data_reads1[] = { |
| 6288 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6289 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6290 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6291 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6292 | }; |
| 6293 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6294 | // After the challenge above, the transaction will be restarted using the |
| 6295 | // identity from the url (foo, b@r) to answer the challenge. |
| 6296 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6297 | MockWrite( |
| 6298 | "GET / HTTP/1.1\r\n" |
| 6299 | "Host: www.example.org\r\n" |
| 6300 | "Connection: keep-alive\r\n" |
| 6301 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6302 | }; |
| 6303 | |
| 6304 | MockRead data_reads2[] = { |
| 6305 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6306 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6307 | MockRead(SYNCHRONOUS, OK), |
| 6308 | }; |
| 6309 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6310 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6311 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6312 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6313 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6315 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6317 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6318 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6320 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6321 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6322 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6323 | |
| 6324 | TestCompletionCallback callback2; |
| 6325 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6327 | rv = callback2.WaitForResult(); |
| 6328 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6329 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6330 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6332 | ASSERT_TRUE(response != NULL); |
| 6333 | |
| 6334 | // There is no challenge info, since the identity in URL worked. |
| 6335 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6336 | |
| 6337 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6338 | |
| 6339 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6340 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6341 | } |
| 6342 | |
| 6343 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6344 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6345 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6346 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6347 | HttpRequestInfo request; |
| 6348 | request.method = "GET"; |
| 6349 | // Note: the URL has a username:password in it. The password "baz" is |
| 6350 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6351 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6352 | |
| 6353 | request.load_flags = LOAD_NORMAL; |
| 6354 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6355 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6356 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6357 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6358 | |
| 6359 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6360 | MockWrite( |
| 6361 | "GET / HTTP/1.1\r\n" |
| 6362 | "Host: www.example.org\r\n" |
| 6363 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6364 | }; |
| 6365 | |
| 6366 | MockRead data_reads1[] = { |
| 6367 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6368 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6369 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6370 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6371 | }; |
| 6372 | |
| 6373 | // After the challenge above, the transaction will be restarted using the |
| 6374 | // identity from the url (foo, baz) to answer the challenge. |
| 6375 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6376 | MockWrite( |
| 6377 | "GET / HTTP/1.1\r\n" |
| 6378 | "Host: www.example.org\r\n" |
| 6379 | "Connection: keep-alive\r\n" |
| 6380 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6381 | }; |
| 6382 | |
| 6383 | MockRead data_reads2[] = { |
| 6384 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6385 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6386 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6387 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6388 | }; |
| 6389 | |
| 6390 | // After the challenge above, the transaction will be restarted using the |
| 6391 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6392 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6393 | MockWrite( |
| 6394 | "GET / HTTP/1.1\r\n" |
| 6395 | "Host: www.example.org\r\n" |
| 6396 | "Connection: keep-alive\r\n" |
| 6397 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6398 | }; |
| 6399 | |
| 6400 | MockRead data_reads3[] = { |
| 6401 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6402 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6403 | MockRead(SYNCHRONOUS, OK), |
| 6404 | }; |
| 6405 | |
| 6406 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6407 | data_writes1, arraysize(data_writes1)); |
| 6408 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6409 | data_writes2, arraysize(data_writes2)); |
| 6410 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6411 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6412 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6413 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6414 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6415 | |
| 6416 | TestCompletionCallback callback1; |
| 6417 | |
| 6418 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6419 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6420 | |
| 6421 | rv = callback1.WaitForResult(); |
| 6422 | EXPECT_EQ(OK, rv); |
| 6423 | |
| 6424 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6425 | TestCompletionCallback callback2; |
| 6426 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6427 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6428 | rv = callback2.WaitForResult(); |
| 6429 | EXPECT_EQ(OK, rv); |
| 6430 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6431 | |
| 6432 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6433 | ASSERT_TRUE(response != NULL); |
| 6434 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6435 | |
| 6436 | TestCompletionCallback callback3; |
| 6437 | rv = trans->RestartWithAuth( |
| 6438 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6440 | rv = callback3.WaitForResult(); |
| 6441 | EXPECT_EQ(OK, rv); |
| 6442 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6443 | |
| 6444 | response = trans->GetResponseInfo(); |
| 6445 | ASSERT_TRUE(response != NULL); |
| 6446 | |
| 6447 | // There is no challenge info, since the identity worked. |
| 6448 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6449 | |
| 6450 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6451 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6452 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6453 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6454 | } |
| 6455 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6456 | |
| 6457 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6458 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6459 | // from the URL should never be used. |
| 6460 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6461 | HttpRequestInfo request; |
| 6462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6463 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6464 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6465 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6466 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6467 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6468 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6469 | |
| 6470 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6471 | MockWrite( |
| 6472 | "GET / HTTP/1.1\r\n" |
| 6473 | "Host: www.example.org\r\n" |
| 6474 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6475 | }; |
| 6476 | |
| 6477 | MockRead data_reads1[] = { |
| 6478 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6479 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6480 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6481 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6482 | }; |
| 6483 | |
| 6484 | // After the challenge above, the transaction will be restarted using the |
| 6485 | // identity supplied by the user, not the one in the URL, to answer the |
| 6486 | // challenge. |
| 6487 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6488 | MockWrite( |
| 6489 | "GET / HTTP/1.1\r\n" |
| 6490 | "Host: www.example.org\r\n" |
| 6491 | "Connection: keep-alive\r\n" |
| 6492 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6493 | }; |
| 6494 | |
| 6495 | MockRead data_reads3[] = { |
| 6496 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6497 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6498 | MockRead(SYNCHRONOUS, OK), |
| 6499 | }; |
| 6500 | |
| 6501 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6502 | data_writes1, arraysize(data_writes1)); |
| 6503 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6504 | data_writes3, arraysize(data_writes3)); |
| 6505 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6506 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6507 | |
| 6508 | TestCompletionCallback callback1; |
| 6509 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6510 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6511 | rv = callback1.WaitForResult(); |
| 6512 | EXPECT_EQ(OK, rv); |
| 6513 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6514 | |
| 6515 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6516 | ASSERT_TRUE(response != NULL); |
| 6517 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6518 | |
| 6519 | TestCompletionCallback callback3; |
| 6520 | rv = trans->RestartWithAuth( |
| 6521 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6522 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6523 | rv = callback3.WaitForResult(); |
| 6524 | EXPECT_EQ(OK, rv); |
| 6525 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6526 | |
| 6527 | response = trans->GetResponseInfo(); |
| 6528 | ASSERT_TRUE(response != NULL); |
| 6529 | |
| 6530 | // There is no challenge info, since the identity worked. |
| 6531 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6532 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6533 | |
| 6534 | // Empty the current queue. |
| 6535 | base::MessageLoop::current()->RunUntilIdle(); |
| 6536 | } |
| 6537 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6538 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6539 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6540 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6541 | |
| 6542 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6543 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6544 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6545 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6546 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6547 | request.load_flags = 0; |
| 6548 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6549 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6550 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6551 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6552 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6553 | MockWrite( |
| 6554 | "GET /x/y/z HTTP/1.1\r\n" |
| 6555 | "Host: www.example.org\r\n" |
| 6556 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6557 | }; |
| 6558 | |
| 6559 | MockRead data_reads1[] = { |
| 6560 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6561 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6562 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6563 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6564 | }; |
| 6565 | |
| 6566 | // Resend with authorization (username=foo, password=bar) |
| 6567 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6568 | MockWrite( |
| 6569 | "GET /x/y/z HTTP/1.1\r\n" |
| 6570 | "Host: www.example.org\r\n" |
| 6571 | "Connection: keep-alive\r\n" |
| 6572 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6573 | }; |
| 6574 | |
| 6575 | // Sever accepts the authorization. |
| 6576 | MockRead data_reads2[] = { |
| 6577 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6578 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6579 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6580 | }; |
| 6581 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6582 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6583 | data_writes1, arraysize(data_writes1)); |
| 6584 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6585 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6587 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6589 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6591 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6592 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6593 | |
| 6594 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6595 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6596 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6597 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6598 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6599 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6601 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6603 | rv = trans->RestartWithAuth( |
| 6604 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6605 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6606 | |
| 6607 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6608 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6609 | |
| 6610 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6611 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6612 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6613 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6614 | } |
| 6615 | |
| 6616 | // ------------------------------------------------------------------------ |
| 6617 | |
| 6618 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6619 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6620 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6621 | request.method = "GET"; |
| 6622 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6623 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6624 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6625 | request.load_flags = 0; |
| 6626 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6627 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6629 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6630 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6631 | MockWrite( |
| 6632 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6633 | "Host: www.example.org\r\n" |
| 6634 | "Connection: keep-alive\r\n" |
| 6635 | // Send preemptive authorization for MyRealm1 |
| 6636 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6637 | }; |
| 6638 | |
| 6639 | // The server didn't like the preemptive authorization, and |
| 6640 | // challenges us for a different realm (MyRealm2). |
| 6641 | MockRead data_reads1[] = { |
| 6642 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6643 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6644 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6645 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6646 | }; |
| 6647 | |
| 6648 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6649 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6650 | MockWrite( |
| 6651 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6652 | "Host: www.example.org\r\n" |
| 6653 | "Connection: keep-alive\r\n" |
| 6654 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6655 | }; |
| 6656 | |
| 6657 | // Sever accepts the authorization. |
| 6658 | MockRead data_reads2[] = { |
| 6659 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6660 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6661 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6662 | }; |
| 6663 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6664 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6665 | data_writes1, arraysize(data_writes1)); |
| 6666 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6667 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6669 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6671 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6673 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6675 | |
| 6676 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6677 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6678 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6679 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6680 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6681 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6682 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6683 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6684 | response->auth_challenge->challenger.ToString()); |
| 6685 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6686 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6688 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6690 | rv = trans->RestartWithAuth( |
| 6691 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6692 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6693 | |
| 6694 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6695 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6696 | |
| 6697 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6698 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6699 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6700 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6701 | } |
| 6702 | |
| 6703 | // ------------------------------------------------------------------------ |
| 6704 | |
| 6705 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6706 | // succeed with preemptive authorization. |
| 6707 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6708 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6710 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6711 | request.load_flags = 0; |
| 6712 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6713 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6714 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6715 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6716 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6717 | MockWrite( |
| 6718 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6719 | "Host: www.example.org\r\n" |
| 6720 | "Connection: keep-alive\r\n" |
| 6721 | // The authorization for MyRealm1 gets sent preemptively |
| 6722 | // (since the url is in the same protection space) |
| 6723 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6724 | }; |
| 6725 | |
| 6726 | // Sever accepts the preemptive authorization |
| 6727 | MockRead data_reads1[] = { |
| 6728 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6729 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6730 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6731 | }; |
| 6732 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6733 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6734 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6735 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6737 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6739 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6740 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6741 | |
| 6742 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6743 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6744 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6745 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6746 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6747 | |
| 6748 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6749 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6750 | } |
| 6751 | |
| 6752 | // ------------------------------------------------------------------------ |
| 6753 | |
| 6754 | // Transaction 4: request another URL in MyRealm (however the |
| 6755 | // url is not known to belong to the protection space, so no pre-auth). |
| 6756 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6757 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6759 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6760 | request.load_flags = 0; |
| 6761 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6762 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6763 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6764 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6765 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6766 | MockWrite( |
| 6767 | "GET /x/1 HTTP/1.1\r\n" |
| 6768 | "Host: www.example.org\r\n" |
| 6769 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6770 | }; |
| 6771 | |
| 6772 | MockRead data_reads1[] = { |
| 6773 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6774 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6775 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6776 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6777 | }; |
| 6778 | |
| 6779 | // Resend with authorization from MyRealm's cache. |
| 6780 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6781 | MockWrite( |
| 6782 | "GET /x/1 HTTP/1.1\r\n" |
| 6783 | "Host: www.example.org\r\n" |
| 6784 | "Connection: keep-alive\r\n" |
| 6785 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6786 | }; |
| 6787 | |
| 6788 | // Sever accepts the authorization. |
| 6789 | MockRead data_reads2[] = { |
| 6790 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6791 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6792 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6793 | }; |
| 6794 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6795 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6796 | data_writes1, arraysize(data_writes1)); |
| 6797 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6798 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6800 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6802 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6804 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6805 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6806 | |
| 6807 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6808 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6809 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6810 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | TestCompletionCallback callback2; |
| 6812 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6813 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6814 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6815 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6816 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6817 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6819 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6820 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6821 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6822 | } |
| 6823 | |
| 6824 | // ------------------------------------------------------------------------ |
| 6825 | |
| 6826 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6827 | // cached identity. Should invalidate and re-prompt. |
| 6828 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6829 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6831 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6832 | request.load_flags = 0; |
| 6833 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6834 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6835 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6836 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6837 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6838 | MockWrite( |
| 6839 | "GET /p/q/t HTTP/1.1\r\n" |
| 6840 | "Host: www.example.org\r\n" |
| 6841 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6842 | }; |
| 6843 | |
| 6844 | MockRead data_reads1[] = { |
| 6845 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6846 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6847 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6848 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6849 | }; |
| 6850 | |
| 6851 | // Resend with authorization from cache for MyRealm. |
| 6852 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6853 | MockWrite( |
| 6854 | "GET /p/q/t HTTP/1.1\r\n" |
| 6855 | "Host: www.example.org\r\n" |
| 6856 | "Connection: keep-alive\r\n" |
| 6857 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6858 | }; |
| 6859 | |
| 6860 | // Sever rejects the authorization. |
| 6861 | MockRead data_reads2[] = { |
| 6862 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6863 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6864 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6865 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6866 | }; |
| 6867 | |
| 6868 | // At this point we should prompt for new credentials for MyRealm. |
| 6869 | // Restart with username=foo3, password=foo4. |
| 6870 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6871 | MockWrite( |
| 6872 | "GET /p/q/t HTTP/1.1\r\n" |
| 6873 | "Host: www.example.org\r\n" |
| 6874 | "Connection: keep-alive\r\n" |
| 6875 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6876 | }; |
| 6877 | |
| 6878 | // Sever accepts the authorization. |
| 6879 | MockRead data_reads3[] = { |
| 6880 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6881 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6882 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6883 | }; |
| 6884 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6885 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6886 | data_writes1, arraysize(data_writes1)); |
| 6887 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6888 | data_writes2, arraysize(data_writes2)); |
| 6889 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6890 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6892 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6893 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6894 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6895 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6897 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6899 | |
| 6900 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6901 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6902 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6903 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6904 | TestCompletionCallback callback2; |
| 6905 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6906 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6907 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6908 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6909 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6910 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6911 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6912 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6913 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6915 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6917 | rv = trans->RestartWithAuth( |
| 6918 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6920 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6921 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6922 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6923 | |
| 6924 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6925 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6926 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6927 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6928 | } |
| 6929 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6930 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6931 | // Tests that nonce count increments when multiple auth attempts |
| 6932 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6933 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6934 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6935 | new HttpAuthHandlerDigest::Factory(); |
| 6936 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6937 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6938 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6939 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6940 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6941 | |
| 6942 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6943 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6944 | HttpRequestInfo request; |
| 6945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6946 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6947 | request.load_flags = 0; |
| 6948 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6949 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6950 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6951 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6952 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6953 | MockWrite( |
| 6954 | "GET /x/y/z HTTP/1.1\r\n" |
| 6955 | "Host: www.example.org\r\n" |
| 6956 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6957 | }; |
| 6958 | |
| 6959 | MockRead data_reads1[] = { |
| 6960 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6961 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6962 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6963 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6964 | }; |
| 6965 | |
| 6966 | // Resend with authorization (username=foo, password=bar) |
| 6967 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6968 | MockWrite( |
| 6969 | "GET /x/y/z HTTP/1.1\r\n" |
| 6970 | "Host: www.example.org\r\n" |
| 6971 | "Connection: keep-alive\r\n" |
| 6972 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6973 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6974 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6975 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6976 | }; |
| 6977 | |
| 6978 | // Sever accepts the authorization. |
| 6979 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6980 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6982 | }; |
| 6983 | |
| 6984 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6985 | data_writes1, arraysize(data_writes1)); |
| 6986 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6987 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6991 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6993 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6994 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6995 | |
| 6996 | rv = callback1.WaitForResult(); |
| 6997 | EXPECT_EQ(OK, rv); |
| 6998 | |
| 6999 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7000 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7001 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7003 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7005 | rv = trans->RestartWithAuth( |
| 7006 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7007 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7008 | |
| 7009 | rv = callback2.WaitForResult(); |
| 7010 | EXPECT_EQ(OK, rv); |
| 7011 | |
| 7012 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7013 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7014 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7015 | } |
| 7016 | |
| 7017 | // ------------------------------------------------------------------------ |
| 7018 | |
| 7019 | // Transaction 2: Request another resource in digestive's protection space. |
| 7020 | // This will preemptively add an Authorization header which should have an |
| 7021 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7022 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7023 | HttpRequestInfo request; |
| 7024 | request.method = "GET"; |
| 7025 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7026 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7027 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7028 | request.load_flags = 0; |
| 7029 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7030 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7031 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7032 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7033 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7034 | MockWrite( |
| 7035 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7036 | "Host: www.example.org\r\n" |
| 7037 | "Connection: keep-alive\r\n" |
| 7038 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7039 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7040 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7041 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7042 | }; |
| 7043 | |
| 7044 | // Sever accepts the authorization. |
| 7045 | MockRead data_reads1[] = { |
| 7046 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7047 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7048 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7049 | }; |
| 7050 | |
| 7051 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7052 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7055 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7057 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7059 | |
| 7060 | rv = callback1.WaitForResult(); |
| 7061 | EXPECT_EQ(OK, rv); |
| 7062 | |
| 7063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7064 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7065 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7066 | } |
| 7067 | } |
| 7068 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7069 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7070 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7071 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7072 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7073 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7074 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7075 | |
| 7076 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7077 | trans->read_buf_ = new IOBuffer(15); |
| 7078 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7079 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7080 | |
| 7081 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7082 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7083 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7084 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7085 | response->response_time = base::Time::Now(); |
| 7086 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7087 | |
| 7088 | { // Setup state for response_.vary_data |
| 7089 | HttpRequestInfo request; |
| 7090 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7091 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7092 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7093 | request.extra_headers.SetHeader("Foo", "1"); |
| 7094 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7095 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | // Cause the above state to be reset. |
| 7099 | trans->ResetStateForRestart(); |
| 7100 | |
| 7101 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 7102 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7103 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7104 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7105 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7106 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7107 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7108 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7109 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7110 | } |
| 7111 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7112 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7113 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7114 | HttpRequestInfo request; |
| 7115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7116 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7117 | request.load_flags = 0; |
| 7118 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7119 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7120 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7122 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7123 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7124 | MockWrite( |
| 7125 | "GET / HTTP/1.1\r\n" |
| 7126 | "Host: www.example.org\r\n" |
| 7127 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7128 | }; |
| 7129 | |
| 7130 | MockRead data_reads[] = { |
| 7131 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7132 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7133 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7134 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7135 | }; |
| 7136 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7137 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7138 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7139 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7140 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7141 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7142 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7143 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7148 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7150 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7151 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7152 | |
| 7153 | rv = callback.WaitForResult(); |
| 7154 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7156 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7157 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7158 | |
| 7159 | rv = callback.WaitForResult(); |
| 7160 | EXPECT_EQ(OK, rv); |
| 7161 | |
| 7162 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7163 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7164 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7165 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7166 | } |
| 7167 | |
| 7168 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7169 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7170 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7171 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7172 | |
| 7173 | HttpRequestInfo request; |
| 7174 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7175 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7176 | request.load_flags = 0; |
| 7177 | |
| 7178 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7179 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7180 | "Host: www.example.org:443\r\n" |
| 7181 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7182 | }; |
| 7183 | |
| 7184 | MockRead proxy_reads[] = { |
| 7185 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7186 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7187 | }; |
| 7188 | |
| 7189 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7190 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7191 | "Host: www.example.org:443\r\n" |
| 7192 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7193 | MockWrite("GET / HTTP/1.1\r\n" |
| 7194 | "Host: www.example.org\r\n" |
| 7195 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7196 | }; |
| 7197 | |
| 7198 | MockRead data_reads[] = { |
| 7199 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7200 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7201 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7202 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7203 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7204 | }; |
| 7205 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7206 | StaticSocketDataProvider ssl_bad_certificate( |
| 7207 | proxy_reads, arraysize(proxy_reads), |
| 7208 | proxy_writes, arraysize(proxy_writes)); |
| 7209 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7210 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7211 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7212 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7213 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7214 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7219 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7220 | |
| 7221 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7222 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7223 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7224 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7225 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7226 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7228 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7229 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7230 | |
| 7231 | rv = callback.WaitForResult(); |
| 7232 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7234 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7236 | |
| 7237 | rv = callback.WaitForResult(); |
| 7238 | EXPECT_EQ(OK, rv); |
| 7239 | |
| 7240 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7241 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7242 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7243 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7244 | } |
| 7245 | } |
| 7246 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7247 | |
| 7248 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7249 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7250 | session_deps_.proxy_service = |
| 7251 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7252 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7253 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7254 | |
| 7255 | HttpRequestInfo request; |
| 7256 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7257 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7258 | request.load_flags = 0; |
| 7259 | |
| 7260 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7261 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7262 | "Host: www.example.org:443\r\n" |
| 7263 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7264 | MockWrite("GET / HTTP/1.1\r\n" |
| 7265 | "Host: www.example.org\r\n" |
| 7266 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7267 | }; |
| 7268 | |
| 7269 | MockRead data_reads[] = { |
| 7270 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7271 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7273 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7274 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7275 | }; |
| 7276 | |
| 7277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7278 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7279 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7280 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7281 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7282 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7283 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7286 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7287 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7288 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7289 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7292 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7294 | |
| 7295 | rv = callback.WaitForResult(); |
| 7296 | EXPECT_EQ(OK, rv); |
| 7297 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7298 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7299 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7300 | |
| 7301 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7302 | EXPECT_EQ(200, response->headers->response_code()); |
| 7303 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7304 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7305 | |
| 7306 | LoadTimingInfo load_timing_info; |
| 7307 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7308 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7309 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7310 | } |
| 7311 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7312 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7313 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7314 | session_deps_.proxy_service = |
| 7315 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7316 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7317 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7318 | |
| 7319 | HttpRequestInfo request; |
| 7320 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7321 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7322 | request.load_flags = 0; |
| 7323 | |
| 7324 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7325 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7326 | "Host: www.example.org:443\r\n" |
| 7327 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7328 | }; |
| 7329 | |
| 7330 | MockRead data_reads[] = { |
| 7331 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7332 | MockRead("Location: http://login.example.com/\r\n"), |
| 7333 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7334 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7335 | }; |
| 7336 | |
| 7337 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7338 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7339 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7340 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7341 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7344 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7345 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7346 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7347 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7348 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7350 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7352 | |
| 7353 | rv = callback.WaitForResult(); |
| 7354 | EXPECT_EQ(OK, rv); |
| 7355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7356 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7357 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7358 | |
| 7359 | EXPECT_EQ(302, response->headers->response_code()); |
| 7360 | std::string url; |
| 7361 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7362 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7363 | |
| 7364 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7365 | // timing for the proxy connection instead of the connection to the host, |
| 7366 | // and no send / receive times. |
| 7367 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7368 | LoadTimingInfo load_timing_info; |
| 7369 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7370 | |
| 7371 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7372 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7373 | |
| 7374 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7375 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7376 | load_timing_info.proxy_resolve_end); |
| 7377 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7378 | load_timing_info.connect_timing.connect_start); |
| 7379 | ExpectConnectTimingHasTimes( |
| 7380 | load_timing_info.connect_timing, |
| 7381 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7382 | |
| 7383 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7384 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7385 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7386 | } |
| 7387 | |
| 7388 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7389 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7390 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7391 | |
| 7392 | HttpRequestInfo request; |
| 7393 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7394 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7395 | request.load_flags = 0; |
| 7396 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7397 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7398 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7399 | scoped_ptr<SpdyFrame> goaway( |
| 7400 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7401 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7402 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7403 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7404 | }; |
| 7405 | |
| 7406 | static const char* const kExtraHeaders[] = { |
| 7407 | "location", |
| 7408 | "http://login.example.com/", |
| 7409 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7410 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7411 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7412 | arraysize(kExtraHeaders)/2, 1)); |
| 7413 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7414 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7415 | }; |
| 7416 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7417 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7418 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7419 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7420 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7421 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7425 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7426 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7427 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7428 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7429 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7431 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7432 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7433 | |
| 7434 | rv = callback.WaitForResult(); |
| 7435 | EXPECT_EQ(OK, rv); |
| 7436 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7437 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7438 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7439 | |
| 7440 | EXPECT_EQ(302, response->headers->response_code()); |
| 7441 | std::string url; |
| 7442 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7443 | EXPECT_EQ("http://login.example.com/", url); |
| 7444 | } |
| 7445 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7446 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7447 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7448 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7449 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7450 | |
| 7451 | HttpRequestInfo request; |
| 7452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7453 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7454 | request.load_flags = 0; |
| 7455 | |
| 7456 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7457 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7458 | "Host: www.example.org:443\r\n" |
| 7459 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7460 | }; |
| 7461 | |
| 7462 | MockRead data_reads[] = { |
| 7463 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7464 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7465 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7466 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7467 | }; |
| 7468 | |
| 7469 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7470 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7471 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7476 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7477 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7478 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7479 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7482 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7484 | |
| 7485 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7486 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7487 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7488 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7489 | } |
| 7490 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7491 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7492 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7493 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7494 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7495 | |
| 7496 | HttpRequestInfo request; |
| 7497 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7498 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7499 | request.load_flags = 0; |
| 7500 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7501 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7502 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7503 | scoped_ptr<SpdyFrame> rst( |
| 7504 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7505 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7506 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7507 | }; |
| 7508 | |
| 7509 | static const char* const kExtraHeaders[] = { |
| 7510 | "location", |
| 7511 | "http://login.example.com/", |
| 7512 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7513 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7514 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7515 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7516 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7517 | spdy_util_.ConstructSpdyBodyFrame( |
| 7518 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7519 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7520 | CreateMockRead(*resp.get(), 1), |
| 7521 | CreateMockRead(*body.get(), 2), |
| 7522 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7523 | }; |
| 7524 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7525 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7526 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7527 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7528 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7529 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7533 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7534 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7535 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7536 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7537 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7539 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7540 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7541 | |
| 7542 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7543 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7544 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7545 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7546 | } |
| 7547 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7548 | // Test the request-challenge-retry sequence for basic auth, through |
| 7549 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7550 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7551 | HttpRequestInfo request; |
| 7552 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7553 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7554 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7555 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7556 | |
| 7557 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7558 | session_deps_.proxy_service = |
| 7559 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7560 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7561 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7562 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7563 | |
| 7564 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7565 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7566 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7567 | scoped_ptr<SpdyFrame> rst( |
| 7568 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7569 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7570 | |
| 7571 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7572 | // be issuing -- the final header line contains the credentials. |
| 7573 | const char* const kAuthCredentials[] = { |
| 7574 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7575 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7576 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7577 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7578 | HostPortPair("www.example.org", 443))); |
| 7579 | // fetch https://www.example.org/ via HTTP |
| 7580 | const char get[] = |
| 7581 | "GET / HTTP/1.1\r\n" |
| 7582 | "Host: www.example.org\r\n" |
| 7583 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7584 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7585 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7586 | |
| 7587 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7588 | CreateMockWrite(*req, 0, ASYNC), |
| 7589 | CreateMockWrite(*rst, 2, ASYNC), |
| 7590 | CreateMockWrite(*connect2, 3), |
| 7591 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7592 | }; |
| 7593 | |
| 7594 | // The proxy responds to the connect with a 407, using a persistent |
| 7595 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7596 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7597 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7598 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7599 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7600 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7601 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7602 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7603 | scoped_ptr<SpdyFrame> conn_resp( |
| 7604 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7605 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7606 | "Content-Length: 5\r\n\r\n"; |
| 7607 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7608 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7609 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7610 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7611 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7612 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7613 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7614 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7615 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7616 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7617 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7618 | }; |
| 7619 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7620 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7621 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7622 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7623 | // Negotiate SPDY to the proxy |
| 7624 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7625 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7627 | // Vanilla SSL to the server |
| 7628 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7630 | |
| 7631 | TestCompletionCallback callback1; |
| 7632 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7633 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7634 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7635 | |
| 7636 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7637 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7638 | |
| 7639 | rv = callback1.WaitForResult(); |
| 7640 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7641 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7642 | log.GetEntries(&entries); |
| 7643 | size_t pos = ExpectLogContainsSomewhere( |
| 7644 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7645 | NetLog::PHASE_NONE); |
| 7646 | ExpectLogContainsSomewhere( |
| 7647 | entries, pos, |
| 7648 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7649 | NetLog::PHASE_NONE); |
| 7650 | |
| 7651 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7652 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7653 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7654 | EXPECT_EQ(407, response->headers->response_code()); |
| 7655 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7656 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7657 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7658 | |
| 7659 | TestCompletionCallback callback2; |
| 7660 | |
| 7661 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7662 | callback2.callback()); |
| 7663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7664 | |
| 7665 | rv = callback2.WaitForResult(); |
| 7666 | EXPECT_EQ(OK, rv); |
| 7667 | |
| 7668 | response = trans->GetResponseInfo(); |
| 7669 | ASSERT_TRUE(response != NULL); |
| 7670 | |
| 7671 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7672 | EXPECT_EQ(200, response->headers->response_code()); |
| 7673 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7674 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7675 | |
| 7676 | // The password prompt info should not be set. |
| 7677 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7678 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7679 | LoadTimingInfo load_timing_info; |
| 7680 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7681 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7682 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7683 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7684 | trans.reset(); |
| 7685 | session->CloseAllConnections(); |
| 7686 | } |
| 7687 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7688 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7689 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7690 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7691 | HttpRequestInfo request; |
| 7692 | HttpRequestInfo push_request; |
| 7693 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7694 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7695 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7696 | push_request.method = "GET"; |
| 7697 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7698 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7699 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7700 | session_deps_.proxy_service = |
| 7701 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7702 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7703 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7704 | |
| 7705 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7706 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7707 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7708 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7709 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7710 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7711 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7712 | |
| 7713 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7714 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7715 | }; |
| 7716 | |
| 7717 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7718 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7719 | |
| 7720 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7721 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7722 | |
| 7723 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7724 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7725 | 0, |
| 7726 | 2, |
| 7727 | 1, |
| 7728 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7729 | const char kPushedData[] = "pushed"; |
| 7730 | scoped_ptr<SpdyFrame> stream2_body( |
| 7731 | spdy_util_.ConstructSpdyBodyFrame( |
| 7732 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7733 | |
| 7734 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7735 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7736 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7737 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7738 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7739 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7740 | }; |
| 7741 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7742 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7743 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7744 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7745 | // Negotiate SPDY to the proxy |
| 7746 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7747 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7749 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7750 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7751 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7752 | TestCompletionCallback callback; |
| 7753 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7754 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7755 | |
| 7756 | rv = callback.WaitForResult(); |
| 7757 | EXPECT_EQ(OK, rv); |
| 7758 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7759 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7760 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7761 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7762 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7763 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7764 | |
| 7765 | rv = callback.WaitForResult(); |
| 7766 | EXPECT_EQ(OK, rv); |
| 7767 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7768 | |
| 7769 | ASSERT_TRUE(response != NULL); |
| 7770 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7771 | |
| 7772 | EXPECT_EQ(200, response->headers->response_code()); |
| 7773 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7774 | |
| 7775 | std::string response_data; |
| 7776 | rv = ReadTransaction(trans.get(), &response_data); |
| 7777 | EXPECT_EQ(OK, rv); |
| 7778 | EXPECT_EQ("hello!", response_data); |
| 7779 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7780 | LoadTimingInfo load_timing_info; |
| 7781 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7782 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7783 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7784 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7785 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7786 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7787 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7788 | |
| 7789 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7790 | EXPECT_EQ(OK, rv); |
| 7791 | EXPECT_EQ("pushed", response_data); |
| 7792 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7793 | LoadTimingInfo push_load_timing_info; |
| 7794 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7795 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7796 | // The transactions should share a socket ID, despite being for different |
| 7797 | // origins. |
| 7798 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7799 | push_load_timing_info.socket_log_id); |
| 7800 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7801 | trans.reset(); |
| 7802 | push_trans.reset(); |
| 7803 | session->CloseAllConnections(); |
| 7804 | } |
| 7805 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7806 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7807 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7808 | HttpRequestInfo request; |
| 7809 | |
| 7810 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7811 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7812 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7813 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7814 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7815 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7816 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7817 | |
| 7818 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7819 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7820 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7821 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7822 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7823 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7824 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7825 | |
| 7826 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7827 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7828 | |
| 7829 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7830 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7831 | }; |
| 7832 | |
| 7833 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7834 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7835 | |
| 7836 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7837 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7838 | |
| 7839 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7840 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7841 | 0, |
| 7842 | 2, |
| 7843 | 1, |
| 7844 | "https://www.another-origin.com/foo.dat")); |
| 7845 | |
| 7846 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7847 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7848 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7849 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7850 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7851 | }; |
| 7852 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7853 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7854 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7855 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7856 | // Negotiate SPDY to the proxy |
| 7857 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7858 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7860 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7861 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7863 | TestCompletionCallback callback; |
| 7864 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7866 | |
| 7867 | rv = callback.WaitForResult(); |
| 7868 | EXPECT_EQ(OK, rv); |
| 7869 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7870 | |
| 7871 | ASSERT_TRUE(response != NULL); |
| 7872 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7873 | |
| 7874 | EXPECT_EQ(200, response->headers->response_code()); |
| 7875 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7876 | |
| 7877 | std::string response_data; |
| 7878 | rv = ReadTransaction(trans.get(), &response_data); |
| 7879 | EXPECT_EQ(OK, rv); |
| 7880 | EXPECT_EQ("hello!", response_data); |
| 7881 | |
| 7882 | trans.reset(); |
| 7883 | session->CloseAllConnections(); |
| 7884 | } |
| 7885 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7886 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7887 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7888 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7889 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7890 | |
| 7891 | HttpRequestInfo request; |
| 7892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7893 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7894 | request.load_flags = 0; |
| 7895 | |
| 7896 | // Attempt to fetch the URL from a server with a bad cert |
| 7897 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7898 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7899 | "Host: www.example.org:443\r\n" |
| 7900 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7901 | }; |
| 7902 | |
| 7903 | MockRead bad_cert_reads[] = { |
| 7904 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7905 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7906 | }; |
| 7907 | |
| 7908 | // Attempt to fetch the URL with a good cert |
| 7909 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7910 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7911 | "Host: www.example.org:443\r\n" |
| 7912 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7913 | MockWrite("GET / HTTP/1.1\r\n" |
| 7914 | "Host: www.example.org\r\n" |
| 7915 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7916 | }; |
| 7917 | |
| 7918 | MockRead good_cert_reads[] = { |
| 7919 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7920 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7921 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7922 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7924 | }; |
| 7925 | |
| 7926 | StaticSocketDataProvider ssl_bad_certificate( |
| 7927 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7928 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7929 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7930 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7931 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7932 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7933 | |
| 7934 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7936 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7938 | |
| 7939 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7943 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7944 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7945 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7946 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7947 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7948 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7950 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7952 | |
| 7953 | rv = callback.WaitForResult(); |
| 7954 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7956 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7958 | |
| 7959 | rv = callback.WaitForResult(); |
| 7960 | EXPECT_EQ(OK, rv); |
| 7961 | |
| 7962 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7963 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7964 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7966 | } |
| 7967 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7968 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7969 | HttpRequestInfo request; |
| 7970 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7971 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7972 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7973 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7974 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7975 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7976 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7978 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7979 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7980 | MockWrite( |
| 7981 | "GET / HTTP/1.1\r\n" |
| 7982 | "Host: www.example.org\r\n" |
| 7983 | "Connection: keep-alive\r\n" |
| 7984 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7985 | }; |
| 7986 | |
| 7987 | // Lastly, the server responds with the actual content. |
| 7988 | MockRead data_reads[] = { |
| 7989 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7990 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7991 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7993 | }; |
| 7994 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7995 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7996 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7999 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8001 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8003 | |
| 8004 | rv = callback.WaitForResult(); |
| 8005 | EXPECT_EQ(OK, rv); |
| 8006 | } |
| 8007 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8008 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8009 | HttpRequestInfo request; |
| 8010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8011 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8012 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8013 | "Chromium Ultra Awesome X Edition"); |
| 8014 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8015 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8016 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8017 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8019 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8020 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8021 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8022 | "Host: www.example.org:443\r\n" |
| 8023 | "Proxy-Connection: keep-alive\r\n" |
| 8024 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8025 | }; |
| 8026 | MockRead data_reads[] = { |
| 8027 | // Return an error, so the transaction stops here (this test isn't |
| 8028 | // interested in the rest). |
| 8029 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8030 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8031 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8032 | }; |
| 8033 | |
| 8034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8035 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8038 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8040 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8042 | |
| 8043 | rv = callback.WaitForResult(); |
| 8044 | EXPECT_EQ(OK, rv); |
| 8045 | } |
| 8046 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8047 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8048 | HttpRequestInfo request; |
| 8049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8050 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8051 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8052 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8053 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8054 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8055 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8056 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8057 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8058 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8059 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8060 | MockWrite( |
| 8061 | "GET / HTTP/1.1\r\n" |
| 8062 | "Host: www.example.org\r\n" |
| 8063 | "Connection: keep-alive\r\n" |
| 8064 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8065 | }; |
| 8066 | |
| 8067 | // Lastly, the server responds with the actual content. |
| 8068 | MockRead data_reads[] = { |
| 8069 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8070 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8071 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8073 | }; |
| 8074 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8075 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8076 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8079 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58: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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8083 | |
| 8084 | rv = callback.WaitForResult(); |
| 8085 | EXPECT_EQ(OK, rv); |
| 8086 | } |
| 8087 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8088 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8089 | HttpRequestInfo request; |
| 8090 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8091 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8092 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8093 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8094 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8095 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8096 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8097 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8098 | MockWrite( |
| 8099 | "POST / HTTP/1.1\r\n" |
| 8100 | "Host: www.example.org\r\n" |
| 8101 | "Connection: keep-alive\r\n" |
| 8102 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8103 | }; |
| 8104 | |
| 8105 | // Lastly, the server responds with the actual content. |
| 8106 | MockRead data_reads[] = { |
| 8107 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8108 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8109 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8111 | }; |
| 8112 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8113 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8114 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8117 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8119 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8121 | |
| 8122 | rv = callback.WaitForResult(); |
| 8123 | EXPECT_EQ(OK, rv); |
| 8124 | } |
| 8125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8126 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8127 | HttpRequestInfo request; |
| 8128 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8129 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8130 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8131 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8132 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8134 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8135 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8136 | MockWrite( |
| 8137 | "PUT / HTTP/1.1\r\n" |
| 8138 | "Host: www.example.org\r\n" |
| 8139 | "Connection: keep-alive\r\n" |
| 8140 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8141 | }; |
| 8142 | |
| 8143 | // Lastly, the server responds with the actual content. |
| 8144 | MockRead data_reads[] = { |
| 8145 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8146 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8147 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8148 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8149 | }; |
| 8150 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8152 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8155 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8157 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8159 | |
| 8160 | rv = callback.WaitForResult(); |
| 8161 | EXPECT_EQ(OK, rv); |
| 8162 | } |
| 8163 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8164 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8165 | HttpRequestInfo request; |
| 8166 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8167 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8168 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8169 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8170 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8172 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8173 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8174 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8175 | "Host: www.example.org\r\n" |
| 8176 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8177 | }; |
| 8178 | |
| 8179 | // Lastly, the server responds with the actual content. |
| 8180 | MockRead data_reads[] = { |
| 8181 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8182 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8183 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8184 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8185 | }; |
| 8186 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8187 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8188 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8191 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8193 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8195 | |
| 8196 | rv = callback.WaitForResult(); |
| 8197 | EXPECT_EQ(OK, rv); |
| 8198 | } |
| 8199 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8200 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8201 | HttpRequestInfo request; |
| 8202 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8203 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8204 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8205 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8206 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8207 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8209 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8210 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8211 | MockWrite( |
| 8212 | "GET / HTTP/1.1\r\n" |
| 8213 | "Host: www.example.org\r\n" |
| 8214 | "Connection: keep-alive\r\n" |
| 8215 | "Pragma: no-cache\r\n" |
| 8216 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8217 | }; |
| 8218 | |
| 8219 | // Lastly, the server responds with the actual content. |
| 8220 | MockRead data_reads[] = { |
| 8221 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8222 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8223 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8224 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8225 | }; |
| 8226 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8227 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8228 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8231 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8233 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8234 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8235 | |
| 8236 | rv = callback.WaitForResult(); |
| 8237 | EXPECT_EQ(OK, rv); |
| 8238 | } |
| 8239 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8240 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8241 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8242 | HttpRequestInfo request; |
| 8243 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8244 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8245 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8246 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8247 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8248 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8250 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8251 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8252 | MockWrite( |
| 8253 | "GET / HTTP/1.1\r\n" |
| 8254 | "Host: www.example.org\r\n" |
| 8255 | "Connection: keep-alive\r\n" |
| 8256 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8257 | }; |
| 8258 | |
| 8259 | // Lastly, the server responds with the actual content. |
| 8260 | MockRead data_reads[] = { |
| 8261 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8262 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8263 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8265 | }; |
| 8266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8268 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8271 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8273 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8274 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8275 | |
| 8276 | rv = callback.WaitForResult(); |
| 8277 | EXPECT_EQ(OK, rv); |
| 8278 | } |
| 8279 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8280 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8281 | HttpRequestInfo request; |
| 8282 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8283 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8284 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8285 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8286 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8287 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8289 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8290 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8291 | MockWrite( |
| 8292 | "GET / HTTP/1.1\r\n" |
| 8293 | "Host: www.example.org\r\n" |
| 8294 | "Connection: keep-alive\r\n" |
| 8295 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8296 | }; |
| 8297 | |
| 8298 | // Lastly, the server responds with the actual content. |
| 8299 | MockRead data_reads[] = { |
| 8300 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8301 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8302 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8303 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8304 | }; |
| 8305 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8306 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8307 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8308 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8310 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8312 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8313 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8314 | |
| 8315 | rv = callback.WaitForResult(); |
| 8316 | EXPECT_EQ(OK, rv); |
| 8317 | } |
| 8318 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8319 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8320 | HttpRequestInfo request; |
| 8321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8322 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8323 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8324 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8325 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8326 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8327 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8328 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8330 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8331 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8332 | MockWrite( |
| 8333 | "GET / HTTP/1.1\r\n" |
| 8334 | "Host: www.example.org\r\n" |
| 8335 | "Connection: keep-alive\r\n" |
| 8336 | "referer: www.foo.com\r\n" |
| 8337 | "hEllo: Kitty\r\n" |
| 8338 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8339 | }; |
| 8340 | |
| 8341 | // Lastly, the server responds with the actual content. |
| 8342 | MockRead data_reads[] = { |
| 8343 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8344 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8345 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8346 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8347 | }; |
| 8348 | |
| 8349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8350 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8353 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8355 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8357 | |
| 8358 | rv = callback.WaitForResult(); |
| 8359 | EXPECT_EQ(OK, rv); |
| 8360 | } |
| 8361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8362 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8363 | HttpRequestInfo request; |
| 8364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8365 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8366 | request.load_flags = 0; |
| 8367 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8368 | session_deps_.proxy_service = |
| 8369 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8370 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8371 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8372 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8373 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8374 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8375 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8376 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8377 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8378 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8379 | |
| 8380 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8381 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8382 | MockWrite( |
| 8383 | "GET / HTTP/1.1\r\n" |
| 8384 | "Host: www.example.org\r\n" |
| 8385 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8386 | |
| 8387 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8388 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8389 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8390 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8391 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8392 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8393 | }; |
| 8394 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8395 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8396 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8397 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8399 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8401 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8403 | |
| 8404 | rv = callback.WaitForResult(); |
| 8405 | EXPECT_EQ(OK, rv); |
| 8406 | |
| 8407 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8408 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8409 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8410 | LoadTimingInfo load_timing_info; |
| 8411 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8412 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8413 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8414 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8415 | std::string response_text; |
| 8416 | rv = ReadTransaction(trans.get(), &response_text); |
| 8417 | EXPECT_EQ(OK, rv); |
| 8418 | EXPECT_EQ("Payload", response_text); |
| 8419 | } |
| 8420 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8421 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8422 | HttpRequestInfo request; |
| 8423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8424 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8425 | request.load_flags = 0; |
| 8426 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8427 | session_deps_.proxy_service = |
| 8428 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8429 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8430 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8431 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8432 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8433 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8434 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8435 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8436 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8437 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8438 | |
| 8439 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8440 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8441 | arraysize(write_buffer)), |
| 8442 | MockWrite( |
| 8443 | "GET / HTTP/1.1\r\n" |
| 8444 | "Host: www.example.org\r\n" |
| 8445 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8446 | |
| 8447 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8448 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8449 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8450 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8451 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8452 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8453 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8454 | }; |
| 8455 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8456 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8457 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8459 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8460 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8463 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8465 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8466 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8467 | |
| 8468 | rv = callback.WaitForResult(); |
| 8469 | EXPECT_EQ(OK, rv); |
| 8470 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8471 | LoadTimingInfo load_timing_info; |
| 8472 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8473 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8474 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8475 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8476 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8477 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8478 | |
| 8479 | std::string response_text; |
| 8480 | rv = ReadTransaction(trans.get(), &response_text); |
| 8481 | EXPECT_EQ(OK, rv); |
| 8482 | EXPECT_EQ("Payload", response_text); |
| 8483 | } |
| 8484 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8485 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8486 | HttpRequestInfo request; |
| 8487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8488 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8489 | request.load_flags = 0; |
| 8490 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8491 | session_deps_.proxy_service = |
| 8492 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8493 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8494 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8495 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8496 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8497 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8498 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8499 | |
| 8500 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8501 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8502 | |
| 8503 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8504 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8505 | MockWrite( |
| 8506 | "GET / HTTP/1.1\r\n" |
| 8507 | "Host: www.example.org\r\n" |
| 8508 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8509 | |
| 8510 | MockRead data_reads[] = { |
| 8511 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8512 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8513 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8514 | MockRead("Payload"), |
| 8515 | MockRead(SYNCHRONOUS, OK) |
| 8516 | }; |
| 8517 | |
| 8518 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8519 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8520 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8521 | |
| 8522 | TestCompletionCallback callback; |
| 8523 | |
| 8524 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8526 | |
| 8527 | rv = callback.WaitForResult(); |
| 8528 | EXPECT_EQ(OK, rv); |
| 8529 | |
| 8530 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8531 | ASSERT_TRUE(response != NULL); |
| 8532 | |
| 8533 | LoadTimingInfo load_timing_info; |
| 8534 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8535 | TestLoadTimingNotReused(load_timing_info, |
| 8536 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8537 | |
| 8538 | std::string response_text; |
| 8539 | rv = ReadTransaction(trans.get(), &response_text); |
| 8540 | EXPECT_EQ(OK, rv); |
| 8541 | EXPECT_EQ("Payload", response_text); |
| 8542 | } |
| 8543 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8544 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8545 | HttpRequestInfo request; |
| 8546 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8547 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8548 | request.load_flags = 0; |
| 8549 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8550 | session_deps_.proxy_service = |
| 8551 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8552 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8553 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8554 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8555 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8556 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8558 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8559 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8560 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8561 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8562 | 0x05, // Version |
| 8563 | 0x01, // Command (CONNECT) |
| 8564 | 0x00, // Reserved. |
| 8565 | 0x03, // Address type (DOMAINNAME). |
| 8566 | 0x0F, // Length of domain (15) |
| 8567 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8568 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8569 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8570 | const char kSOCKS5OkResponse[] = |
| 8571 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8572 | |
| 8573 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8574 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8575 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8576 | MockWrite( |
| 8577 | "GET / HTTP/1.1\r\n" |
| 8578 | "Host: www.example.org\r\n" |
| 8579 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8580 | |
| 8581 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8582 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8583 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8584 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8586 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8587 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8588 | }; |
| 8589 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8590 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8591 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8594 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8596 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8598 | |
| 8599 | rv = callback.WaitForResult(); |
| 8600 | EXPECT_EQ(OK, rv); |
| 8601 | |
| 8602 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8603 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8604 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8605 | LoadTimingInfo load_timing_info; |
| 8606 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8607 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8608 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8609 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8610 | std::string response_text; |
| 8611 | rv = ReadTransaction(trans.get(), &response_text); |
| 8612 | EXPECT_EQ(OK, rv); |
| 8613 | EXPECT_EQ("Payload", response_text); |
| 8614 | } |
| 8615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8616 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8617 | HttpRequestInfo request; |
| 8618 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8619 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8620 | request.load_flags = 0; |
| 8621 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8622 | session_deps_.proxy_service = |
| 8623 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8624 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8625 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8626 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8627 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8628 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8629 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8630 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8631 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8632 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8633 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8634 | 0x05, // Version |
| 8635 | 0x01, // Command (CONNECT) |
| 8636 | 0x00, // Reserved. |
| 8637 | 0x03, // Address type (DOMAINNAME). |
| 8638 | 0x0F, // Length of domain (15) |
| 8639 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8640 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8641 | }; |
| 8642 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8643 | const char kSOCKS5OkResponse[] = |
| 8644 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8645 | |
| 8646 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8647 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8648 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8649 | arraysize(kSOCKS5OkRequest)), |
| 8650 | MockWrite( |
| 8651 | "GET / HTTP/1.1\r\n" |
| 8652 | "Host: www.example.org\r\n" |
| 8653 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8654 | |
| 8655 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8656 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8657 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8658 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8659 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8660 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8661 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8662 | }; |
| 8663 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8665 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8667 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8668 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8669 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8671 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8673 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8675 | |
| 8676 | rv = callback.WaitForResult(); |
| 8677 | EXPECT_EQ(OK, rv); |
| 8678 | |
| 8679 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8680 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8681 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8682 | LoadTimingInfo load_timing_info; |
| 8683 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8684 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8685 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8686 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8687 | std::string response_text; |
| 8688 | rv = ReadTransaction(trans.get(), &response_text); |
| 8689 | EXPECT_EQ(OK, rv); |
| 8690 | EXPECT_EQ("Payload", response_text); |
| 8691 | } |
| 8692 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8693 | namespace { |
| 8694 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8695 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8696 | |
| 8697 | struct GroupNameTest { |
| 8698 | std::string proxy_server; |
| 8699 | std::string url; |
| 8700 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8701 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8702 | }; |
| 8703 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8704 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8705 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8706 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8707 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8708 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8709 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8710 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8711 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8712 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8713 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8714 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8715 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8716 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8717 | |
| 8718 | return session; |
| 8719 | } |
| 8720 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8721 | int GroupNameTransactionHelper(const std::string& url, |
| 8722 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8723 | HttpRequestInfo request; |
| 8724 | request.method = "GET"; |
| 8725 | request.url = GURL(url); |
| 8726 | request.load_flags = 0; |
| 8727 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8728 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8731 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8732 | |
| 8733 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8734 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8735 | } |
| 8736 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8737 | } // namespace |
| 8738 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8739 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8740 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8741 | { |
| 8742 | "", // unused |
| 8743 | "http://www.example.org/direct", |
| 8744 | "www.example.org:80", |
| 8745 | false, |
| 8746 | }, |
| 8747 | { |
| 8748 | "", // unused |
| 8749 | "http://[2001:1418:13:1::25]/direct", |
| 8750 | "[2001:1418:13:1::25]:80", |
| 8751 | false, |
| 8752 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8753 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8754 | // SSL Tests |
| 8755 | { |
| 8756 | "", // unused |
| 8757 | "https://www.example.org/direct_ssl", |
| 8758 | "ssl/www.example.org:443", |
| 8759 | true, |
| 8760 | }, |
| 8761 | { |
| 8762 | "", // unused |
| 8763 | "https://[2001:1418:13:1::25]/direct", |
| 8764 | "ssl/[2001:1418:13:1::25]:443", |
| 8765 | true, |
| 8766 | }, |
| 8767 | { |
| 8768 | "", // unused |
| 8769 | "http://host.with.alternate/direct", |
| 8770 | "ssl/host.with.alternate:443", |
| 8771 | true, |
| 8772 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8773 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8774 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8775 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8776 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8777 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8778 | session_deps_.proxy_service = |
| 8779 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8780 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8781 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8782 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8783 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8784 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8785 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8786 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8787 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8788 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8789 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8790 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8791 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8792 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8793 | |
| 8794 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8795 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8796 | if (tests[i].ssl) |
| 8797 | EXPECT_EQ(tests[i].expected_group_name, |
| 8798 | ssl_conn_pool->last_group_name_received()); |
| 8799 | else |
| 8800 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8801 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8802 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8803 | } |
| 8804 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8805 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8806 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8807 | { |
| 8808 | "http_proxy", |
| 8809 | "http://www.example.org/http_proxy_normal", |
| 8810 | "www.example.org:80", |
| 8811 | false, |
| 8812 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8813 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8814 | // SSL Tests |
| 8815 | { |
| 8816 | "http_proxy", |
| 8817 | "https://www.example.org/http_connect_ssl", |
| 8818 | "ssl/www.example.org:443", |
| 8819 | true, |
| 8820 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8821 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8822 | { |
| 8823 | "http_proxy", |
| 8824 | "http://host.with.alternate/direct", |
| 8825 | "ssl/host.with.alternate:443", |
| 8826 | true, |
| 8827 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8828 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8829 | { |
| 8830 | "http_proxy", |
| 8831 | "ftp://ftp.google.com/http_proxy_normal", |
| 8832 | "ftp/ftp.google.com:21", |
| 8833 | false, |
| 8834 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8835 | }; |
| 8836 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8837 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8838 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8839 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8840 | session_deps_.proxy_service = |
| 8841 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8842 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8843 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8844 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8845 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8846 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8847 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8848 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8849 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8850 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8851 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8852 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8853 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8854 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8855 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8856 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8857 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8858 | |
| 8859 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8860 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8861 | if (tests[i].ssl) |
| 8862 | EXPECT_EQ(tests[i].expected_group_name, |
| 8863 | ssl_conn_pool->last_group_name_received()); |
| 8864 | else |
| 8865 | EXPECT_EQ(tests[i].expected_group_name, |
| 8866 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8867 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8868 | } |
| 8869 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8870 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8871 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8872 | { |
| 8873 | "socks4://socks_proxy:1080", |
| 8874 | "http://www.example.org/socks4_direct", |
| 8875 | "socks4/www.example.org:80", |
| 8876 | false, |
| 8877 | }, |
| 8878 | { |
| 8879 | "socks5://socks_proxy:1080", |
| 8880 | "http://www.example.org/socks5_direct", |
| 8881 | "socks5/www.example.org:80", |
| 8882 | false, |
| 8883 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8884 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8885 | // SSL Tests |
| 8886 | { |
| 8887 | "socks4://socks_proxy:1080", |
| 8888 | "https://www.example.org/socks4_ssl", |
| 8889 | "socks4/ssl/www.example.org:443", |
| 8890 | true, |
| 8891 | }, |
| 8892 | { |
| 8893 | "socks5://socks_proxy:1080", |
| 8894 | "https://www.example.org/socks5_ssl", |
| 8895 | "socks5/ssl/www.example.org:443", |
| 8896 | true, |
| 8897 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8898 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8899 | { |
| 8900 | "socks4://socks_proxy:1080", |
| 8901 | "http://host.with.alternate/direct", |
| 8902 | "socks4/ssl/host.with.alternate:443", |
| 8903 | true, |
| 8904 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8905 | }; |
| 8906 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8907 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8908 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8909 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8910 | session_deps_.proxy_service = |
| 8911 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8912 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8913 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8914 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8915 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8916 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8917 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8918 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8919 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8920 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8921 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8922 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8923 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8924 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8925 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8926 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8927 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8928 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8929 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8930 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8931 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8932 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8933 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8934 | if (tests[i].ssl) |
| 8935 | EXPECT_EQ(tests[i].expected_group_name, |
| 8936 | ssl_conn_pool->last_group_name_received()); |
| 8937 | else |
| 8938 | EXPECT_EQ(tests[i].expected_group_name, |
| 8939 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8940 | } |
| 8941 | } |
| 8942 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8943 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8944 | HttpRequestInfo request; |
| 8945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8946 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8947 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8948 | session_deps_.proxy_service = |
| 8949 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8950 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8951 | // This simulates failure resolving all hostnames; that means we will fail |
| 8952 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8953 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8954 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8955 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8956 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8957 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8959 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8961 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8962 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8963 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8964 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8965 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8966 | } |
| 8967 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8968 | // Base test to make sure that when the load flags for a request specify to |
| 8969 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8970 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8971 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8972 | // Issue a request, asking to bypass the cache(s). |
| 8973 | HttpRequestInfo request; |
| 8974 | request.method = "GET"; |
| 8975 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8977 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8978 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8979 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8980 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8981 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8982 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8984 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8985 | // Warm up the host cache so it has an entry for "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8986 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8987 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8988 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8989 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8990 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8991 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8992 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8993 | EXPECT_EQ(OK, rv); |
| 8994 | |
| 8995 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8996 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8997 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8998 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8999 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9000 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9001 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9002 | // Inject a failure the next time that "www.example.org" is resolved. This way |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9003 | // we can tell if the next lookup hit the cache, or the "network". |
| 9004 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9005 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9006 | |
| 9007 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9008 | // 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] | 9009 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9010 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9012 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9013 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9014 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9015 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9016 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9017 | |
| 9018 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9019 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9020 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 9021 | } |
| 9022 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9023 | // There are multiple load flags that should trigger the host cache bypass. |
| 9024 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9025 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9026 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9027 | } |
| 9028 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9029 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9030 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9031 | } |
| 9032 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9033 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9034 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9035 | } |
| 9036 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9037 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9038 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9039 | HttpRequestInfo request; |
| 9040 | request.method = "GET"; |
| 9041 | request.url = GURL("http://www.foo.com/"); |
| 9042 | request.load_flags = 0; |
| 9043 | |
| 9044 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9045 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9046 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9047 | StaticSocketDataProvider data(NULL, 0, |
| 9048 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9050 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9052 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9053 | |
| 9054 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9057 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9059 | |
| 9060 | rv = callback.WaitForResult(); |
| 9061 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9062 | |
| 9063 | IPEndPoint endpoint; |
| 9064 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9065 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9066 | } |
| 9067 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9068 | // Check that a connection closed after the start of the headers finishes ok. |
| 9069 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9070 | HttpRequestInfo request; |
| 9071 | request.method = "GET"; |
| 9072 | request.url = GURL("http://www.foo.com/"); |
| 9073 | request.load_flags = 0; |
| 9074 | |
| 9075 | MockRead data_reads[] = { |
| 9076 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9077 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9078 | }; |
| 9079 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9080 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9082 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9084 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9085 | |
| 9086 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9087 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9089 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9090 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9091 | |
| 9092 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9093 | EXPECT_EQ(OK, rv); |
| 9094 | |
| 9095 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9096 | ASSERT_TRUE(response != NULL); |
| 9097 | |
| 9098 | EXPECT_TRUE(response->headers.get() != NULL); |
| 9099 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9100 | |
| 9101 | std::string response_data; |
| 9102 | rv = ReadTransaction(trans.get(), &response_data); |
| 9103 | EXPECT_EQ(OK, rv); |
| 9104 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9105 | |
| 9106 | IPEndPoint endpoint; |
| 9107 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9108 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9109 | } |
| 9110 | |
| 9111 | // Make sure that a dropped connection while draining the body for auth |
| 9112 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9113 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9114 | HttpRequestInfo request; |
| 9115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9116 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9117 | request.load_flags = 0; |
| 9118 | |
| 9119 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9120 | MockWrite( |
| 9121 | "GET / HTTP/1.1\r\n" |
| 9122 | "Host: www.example.org\r\n" |
| 9123 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9124 | }; |
| 9125 | |
| 9126 | MockRead data_reads1[] = { |
| 9127 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9128 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9129 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9130 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9131 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9132 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9133 | }; |
| 9134 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9135 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9136 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9137 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9138 | |
| 9139 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9140 | // be issuing -- the final header line contains the credentials. |
| 9141 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9142 | MockWrite( |
| 9143 | "GET / HTTP/1.1\r\n" |
| 9144 | "Host: www.example.org\r\n" |
| 9145 | "Connection: keep-alive\r\n" |
| 9146 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9147 | }; |
| 9148 | |
| 9149 | // Lastly, the server responds with the actual content. |
| 9150 | MockRead data_reads2[] = { |
| 9151 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9152 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9153 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9154 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9155 | }; |
| 9156 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9157 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9158 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9159 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9160 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9162 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9163 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9164 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9165 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9167 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9168 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9169 | |
| 9170 | rv = callback1.WaitForResult(); |
| 9171 | EXPECT_EQ(OK, rv); |
| 9172 | |
| 9173 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9174 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9175 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9177 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9179 | rv = trans->RestartWithAuth( |
| 9180 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9182 | |
| 9183 | rv = callback2.WaitForResult(); |
| 9184 | EXPECT_EQ(OK, rv); |
| 9185 | |
| 9186 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9187 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9188 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9189 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9190 | } |
| 9191 | |
| 9192 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9193 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9194 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9195 | |
| 9196 | HttpRequestInfo request; |
| 9197 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9198 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9199 | request.load_flags = 0; |
| 9200 | |
| 9201 | MockRead proxy_reads[] = { |
| 9202 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9203 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9204 | }; |
| 9205 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9206 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9207 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9208 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9209 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9212 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9213 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9214 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9215 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9216 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9217 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9218 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9220 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9221 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9222 | |
| 9223 | rv = callback.WaitForResult(); |
| 9224 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9225 | } |
| 9226 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9227 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9228 | HttpRequestInfo request; |
| 9229 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9230 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9231 | request.load_flags = 0; |
| 9232 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9233 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9234 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9236 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9237 | MockRead data_reads[] = { |
| 9238 | 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] | 9239 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9240 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9241 | |
| 9242 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9245 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9247 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9249 | |
| 9250 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9251 | |
| 9252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9253 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9254 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9255 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9256 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9257 | |
| 9258 | std::string response_data; |
| 9259 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9260 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9261 | } |
| 9262 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9263 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9264 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9265 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9266 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9267 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9268 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9269 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9270 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9271 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9272 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, |
| 9273 | base::Time()))); |
| 9274 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9275 | |
| 9276 | HttpRequestInfo request; |
| 9277 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9278 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9279 | request.upload_data_stream = &upload_data_stream; |
| 9280 | request.load_flags = 0; |
| 9281 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9282 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9283 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9284 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9285 | |
| 9286 | MockRead data_reads[] = { |
| 9287 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9288 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9289 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9290 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9291 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9294 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9296 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9297 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9298 | |
| 9299 | rv = callback.WaitForResult(); |
| 9300 | EXPECT_EQ(OK, rv); |
| 9301 | |
| 9302 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9303 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9304 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9305 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9306 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9307 | |
| 9308 | std::string response_data; |
| 9309 | rv = ReadTransaction(trans.get(), &response_data); |
| 9310 | EXPECT_EQ(OK, rv); |
| 9311 | EXPECT_EQ("hello world", response_data); |
| 9312 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9313 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9314 | } |
| 9315 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9316 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9317 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9318 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9319 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9320 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9321 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9322 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9323 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9324 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9325 | element_readers.push_back(make_scoped_ptr( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9326 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9327 | temp_file, 0, kuint64max, base::Time()))); |
| 9328 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9329 | |
| 9330 | HttpRequestInfo request; |
| 9331 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9333 | request.upload_data_stream = &upload_data_stream; |
| 9334 | request.load_flags = 0; |
| 9335 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9336 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9337 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9338 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9339 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9340 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9341 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9342 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9344 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9347 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9348 | |
| 9349 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9350 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9351 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9352 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9353 | } |
| 9354 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9355 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9356 | class FakeUploadElementReader : public UploadElementReader { |
| 9357 | public: |
| 9358 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9359 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9360 | |
| 9361 | const CompletionCallback& callback() const { return callback_; } |
| 9362 | |
| 9363 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9364 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9365 | callback_ = callback; |
| 9366 | return ERR_IO_PENDING; |
| 9367 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9368 | uint64 GetContentLength() const override { return 0; } |
| 9369 | uint64 BytesRemaining() const override { return 0; } |
| 9370 | int Read(IOBuffer* buf, |
| 9371 | int buf_length, |
| 9372 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9373 | return ERR_FAILED; |
| 9374 | } |
| 9375 | |
| 9376 | private: |
| 9377 | CompletionCallback callback_; |
| 9378 | }; |
| 9379 | |
| 9380 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9381 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9382 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9383 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9384 | |
| 9385 | HttpRequestInfo request; |
| 9386 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9387 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9388 | request.upload_data_stream = &upload_data_stream; |
| 9389 | request.load_flags = 0; |
| 9390 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9391 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9392 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9393 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9394 | |
| 9395 | StaticSocketDataProvider data; |
| 9396 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9397 | |
| 9398 | TestCompletionCallback callback; |
| 9399 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9401 | base::MessageLoop::current()->RunUntilIdle(); |
| 9402 | |
| 9403 | // Transaction is pending on request body initialization. |
| 9404 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9405 | |
| 9406 | // Return Init()'s result after the transaction gets destroyed. |
| 9407 | trans.reset(); |
| 9408 | fake_reader->callback().Run(OK); // Should not crash. |
| 9409 | } |
| 9410 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9411 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9412 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9413 | HttpRequestInfo request; |
| 9414 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9415 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9416 | request.load_flags = 0; |
| 9417 | |
| 9418 | // First transaction will request a resource and receive a Basic challenge |
| 9419 | // with realm="first_realm". |
| 9420 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9421 | MockWrite( |
| 9422 | "GET / HTTP/1.1\r\n" |
| 9423 | "Host: www.example.org\r\n" |
| 9424 | "Connection: keep-alive\r\n" |
| 9425 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9426 | }; |
| 9427 | MockRead data_reads1[] = { |
| 9428 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9429 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9430 | "\r\n"), |
| 9431 | }; |
| 9432 | |
| 9433 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9434 | // for first_realm. The server will reject and provide a challenge with |
| 9435 | // second_realm. |
| 9436 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9437 | MockWrite( |
| 9438 | "GET / HTTP/1.1\r\n" |
| 9439 | "Host: www.example.org\r\n" |
| 9440 | "Connection: keep-alive\r\n" |
| 9441 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9442 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9443 | }; |
| 9444 | MockRead data_reads2[] = { |
| 9445 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9446 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9447 | "\r\n"), |
| 9448 | }; |
| 9449 | |
| 9450 | // This again fails, and goes back to first_realm. Make sure that the |
| 9451 | // entry is removed from cache. |
| 9452 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9453 | MockWrite( |
| 9454 | "GET / HTTP/1.1\r\n" |
| 9455 | "Host: www.example.org\r\n" |
| 9456 | "Connection: keep-alive\r\n" |
| 9457 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9458 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9459 | }; |
| 9460 | MockRead data_reads3[] = { |
| 9461 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9462 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9463 | "\r\n"), |
| 9464 | }; |
| 9465 | |
| 9466 | // Try one last time (with the correct password) and get the resource. |
| 9467 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9468 | MockWrite( |
| 9469 | "GET / HTTP/1.1\r\n" |
| 9470 | "Host: www.example.org\r\n" |
| 9471 | "Connection: keep-alive\r\n" |
| 9472 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9473 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9474 | }; |
| 9475 | MockRead data_reads4[] = { |
| 9476 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9477 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9478 | "Content-Length: 5\r\n" |
| 9479 | "\r\n" |
| 9480 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9481 | }; |
| 9482 | |
| 9483 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9484 | data_writes1, arraysize(data_writes1)); |
| 9485 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9486 | data_writes2, arraysize(data_writes2)); |
| 9487 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9488 | data_writes3, arraysize(data_writes3)); |
| 9489 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9490 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9491 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9492 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9493 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9494 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9496 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9497 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9498 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9499 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9501 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9502 | // Issue the first request with Authorize headers. There should be a |
| 9503 | // password prompt for first_realm waiting to be filled in after the |
| 9504 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9505 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9507 | rv = callback1.WaitForResult(); |
| 9508 | EXPECT_EQ(OK, rv); |
| 9509 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9510 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9511 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9512 | ASSERT_FALSE(challenge == NULL); |
| 9513 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9514 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9515 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9516 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9517 | |
| 9518 | // Issue the second request with an incorrect password. There should be a |
| 9519 | // password prompt for second_realm waiting to be filled in after the |
| 9520 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9521 | TestCompletionCallback callback2; |
| 9522 | rv = trans->RestartWithAuth( |
| 9523 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9525 | rv = callback2.WaitForResult(); |
| 9526 | EXPECT_EQ(OK, rv); |
| 9527 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9528 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9529 | challenge = response->auth_challenge.get(); |
| 9530 | ASSERT_FALSE(challenge == NULL); |
| 9531 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9532 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9533 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9534 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9535 | |
| 9536 | // Issue the third request with another incorrect password. There should be |
| 9537 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9538 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9539 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9540 | TestCompletionCallback callback3; |
| 9541 | rv = trans->RestartWithAuth( |
| 9542 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9543 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9544 | rv = callback3.WaitForResult(); |
| 9545 | EXPECT_EQ(OK, rv); |
| 9546 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9547 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9548 | challenge = response->auth_challenge.get(); |
| 9549 | ASSERT_FALSE(challenge == NULL); |
| 9550 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9551 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9552 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9553 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9554 | |
| 9555 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9556 | TestCompletionCallback callback4; |
| 9557 | rv = trans->RestartWithAuth( |
| 9558 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9559 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9560 | rv = callback4.WaitForResult(); |
| 9561 | EXPECT_EQ(OK, rv); |
| 9562 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9563 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9564 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9565 | } |
| 9566 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9567 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 9568 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9569 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9570 | |
| 9571 | std::string alternative_service_http_header = |
| 9572 | GetAlternativeServiceHttpHeader(); |
| 9573 | |
| 9574 | MockRead data_reads[] = { |
| 9575 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9576 | MockRead(alternative_service_http_header.c_str()), |
| 9577 | MockRead("\r\n"), |
| 9578 | MockRead("hello world"), |
| 9579 | MockRead(SYNCHRONOUS, OK), |
| 9580 | }; |
| 9581 | |
| 9582 | HttpRequestInfo request; |
| 9583 | request.method = "GET"; |
| 9584 | request.url = GURL("http://www.example.org/"); |
| 9585 | request.load_flags = 0; |
| 9586 | |
| 9587 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9588 | |
| 9589 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9590 | |
| 9591 | TestCompletionCallback callback; |
| 9592 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9593 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9594 | scoped_ptr<HttpTransaction> trans( |
| 9595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9596 | |
| 9597 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9598 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9599 | |
| 9600 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9601 | HttpServerProperties& http_server_properties = |
| 9602 | *session->http_server_properties(); |
| 9603 | AlternativeServiceVector alternative_service_vector = |
| 9604 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9605 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9606 | |
| 9607 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9608 | |
| 9609 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9610 | ASSERT_TRUE(response != NULL); |
| 9611 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9612 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9613 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9614 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9615 | |
| 9616 | std::string response_data; |
| 9617 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9618 | EXPECT_EQ("hello world", response_data); |
| 9619 | |
| 9620 | alternative_service_vector = |
| 9621 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9622 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9623 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9624 | alternative_service_vector[0].protocol); |
| 9625 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9626 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9627 | } |
| 9628 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9629 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
| 9630 | session_deps_.next_protos = SpdyNextProtos(); |
| 9631 | session_deps_.use_alternative_services = true; |
| 9632 | |
| 9633 | // Set an alternative service for origin. |
| 9634 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9635 | HttpServerProperties& http_server_properties = |
| 9636 | *session->http_server_properties(); |
| 9637 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9638 | AlternativeService alternative_service(QUIC, "", 80); |
| 9639 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9640 | http_server_properties.SetAlternativeService( |
| 9641 | http_host_port_pair, alternative_service, 1.0, expiration); |
| 9642 | AlternativeServiceVector alternative_service_vector = |
| 9643 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9644 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9645 | |
| 9646 | // Send a clear header. |
| 9647 | MockRead data_reads[] = { |
| 9648 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9649 | MockRead("Alt-Svc: clear\r\n"), |
| 9650 | MockRead("\r\n"), |
| 9651 | MockRead("hello world"), |
| 9652 | MockRead(SYNCHRONOUS, OK), |
| 9653 | }; |
| 9654 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9655 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9656 | |
| 9657 | HttpRequestInfo request; |
| 9658 | request.method = "GET"; |
| 9659 | request.url = GURL("http://www.example.org/"); |
| 9660 | request.load_flags = 0; |
| 9661 | |
| 9662 | TestCompletionCallback callback; |
| 9663 | |
| 9664 | scoped_ptr<HttpTransaction> trans( |
| 9665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9666 | |
| 9667 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9668 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9669 | |
| 9670 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9671 | ASSERT_TRUE(response != nullptr); |
| 9672 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9673 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9674 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9675 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9676 | |
| 9677 | std::string response_data; |
| 9678 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9679 | EXPECT_EQ("hello world", response_data); |
| 9680 | |
| 9681 | alternative_service_vector = |
| 9682 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9683 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9684 | } |
| 9685 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9686 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9687 | // is false. |
| 9688 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9689 | session_deps_.next_protos = SpdyNextProtos(); |
| 9690 | session_deps_.use_alternative_services = false; |
| 9691 | |
| 9692 | std::string alternative_service_http_header = |
| 9693 | GetAlternativeServiceHttpHeader(); |
| 9694 | |
| 9695 | MockRead data_reads[] = { |
| 9696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9697 | MockRead(alternative_service_http_header.c_str()), |
| 9698 | MockRead("\r\n"), |
| 9699 | MockRead("hello world"), |
| 9700 | MockRead(SYNCHRONOUS, OK), |
| 9701 | }; |
| 9702 | |
| 9703 | HttpRequestInfo request; |
| 9704 | request.method = "GET"; |
| 9705 | request.url = GURL("http://www.example.org/"); |
| 9706 | request.load_flags = 0; |
| 9707 | |
| 9708 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9709 | |
| 9710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9711 | |
| 9712 | TestCompletionCallback callback; |
| 9713 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9714 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9715 | scoped_ptr<HttpTransaction> trans( |
| 9716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9717 | |
| 9718 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9719 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9720 | |
| 9721 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9722 | HttpServerProperties& http_server_properties = |
| 9723 | *session->http_server_properties(); |
| 9724 | AlternativeServiceVector alternative_service_vector = |
| 9725 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9726 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9727 | |
| 9728 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9729 | |
| 9730 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9731 | ASSERT_TRUE(response != nullptr); |
| 9732 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9733 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9734 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9735 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9736 | |
| 9737 | std::string response_data; |
| 9738 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9739 | EXPECT_EQ("hello world", response_data); |
| 9740 | |
| 9741 | alternative_service_vector = |
| 9742 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9743 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9744 | } |
| 9745 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9746 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9747 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9748 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9749 | |
| 9750 | MockRead data_reads[] = { |
| 9751 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9752 | MockRead("Alt-Svc: "), |
| 9753 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9754 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9755 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9756 | MockRead("hello world"), |
| 9757 | MockRead(SYNCHRONOUS, OK), |
| 9758 | }; |
| 9759 | |
| 9760 | HttpRequestInfo request; |
| 9761 | request.method = "GET"; |
| 9762 | request.url = GURL("http://www.example.org/"); |
| 9763 | request.load_flags = 0; |
| 9764 | |
| 9765 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9766 | |
| 9767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9768 | |
| 9769 | TestCompletionCallback callback; |
| 9770 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9771 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9772 | scoped_ptr<HttpTransaction> trans( |
| 9773 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9774 | |
| 9775 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9776 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9777 | |
| 9778 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9779 | HttpServerProperties& http_server_properties = |
| 9780 | *session->http_server_properties(); |
| 9781 | AlternativeServiceVector alternative_service_vector = |
| 9782 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9783 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9784 | |
| 9785 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9786 | |
| 9787 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9788 | ASSERT_TRUE(response != NULL); |
| 9789 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9790 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9791 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9792 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9793 | |
| 9794 | std::string response_data; |
| 9795 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9796 | EXPECT_EQ("hello world", response_data); |
| 9797 | |
| 9798 | alternative_service_vector = |
| 9799 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9800 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9801 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9802 | alternative_service_vector[0].protocol); |
| 9803 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9804 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9805 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9806 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9807 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9808 | } |
| 9809 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9810 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9811 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9812 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9813 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9814 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9815 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9816 | std::string alternate_protocol_http_header = |
| 9817 | GetAlternateProtocolHttpHeader(); |
| 9818 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9819 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9821 | MockRead(alternate_protocol_http_header.c_str()), |
| 9822 | MockRead("\r\n"), |
| 9823 | MockRead("hello world"), |
| 9824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9825 | }; |
| 9826 | |
| 9827 | HttpRequestInfo request; |
| 9828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9830 | request.load_flags = 0; |
| 9831 | |
| 9832 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9833 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9836 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9837 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9838 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9839 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9842 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9844 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9845 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9846 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9847 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9848 | AlternativeServiceVector alternative_service_vector = |
| 9849 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9850 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9851 | |
| 9852 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9853 | |
| 9854 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9855 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9856 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9857 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9858 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9859 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9860 | |
| 9861 | std::string response_data; |
| 9862 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9863 | EXPECT_EQ("hello world", response_data); |
| 9864 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9865 | alternative_service_vector = |
| 9866 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9867 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9868 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9869 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9870 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9871 | } |
| 9872 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9873 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9874 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9875 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9876 | |
| 9877 | MockRead data_reads[] = { |
| 9878 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9879 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9880 | MockRead("hello world"), |
| 9881 | MockRead(SYNCHRONOUS, OK), |
| 9882 | }; |
| 9883 | |
| 9884 | HttpRequestInfo request; |
| 9885 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9886 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9887 | request.load_flags = 0; |
| 9888 | |
| 9889 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9890 | |
| 9891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9892 | |
| 9893 | TestCompletionCallback callback; |
| 9894 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9895 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9896 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9897 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9898 | HttpServerProperties& http_server_properties = |
| 9899 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9900 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9901 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9902 | http_server_properties.SetAlternativeService( |
| 9903 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9904 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9905 | AlternativeServiceVector alternative_service_vector = |
| 9906 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9907 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9908 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9909 | |
| 9910 | scoped_ptr<HttpTransaction> trans( |
| 9911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9912 | |
| 9913 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9914 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9915 | |
| 9916 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9917 | |
| 9918 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9919 | ASSERT_TRUE(response != NULL); |
| 9920 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9921 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9922 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9923 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9924 | |
| 9925 | std::string response_data; |
| 9926 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9927 | EXPECT_EQ("hello world", response_data); |
| 9928 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9929 | alternative_service_vector = |
| 9930 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9931 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9932 | } |
| 9933 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9934 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9935 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9936 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9937 | |
| 9938 | std::string alternative_service_http_header = |
| 9939 | GetAlternativeServiceHttpHeader(); |
| 9940 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9941 | |
| 9942 | MockRead data_reads[] = { |
| 9943 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9944 | MockRead(alternative_service_http_header.c_str()), |
| 9945 | MockRead(alternate_protocol_http_header.c_str()), |
| 9946 | MockRead("\r\n"), |
| 9947 | MockRead("hello world"), |
| 9948 | MockRead(SYNCHRONOUS, OK), |
| 9949 | }; |
| 9950 | |
| 9951 | HttpRequestInfo request; |
| 9952 | request.method = "GET"; |
| 9953 | request.url = GURL("http://www.example.org/"); |
| 9954 | request.load_flags = 0; |
| 9955 | |
| 9956 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9957 | |
| 9958 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9959 | |
| 9960 | TestCompletionCallback callback; |
| 9961 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9962 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9963 | scoped_ptr<HttpTransaction> trans( |
| 9964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9965 | |
| 9966 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9968 | |
| 9969 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9970 | HttpServerProperties& http_server_properties = |
| 9971 | *session->http_server_properties(); |
| 9972 | AlternativeServiceVector alternative_service_vector = |
| 9973 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9974 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9975 | |
| 9976 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9977 | |
| 9978 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9979 | ASSERT_TRUE(response != NULL); |
| 9980 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9981 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9982 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9983 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9984 | |
| 9985 | std::string response_data; |
| 9986 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9987 | EXPECT_EQ("hello world", response_data); |
| 9988 | |
| 9989 | alternative_service_vector = |
| 9990 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9991 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9992 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9993 | alternative_service_vector[0].protocol); |
| 9994 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9995 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9996 | } |
| 9997 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9998 | // When |use_alternative_services| is false, do not observe alternative service |
| 9999 | // entries that point to a different host. |
| 10000 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 10001 | session_deps_.use_alternative_services = false; |
| 10002 | |
| 10003 | HttpRequestInfo request; |
| 10004 | request.method = "GET"; |
| 10005 | request.url = GURL("http://www.example.org/"); |
| 10006 | request.load_flags = 0; |
| 10007 | |
| 10008 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10009 | StaticSocketDataProvider first_data; |
| 10010 | first_data.set_connect_data(mock_connect); |
| 10011 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10012 | |
| 10013 | MockRead data_reads[] = { |
| 10014 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10015 | MockRead(ASYNC, OK), |
| 10016 | }; |
| 10017 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 10018 | nullptr, 0); |
| 10019 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10020 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10021 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10022 | |
| 10023 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10024 | session->http_server_properties(); |
| 10025 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10026 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10027 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10028 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10029 | http_server_properties->SetAlternativeService( |
| 10030 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 10031 | |
| 10032 | scoped_ptr<HttpTransaction> trans( |
| 10033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10034 | TestCompletionCallback callback; |
| 10035 | |
| 10036 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10037 | // The connetion to origin was refused, and the alternative service should not |
| 10038 | // be used (even though mock data are there), therefore the request should |
| 10039 | // fail. |
| 10040 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10041 | } |
| 10042 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10043 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
| 10044 | HostPortPair origin("origin.example.org", 443); |
| 10045 | HostPortPair alternative("alternative.example.org", 443); |
| 10046 | std::string origin_url = "https://origin.example.org:443"; |
| 10047 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10048 | |
| 10049 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10050 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10051 | ssl.SetNextProto(kProtoHTTP11); |
| 10052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10053 | |
| 10054 | // HTTP/1.1 data for request. |
| 10055 | MockWrite http_writes[] = { |
| 10056 | MockWrite("GET / HTTP/1.1\r\n" |
| 10057 | "Host: alternative.example.org\r\n" |
| 10058 | "Connection: keep-alive\r\n\r\n"), |
| 10059 | }; |
| 10060 | |
| 10061 | MockRead http_reads[] = { |
| 10062 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10063 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10064 | "Content-Length: 40\r\n\r\n" |
| 10065 | "first HTTP/1.1 response from alternative"), |
| 10066 | }; |
| 10067 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10068 | http_writes, arraysize(http_writes)); |
| 10069 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10070 | |
| 10071 | StaticSocketDataProvider data_refused; |
| 10072 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10073 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10074 | |
| 10075 | // Set up a QUIC alternative service for origin. |
| 10076 | session_deps_.use_alternative_services = true; |
| 10077 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10078 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10079 | session->http_server_properties(); |
| 10080 | AlternativeService alternative_service(QUIC, alternative); |
| 10081 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10082 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 10083 | 1.0, expiration); |
| 10084 | // Mark the QUIC alternative service as broken. |
| 10085 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10086 | |
| 10087 | scoped_ptr<HttpTransaction> trans( |
| 10088 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10089 | HttpRequestInfo request; |
| 10090 | request.method = "GET"; |
| 10091 | request.url = GURL(origin_url); |
| 10092 | request.load_flags = 0; |
| 10093 | TestCompletionCallback callback; |
| 10094 | NetErrorDetails details; |
| 10095 | EXPECT_FALSE(details.quic_broken); |
| 10096 | |
| 10097 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10098 | trans->PopulateNetErrorDetails(&details); |
| 10099 | EXPECT_TRUE(details.quic_broken); |
| 10100 | } |
| 10101 | |
| 10102 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
| 10103 | HostPortPair origin("origin.example.org", 443); |
| 10104 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10105 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10106 | std::string origin_url = "https://origin.example.org:443"; |
| 10107 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10108 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10109 | |
| 10110 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10111 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10112 | ssl.SetNextProto(kProtoHTTP11); |
| 10113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10114 | |
| 10115 | // HTTP/1.1 data for request. |
| 10116 | MockWrite http_writes[] = { |
| 10117 | MockWrite("GET / HTTP/1.1\r\n" |
| 10118 | "Host: alternative1.example.org\r\n" |
| 10119 | "Connection: keep-alive\r\n\r\n"), |
| 10120 | }; |
| 10121 | |
| 10122 | MockRead http_reads[] = { |
| 10123 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10124 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10125 | "Content-Length: 40\r\n\r\n" |
| 10126 | "first HTTP/1.1 response from alternative1"), |
| 10127 | }; |
| 10128 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10129 | http_writes, arraysize(http_writes)); |
| 10130 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10131 | |
| 10132 | StaticSocketDataProvider data_refused; |
| 10133 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10134 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10135 | |
| 10136 | session_deps_.use_alternative_services = true; |
| 10137 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10138 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10139 | session->http_server_properties(); |
| 10140 | |
| 10141 | // Set up two QUIC alternative services for origin. |
| 10142 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10143 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10144 | |
| 10145 | AlternativeService alternative_service1(QUIC, alternative1); |
| 10146 | AlternativeServiceInfo alternative_service_info1(alternative_service1, 1.0, |
| 10147 | expiration); |
| 10148 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10149 | AlternativeService alternative_service2(QUIC, alternative2); |
| 10150 | AlternativeServiceInfo alternative_service_info2(alternative_service2, 1.0, |
| 10151 | expiration); |
| 10152 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10153 | |
| 10154 | http_server_properties->SetAlternativeServices( |
| 10155 | origin, alternative_service_info_vector); |
| 10156 | |
| 10157 | // Mark one of the QUIC alternative service as broken. |
| 10158 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10159 | |
| 10160 | const AlternativeServiceVector alternative_service_vector = |
| 10161 | http_server_properties->GetAlternativeServices(origin); |
| 10162 | |
| 10163 | scoped_ptr<HttpTransaction> trans( |
| 10164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10165 | HttpRequestInfo request; |
| 10166 | request.method = "GET"; |
| 10167 | request.url = GURL(origin_url); |
| 10168 | request.load_flags = 0; |
| 10169 | TestCompletionCallback callback; |
| 10170 | NetErrorDetails details; |
| 10171 | EXPECT_FALSE(details.quic_broken); |
| 10172 | |
| 10173 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10174 | trans->PopulateNetErrorDetails(&details); |
| 10175 | EXPECT_FALSE(details.quic_broken); |
| 10176 | } |
| 10177 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10178 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10179 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10180 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10181 | |
| 10182 | HttpRequestInfo request; |
| 10183 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10184 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10185 | request.load_flags = 0; |
| 10186 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10187 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10188 | StaticSocketDataProvider first_data; |
| 10189 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10190 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10191 | |
| 10192 | MockRead data_reads[] = { |
| 10193 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10194 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10195 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10196 | }; |
| 10197 | StaticSocketDataProvider second_data( |
| 10198 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10199 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10200 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10201 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10202 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10203 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10204 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 10205 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10206 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10207 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10208 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10209 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10210 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10211 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10212 | http_server_properties->SetAlternativeService( |
| 10213 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10214 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10215 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10216 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10217 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10219 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10220 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10221 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10222 | |
| 10223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10224 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10225 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10226 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10227 | |
| 10228 | std::string response_data; |
| 10229 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10230 | EXPECT_EQ("hello world", response_data); |
| 10231 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10232 | const AlternativeServiceVector alternative_service_vector = |
| 10233 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 10234 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10235 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10236 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10237 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10238 | } |
| 10239 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10240 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10241 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10242 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10243 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10244 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10245 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10246 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10247 | |
| 10248 | HttpRequestInfo restricted_port_request; |
| 10249 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10250 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10251 | restricted_port_request.load_flags = 0; |
| 10252 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10253 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10254 | StaticSocketDataProvider first_data; |
| 10255 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10256 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10257 | |
| 10258 | MockRead data_reads[] = { |
| 10259 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10260 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10261 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10262 | }; |
| 10263 | StaticSocketDataProvider second_data( |
| 10264 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10265 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10266 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10267 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10268 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10269 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10270 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10271 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10272 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10273 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10274 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10275 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10276 | http_server_properties->SetAlternativeService( |
| 10277 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10278 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10279 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10280 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10282 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10284 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10285 | &restricted_port_request, |
| 10286 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10287 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10288 | // Invalid change to unrestricted port should fail. |
| 10289 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10290 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10291 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10292 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10293 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10294 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10295 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10296 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10297 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10298 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10299 | |
| 10300 | HttpRequestInfo restricted_port_request; |
| 10301 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10302 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10303 | restricted_port_request.load_flags = 0; |
| 10304 | |
| 10305 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10306 | StaticSocketDataProvider first_data; |
| 10307 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10308 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10309 | |
| 10310 | MockRead data_reads[] = { |
| 10311 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10312 | MockRead("hello world"), |
| 10313 | MockRead(ASYNC, OK), |
| 10314 | }; |
| 10315 | StaticSocketDataProvider second_data( |
| 10316 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10317 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10318 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10319 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10320 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10321 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10322 | session->http_server_properties(); |
| 10323 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10324 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10325 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10326 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10327 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10328 | http_server_properties->SetAlternativeService( |
| 10329 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10330 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10331 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10332 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10334 | TestCompletionCallback callback; |
| 10335 | |
| 10336 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10337 | &restricted_port_request, |
| 10338 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10339 | // Change to unrestricted port should succeed. |
| 10340 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10341 | } |
| 10342 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10343 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10344 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10345 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10346 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10347 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10348 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10349 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10350 | |
| 10351 | HttpRequestInfo restricted_port_request; |
| 10352 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10353 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10354 | restricted_port_request.load_flags = 0; |
| 10355 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10356 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10357 | StaticSocketDataProvider first_data; |
| 10358 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10359 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10360 | |
| 10361 | MockRead data_reads[] = { |
| 10362 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10363 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10364 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10365 | }; |
| 10366 | StaticSocketDataProvider second_data( |
| 10367 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10368 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10369 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10370 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10371 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10372 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10373 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10374 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10375 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10376 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10377 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10378 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10379 | http_server_properties->SetAlternativeService( |
| 10380 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10381 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10382 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10383 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10384 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10385 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10387 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10388 | &restricted_port_request, |
| 10389 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10391 | // Valid change to restricted port should pass. |
| 10392 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10393 | } |
| 10394 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10395 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10396 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10397 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10398 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10399 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10400 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10401 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10402 | |
| 10403 | HttpRequestInfo unrestricted_port_request; |
| 10404 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10405 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10406 | unrestricted_port_request.load_flags = 0; |
| 10407 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10408 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10409 | StaticSocketDataProvider first_data; |
| 10410 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10411 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10412 | |
| 10413 | MockRead data_reads[] = { |
| 10414 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10415 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10416 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10417 | }; |
| 10418 | StaticSocketDataProvider second_data( |
| 10419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10421 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10422 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10423 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10424 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10425 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10426 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10427 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10428 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10429 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10430 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10431 | http_server_properties->SetAlternativeService( |
| 10432 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10433 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10434 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10435 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10437 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10439 | int rv = trans->Start( |
| 10440 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10442 | // Valid change to restricted port should pass. |
| 10443 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10444 | } |
| 10445 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10446 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10447 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10448 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10449 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10450 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10451 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10452 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10453 | |
| 10454 | HttpRequestInfo unrestricted_port_request; |
| 10455 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10456 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10457 | unrestricted_port_request.load_flags = 0; |
| 10458 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10459 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10460 | StaticSocketDataProvider first_data; |
| 10461 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10462 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10463 | |
| 10464 | MockRead data_reads[] = { |
| 10465 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10466 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10467 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10468 | }; |
| 10469 | StaticSocketDataProvider second_data( |
| 10470 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10471 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10472 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10473 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10474 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10475 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10476 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10477 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10478 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10479 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10480 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10482 | http_server_properties->SetAlternativeService( |
| 10483 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10484 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10485 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10486 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10487 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10488 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10490 | int rv = trans->Start( |
| 10491 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10493 | // Valid change to an unrestricted port should pass. |
| 10494 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10495 | } |
| 10496 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10497 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10498 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10499 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10500 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10501 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10502 | |
| 10503 | HttpRequestInfo request; |
| 10504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10505 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10506 | request.load_flags = 0; |
| 10507 | |
| 10508 | // The alternate protocol request will error out before we attempt to connect, |
| 10509 | // so only the standard HTTP request will try to connect. |
| 10510 | MockRead data_reads[] = { |
| 10511 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10512 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10513 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10514 | }; |
| 10515 | StaticSocketDataProvider data( |
| 10516 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10518 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10519 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10520 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10521 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10522 | session->http_server_properties(); |
| 10523 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10524 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10525 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10526 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10527 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10528 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10529 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10530 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10531 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10532 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10533 | TestCompletionCallback callback; |
| 10534 | |
| 10535 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10536 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10537 | // The HTTP request should succeed. |
| 10538 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10539 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10540 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10541 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10542 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10543 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10544 | |
| 10545 | std::string response_data; |
| 10546 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10547 | EXPECT_EQ("hello world", response_data); |
| 10548 | } |
| 10549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10550 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10551 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10552 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10553 | |
| 10554 | HttpRequestInfo request; |
| 10555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10556 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10557 | request.load_flags = 0; |
| 10558 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10559 | std::string alternate_protocol_http_header = |
| 10560 | GetAlternateProtocolHttpHeader(); |
| 10561 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10562 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10563 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10564 | MockRead(alternate_protocol_http_header.c_str()), |
| 10565 | MockRead("\r\n"), |
| 10566 | MockRead("hello world"), |
| 10567 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10568 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10569 | |
| 10570 | StaticSocketDataProvider first_transaction( |
| 10571 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10573 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10574 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10575 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10576 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10577 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10579 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10580 | scoped_ptr<SpdyFrame> req( |
| 10581 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10582 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10583 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10584 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10585 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10586 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10587 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10588 | }; |
| 10589 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10590 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10591 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10592 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10593 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10594 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10595 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10596 | NULL, 0, NULL, 0); |
| 10597 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10598 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10599 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10600 | &hanging_non_alternate_protocol_socket); |
| 10601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10602 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10603 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10604 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10605 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10608 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10610 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10611 | |
| 10612 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10613 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10614 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10615 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10616 | |
| 10617 | std::string response_data; |
| 10618 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10619 | EXPECT_EQ("hello world", response_data); |
| 10620 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10621 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10623 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10624 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10625 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10626 | |
| 10627 | response = trans->GetResponseInfo(); |
| 10628 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10629 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10630 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10631 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10632 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10633 | |
| 10634 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10635 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10636 | } |
| 10637 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10638 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10639 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10640 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10641 | |
| 10642 | HttpRequestInfo request; |
| 10643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10644 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10645 | request.load_flags = 0; |
| 10646 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10647 | std::string alternate_protocol_http_header = |
| 10648 | GetAlternateProtocolHttpHeader(); |
| 10649 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10650 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10651 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10652 | MockRead(alternate_protocol_http_header.c_str()), |
| 10653 | MockRead("\r\n"), |
| 10654 | MockRead("hello world"), |
| 10655 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10656 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10657 | }; |
| 10658 | |
| 10659 | StaticSocketDataProvider first_transaction( |
| 10660 | data_reads, arraysize(data_reads), NULL, 0); |
| 10661 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10662 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10663 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10664 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10665 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10666 | hanging_socket1.set_connect_data(never_finishing_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10667 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10668 | // non-Alternate-Protocol jobs from the 2nd transaction. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10669 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10670 | |
| 10671 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10672 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10673 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10674 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10675 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10676 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10677 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10678 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10680 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10681 | scoped_ptr<SpdyFrame> req1( |
| 10682 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10683 | scoped_ptr<SpdyFrame> req2( |
| 10684 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10685 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10686 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10687 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10688 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10689 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10690 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10691 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10692 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10693 | CreateMockRead(*resp1, 2), |
| 10694 | CreateMockRead(*data1, 3), |
| 10695 | CreateMockRead(*resp2, 4), |
| 10696 | CreateMockRead(*data2, 5), |
| 10697 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10698 | }; |
| 10699 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10700 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10701 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10702 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10703 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10704 | |
| 10705 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10706 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10707 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10708 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10709 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10711 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10712 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10714 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10715 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10716 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10717 | |
| 10718 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10719 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10720 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10721 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10722 | |
| 10723 | std::string response_data; |
| 10724 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10725 | EXPECT_EQ("hello world", response_data); |
| 10726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10727 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10728 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10729 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10732 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10733 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10734 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10735 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10736 | |
| 10737 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10738 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10739 | |
| 10740 | response = trans2.GetResponseInfo(); |
| 10741 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10742 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10743 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10744 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10745 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10746 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10747 | EXPECT_EQ("hello!", response_data); |
| 10748 | |
| 10749 | response = trans3.GetResponseInfo(); |
| 10750 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10751 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10752 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10753 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10754 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10755 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10756 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10757 | } |
| 10758 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10759 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10760 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10761 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10762 | |
| 10763 | HttpRequestInfo request; |
| 10764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10766 | request.load_flags = 0; |
| 10767 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10768 | std::string alternate_protocol_http_header = |
| 10769 | GetAlternateProtocolHttpHeader(); |
| 10770 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10771 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10772 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10773 | MockRead(alternate_protocol_http_header.c_str()), |
| 10774 | MockRead("\r\n"), |
| 10775 | MockRead("hello world"), |
| 10776 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10777 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10778 | }; |
| 10779 | |
| 10780 | StaticSocketDataProvider first_transaction( |
| 10781 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10782 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10783 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10784 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10785 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10787 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10788 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10789 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10790 | NULL, 0, NULL, 0); |
| 10791 | hanging_alternate_protocol_socket.set_connect_data( |
| 10792 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10793 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10794 | &hanging_alternate_protocol_socket); |
| 10795 | |
| 10796 | // 2nd request is just a copy of the first one, over HTTP again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10797 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10798 | NULL, 0); |
| 10799 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10800 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10801 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10802 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10803 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10804 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10805 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10807 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10809 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10810 | |
| 10811 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10812 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10813 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10814 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10815 | |
| 10816 | std::string response_data; |
| 10817 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10818 | EXPECT_EQ("hello world", response_data); |
| 10819 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10820 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10822 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10824 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10825 | |
| 10826 | response = trans->GetResponseInfo(); |
| 10827 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10828 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10829 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10830 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10831 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10832 | |
| 10833 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10834 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10835 | } |
| 10836 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10837 | class CapturingProxyResolver : public ProxyResolver { |
| 10838 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10839 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10840 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10841 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10842 | int GetProxyForURL(const GURL& url, |
| 10843 | ProxyInfo* results, |
| 10844 | const CompletionCallback& callback, |
| 10845 | RequestHandle* request, |
| 10846 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10847 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10848 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10849 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10850 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10851 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10852 | } |
| 10853 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10854 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10855 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10856 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10857 | NOTREACHED(); |
| 10858 | return LOAD_STATE_IDLE; |
| 10859 | } |
| 10860 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10861 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10862 | |
| 10863 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10864 | std::vector<GURL> resolved_; |
| 10865 | |
| 10866 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10867 | }; |
| 10868 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10869 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10870 | public: |
| 10871 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10872 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10873 | |
| 10874 | int CreateProxyResolver( |
| 10875 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10876 | scoped_ptr<ProxyResolver>* resolver, |
| 10877 | const net::CompletionCallback& callback, |
| 10878 | scoped_ptr<Request>* request) override { |
| 10879 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10880 | return OK; |
| 10881 | } |
| 10882 | |
| 10883 | private: |
| 10884 | ProxyResolver* resolver_; |
| 10885 | }; |
| 10886 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10887 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10888 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10889 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10890 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10891 | |
| 10892 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10893 | proxy_config.set_auto_detect(true); |
| 10894 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10895 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10896 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10897 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10898 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10899 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10900 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10901 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10902 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10904 | |
| 10905 | HttpRequestInfo request; |
| 10906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10907 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10908 | request.load_flags = 0; |
| 10909 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10910 | std::string alternate_protocol_http_header = |
| 10911 | GetAlternateProtocolHttpHeader(); |
| 10912 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10913 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10914 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10915 | MockRead(alternate_protocol_http_header.c_str()), |
| 10916 | MockRead("\r\n"), |
| 10917 | MockRead("hello world"), |
| 10918 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10919 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10920 | }; |
| 10921 | |
| 10922 | StaticSocketDataProvider first_transaction( |
| 10923 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10924 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10925 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10926 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10927 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10928 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10929 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10931 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10932 | scoped_ptr<SpdyFrame> req( |
| 10933 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10934 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10935 | MockWrite(ASYNC, 0, |
| 10936 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10937 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10938 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10939 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10940 | }; |
| 10941 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10942 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10943 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10944 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10945 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10946 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10947 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10948 | CreateMockRead(*resp.get(), 3), |
| 10949 | CreateMockRead(*data.get(), 4), |
| 10950 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10951 | }; |
| 10952 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10953 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10954 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10955 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10956 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10957 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10958 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10959 | NULL, 0, NULL, 0); |
| 10960 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10961 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10962 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10963 | &hanging_non_alternate_protocol_socket); |
| 10964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10965 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10966 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10967 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10968 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10969 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10971 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10972 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10973 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10974 | |
| 10975 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10976 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10977 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10978 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10979 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10980 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10981 | |
| 10982 | std::string response_data; |
| 10983 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10984 | EXPECT_EQ("hello world", response_data); |
| 10985 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10986 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10988 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10989 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10990 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10991 | |
| 10992 | response = trans->GetResponseInfo(); |
| 10993 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10994 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10995 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10996 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10997 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10998 | |
| 10999 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11000 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11001 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11002 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11003 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11004 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11005 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11006 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11007 | LoadTimingInfo load_timing_info; |
| 11008 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11009 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11010 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11011 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11012 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11013 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11014 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11015 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11016 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11017 | |
| 11018 | HttpRequestInfo request; |
| 11019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11020 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11021 | request.load_flags = 0; |
| 11022 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11023 | std::string alternate_protocol_http_header = |
| 11024 | GetAlternateProtocolHttpHeader(); |
| 11025 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11026 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11027 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11028 | MockRead(alternate_protocol_http_header.c_str()), |
| 11029 | MockRead("\r\n"), |
| 11030 | MockRead("hello world"), |
| 11031 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11032 | }; |
| 11033 | |
| 11034 | StaticSocketDataProvider first_transaction( |
| 11035 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11036 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11037 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11038 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11039 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11040 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11041 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11043 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11044 | scoped_ptr<SpdyFrame> req( |
| 11045 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11046 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11047 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11048 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11049 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11050 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11051 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11052 | }; |
| 11053 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11054 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11055 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11057 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11058 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11059 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11060 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11061 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11062 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11065 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11067 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11068 | |
| 11069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11070 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11071 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11073 | |
| 11074 | std::string response_data; |
| 11075 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11076 | EXPECT_EQ("hello world", response_data); |
| 11077 | |
| 11078 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11079 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11080 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11081 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11082 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11083 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11084 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11085 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11087 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11089 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11090 | |
| 11091 | response = trans->GetResponseInfo(); |
| 11092 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11093 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11094 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11095 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11096 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11097 | |
| 11098 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11099 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11100 | } |
| 11101 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11102 | // GenerateAuthToken is a mighty big test. |
| 11103 | // It tests all permutation of GenerateAuthToken behavior: |
| 11104 | // - Synchronous and Asynchronous completion. |
| 11105 | // - OK or error on completion. |
| 11106 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11107 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11108 | // - Non-authenticating and authenticating backend. |
| 11109 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11110 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11111 | // problems generating an auth token for an authenticating proxy, we don't |
| 11112 | // need to test all permutations of the backend server). |
| 11113 | // |
| 11114 | // The test proceeds by going over each of the configuration cases, and |
| 11115 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11116 | // specifies both the configuration for the test as well as the expectations |
| 11117 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11118 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11119 | static const char kServer[] = "http://www.example.com"; |
| 11120 | static const char kSecureServer[] = "https://www.example.com"; |
| 11121 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11122 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11123 | |
| 11124 | enum AuthTiming { |
| 11125 | AUTH_NONE, |
| 11126 | AUTH_SYNC, |
| 11127 | AUTH_ASYNC, |
| 11128 | }; |
| 11129 | |
| 11130 | const MockWrite kGet( |
| 11131 | "GET / HTTP/1.1\r\n" |
| 11132 | "Host: www.example.com\r\n" |
| 11133 | "Connection: keep-alive\r\n\r\n"); |
| 11134 | const MockWrite kGetProxy( |
| 11135 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11136 | "Host: www.example.com\r\n" |
| 11137 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11138 | const MockWrite kGetAuth( |
| 11139 | "GET / HTTP/1.1\r\n" |
| 11140 | "Host: www.example.com\r\n" |
| 11141 | "Connection: keep-alive\r\n" |
| 11142 | "Authorization: auth_token\r\n\r\n"); |
| 11143 | const MockWrite kGetProxyAuth( |
| 11144 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11145 | "Host: www.example.com\r\n" |
| 11146 | "Proxy-Connection: keep-alive\r\n" |
| 11147 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11148 | const MockWrite kGetAuthThroughProxy( |
| 11149 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11150 | "Host: www.example.com\r\n" |
| 11151 | "Proxy-Connection: keep-alive\r\n" |
| 11152 | "Authorization: auth_token\r\n\r\n"); |
| 11153 | const MockWrite kGetAuthWithProxyAuth( |
| 11154 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11155 | "Host: www.example.com\r\n" |
| 11156 | "Proxy-Connection: keep-alive\r\n" |
| 11157 | "Proxy-Authorization: auth_token\r\n" |
| 11158 | "Authorization: auth_token\r\n\r\n"); |
| 11159 | const MockWrite kConnect( |
| 11160 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11161 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11162 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11163 | const MockWrite kConnectProxyAuth( |
| 11164 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11165 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11166 | "Proxy-Connection: keep-alive\r\n" |
| 11167 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11168 | |
| 11169 | const MockRead kSuccess( |
| 11170 | "HTTP/1.1 200 OK\r\n" |
| 11171 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11172 | "Content-Length: 3\r\n\r\n" |
| 11173 | "Yes"); |
| 11174 | const MockRead kFailure( |
| 11175 | "Should not be called."); |
| 11176 | const MockRead kServerChallenge( |
| 11177 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11178 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11179 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11180 | "Content-Length: 14\r\n\r\n" |
| 11181 | "Unauthorized\r\n"); |
| 11182 | const MockRead kProxyChallenge( |
| 11183 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11184 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11185 | "Proxy-Connection: close\r\n" |
| 11186 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11187 | "Content-Length: 14\r\n\r\n" |
| 11188 | "Unauthorized\r\n"); |
| 11189 | const MockRead kProxyConnected( |
| 11190 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11191 | |
| 11192 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11193 | // no constructors, but the C++ compiler on Windows warns about |
| 11194 | // unspecified data in compound literals. So, moved to using constructors, |
| 11195 | // and TestRound's created with the default constructor should not be used. |
| 11196 | struct TestRound { |
| 11197 | TestRound() |
| 11198 | : expected_rv(ERR_UNEXPECTED), |
| 11199 | extra_write(NULL), |
| 11200 | extra_read(NULL) { |
| 11201 | } |
| 11202 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11203 | int expected_rv_arg) |
| 11204 | : write(write_arg), |
| 11205 | read(read_arg), |
| 11206 | expected_rv(expected_rv_arg), |
| 11207 | extra_write(NULL), |
| 11208 | extra_read(NULL) { |
| 11209 | } |
| 11210 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11211 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11212 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11213 | : write(write_arg), |
| 11214 | read(read_arg), |
| 11215 | expected_rv(expected_rv_arg), |
| 11216 | extra_write(extra_write_arg), |
| 11217 | extra_read(extra_read_arg) { |
| 11218 | } |
| 11219 | MockWrite write; |
| 11220 | MockRead read; |
| 11221 | int expected_rv; |
| 11222 | const MockWrite* extra_write; |
| 11223 | const MockRead* extra_read; |
| 11224 | }; |
| 11225 | |
| 11226 | static const int kNoSSL = 500; |
| 11227 | |
| 11228 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11229 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11230 | AuthTiming proxy_auth_timing; |
| 11231 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11232 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11233 | AuthTiming server_auth_timing; |
| 11234 | int server_auth_rv; |
| 11235 | int num_auth_rounds; |
| 11236 | int first_ssl_round; |
| 11237 | TestRound rounds[3]; |
| 11238 | } test_configs[] = { |
| 11239 | // Non-authenticating HTTP server with a direct connection. |
| 11240 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11241 | { TestRound(kGet, kSuccess, OK)}}, |
| 11242 | // Authenticating HTTP server with a direct connection. |
| 11243 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11244 | { TestRound(kGet, kServerChallenge, OK), |
| 11245 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11246 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11247 | { TestRound(kGet, kServerChallenge, OK), |
| 11248 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11249 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11250 | { TestRound(kGet, kServerChallenge, OK), |
| 11251 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11252 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11253 | { TestRound(kGet, kServerChallenge, OK), |
| 11254 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11255 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11256 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11257 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11258 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11259 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11260 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11261 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11262 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11263 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11264 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11265 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11266 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11267 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11268 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11269 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11270 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11271 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11272 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11273 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11274 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11275 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11276 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11277 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11278 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11279 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11280 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11281 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11282 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11283 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11284 | // Authenticating HTTP server through an authenticating proxy. |
| 11285 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11286 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11287 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11288 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11289 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11290 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11291 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11292 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11293 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11294 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11295 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11296 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11297 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11298 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11299 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11300 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11301 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11302 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11303 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11304 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11305 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11306 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11307 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11308 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11309 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11310 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11311 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11312 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11313 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11314 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11315 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11316 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11317 | // Non-authenticating HTTPS server with a direct connection. |
| 11318 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11319 | { TestRound(kGet, kSuccess, OK)}}, |
| 11320 | // Authenticating HTTPS server with a direct connection. |
| 11321 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11322 | { TestRound(kGet, kServerChallenge, OK), |
| 11323 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11324 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11325 | { TestRound(kGet, kServerChallenge, OK), |
| 11326 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11327 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11328 | { TestRound(kGet, kServerChallenge, OK), |
| 11329 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11330 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11331 | { TestRound(kGet, kServerChallenge, OK), |
| 11332 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11333 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11334 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11335 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11336 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11337 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11338 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11339 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11340 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11341 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11342 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11343 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11344 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11345 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11346 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11347 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11348 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11349 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11350 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11351 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11352 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11353 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11354 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11355 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11356 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11357 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11358 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11359 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11360 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11361 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11362 | // Authenticating HTTPS server through an authenticating proxy. |
| 11363 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11364 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11365 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11366 | &kGet, &kServerChallenge), |
| 11367 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11368 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11369 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11370 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11371 | &kGet, &kServerChallenge), |
| 11372 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11373 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11374 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11375 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11376 | &kGet, &kServerChallenge), |
| 11377 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11378 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11379 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11380 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11381 | &kGet, &kServerChallenge), |
| 11382 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11383 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11384 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11385 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11386 | &kGet, &kServerChallenge), |
| 11387 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11388 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11389 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11390 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11391 | &kGet, &kServerChallenge), |
| 11392 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11393 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11394 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11395 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11396 | &kGet, &kServerChallenge), |
| 11397 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11398 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11399 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11400 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11401 | &kGet, &kServerChallenge), |
| 11402 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11403 | }; |
| 11404 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11405 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11406 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11407 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11409 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11410 | |
| 11411 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11412 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11413 | for (int n = 0; n < 2; n++) { |
| 11414 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11415 | std::string auth_challenge = "Mock realm=proxy"; |
| 11416 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11417 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11418 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11419 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11420 | origin, BoundNetLog()); |
| 11421 | auth_handler->SetGenerateExpectation( |
| 11422 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11423 | test_config.proxy_auth_rv); |
| 11424 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11425 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11426 | } |
| 11427 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11428 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11429 | std::string auth_challenge = "Mock realm=server"; |
| 11430 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11431 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11432 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11433 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11434 | origin, BoundNetLog()); |
| 11435 | auth_handler->SetGenerateExpectation( |
| 11436 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11437 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11438 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11439 | } |
| 11440 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11441 | session_deps_.proxy_service = |
| 11442 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11443 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11444 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11445 | } |
| 11446 | |
| 11447 | HttpRequestInfo request; |
| 11448 | request.method = "GET"; |
| 11449 | request.url = GURL(test_config.server_url); |
| 11450 | request.load_flags = 0; |
| 11451 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11452 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11453 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11454 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11455 | |
| 11456 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11457 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11458 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11459 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11460 | |
| 11461 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11462 | mock_reads.back().push_back(read_write_round.read); |
| 11463 | mock_writes.back().push_back(read_write_round.write); |
| 11464 | |
| 11465 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11466 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11467 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11468 | mock_reads.push_back(std::vector<MockRead>()); |
| 11469 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11470 | } |
| 11471 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11472 | if (read_write_round.extra_read) { |
| 11473 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11474 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11475 | if (read_write_round.extra_write) { |
| 11476 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11477 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11478 | |
| 11479 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11480 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11481 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11482 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11483 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11484 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11485 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 11486 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 11487 | data_providers.push_back(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11488 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
| 11489 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11490 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11491 | data_providers.back()); |
| 11492 | } |
| 11493 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11494 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11495 | // they are as well. |
| 11496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11497 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11498 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11499 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11500 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11501 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11502 | int rv; |
| 11503 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11504 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11505 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11506 | rv = trans.RestartWithAuth( |
| 11507 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11508 | } |
| 11509 | if (rv == ERR_IO_PENDING) |
| 11510 | rv = callback.WaitForResult(); |
| 11511 | |
| 11512 | // Compare results with expected data. |
| 11513 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11514 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11515 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11516 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11517 | continue; |
| 11518 | } |
| 11519 | if (round + 1 < test_config.num_auth_rounds) { |
| 11520 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11521 | } else { |
| 11522 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11523 | } |
| 11524 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11525 | } |
| 11526 | } |
| 11527 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11528 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11529 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11530 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11531 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11532 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11533 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11534 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11535 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11536 | |
| 11537 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11538 | auth_handler->set_connection_based(true); |
| 11539 | std::string auth_challenge = "Mock realm=server"; |
| 11540 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11541 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11542 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11543 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11544 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11545 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11546 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11547 | int rv = OK; |
| 11548 | const HttpResponseInfo* response = NULL; |
| 11549 | HttpRequestInfo request; |
| 11550 | request.method = "GET"; |
| 11551 | request.url = origin; |
| 11552 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11553 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11554 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11555 | |
| 11556 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11557 | // to validate that the TCP socket is not released to the pool between |
| 11558 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11559 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11560 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11561 | 50, // Max sockets for pool |
| 11562 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11563 | session_deps_.host_resolver.get(), |
| 11564 | session_deps_.socket_factory.get(), |
| 11565 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11566 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11567 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11568 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 11569 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11570 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11571 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11572 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11573 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11574 | |
| 11575 | const MockWrite kGet( |
| 11576 | "GET / HTTP/1.1\r\n" |
| 11577 | "Host: www.example.com\r\n" |
| 11578 | "Connection: keep-alive\r\n\r\n"); |
| 11579 | const MockWrite kGetAuth( |
| 11580 | "GET / HTTP/1.1\r\n" |
| 11581 | "Host: www.example.com\r\n" |
| 11582 | "Connection: keep-alive\r\n" |
| 11583 | "Authorization: auth_token\r\n\r\n"); |
| 11584 | |
| 11585 | const MockRead kServerChallenge( |
| 11586 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11587 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11588 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11589 | "Content-Length: 14\r\n\r\n" |
| 11590 | "Unauthorized\r\n"); |
| 11591 | const MockRead kSuccess( |
| 11592 | "HTTP/1.1 200 OK\r\n" |
| 11593 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11594 | "Content-Length: 3\r\n\r\n" |
| 11595 | "Yes"); |
| 11596 | |
| 11597 | MockWrite writes[] = { |
| 11598 | // First round |
| 11599 | kGet, |
| 11600 | // Second round |
| 11601 | kGetAuth, |
| 11602 | // Third round |
| 11603 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11604 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11605 | kGetAuth, |
| 11606 | // Competing request |
| 11607 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11608 | }; |
| 11609 | MockRead reads[] = { |
| 11610 | // First round |
| 11611 | kServerChallenge, |
| 11612 | // Second round |
| 11613 | kServerChallenge, |
| 11614 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11615 | kServerChallenge, |
| 11616 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11617 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11618 | // Competing response |
| 11619 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11620 | }; |
| 11621 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11622 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11623 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11624 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11625 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11626 | |
| 11627 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11628 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11629 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11630 | if (rv == ERR_IO_PENDING) |
| 11631 | rv = callback.WaitForResult(); |
| 11632 | EXPECT_EQ(OK, rv); |
| 11633 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11634 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11635 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11636 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11637 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11638 | // In between rounds, another request comes in for the same domain. |
| 11639 | // It should not be able to grab the TCP socket that trans has already |
| 11640 | // claimed. |
| 11641 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11642 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11643 | TestCompletionCallback callback_compete; |
| 11644 | rv = trans_compete->Start( |
| 11645 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11647 | // callback_compete.WaitForResult at this point would stall forever, |
| 11648 | // since the HttpNetworkTransaction does not release the request back to |
| 11649 | // the pool until after authentication completes. |
| 11650 | |
| 11651 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11652 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11653 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11654 | if (rv == ERR_IO_PENDING) |
| 11655 | rv = callback.WaitForResult(); |
| 11656 | EXPECT_EQ(OK, rv); |
| 11657 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11658 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11659 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11660 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11661 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11662 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11663 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11664 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11665 | if (rv == ERR_IO_PENDING) |
| 11666 | rv = callback.WaitForResult(); |
| 11667 | EXPECT_EQ(OK, rv); |
| 11668 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11669 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11670 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11671 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11672 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11673 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11674 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11675 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11676 | if (rv == ERR_IO_PENDING) |
| 11677 | rv = callback.WaitForResult(); |
| 11678 | EXPECT_EQ(OK, rv); |
| 11679 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11680 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11681 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11682 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11683 | |
| 11684 | // Read the body since the fourth round was successful. This will also |
| 11685 | // release the socket back to the pool. |
| 11686 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11687 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11688 | if (rv == ERR_IO_PENDING) |
| 11689 | rv = callback.WaitForResult(); |
| 11690 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11691 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11692 | EXPECT_EQ(0, rv); |
| 11693 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11694 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11695 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11696 | |
| 11697 | // The competing request can now finish. Wait for the headers and then |
| 11698 | // read the body. |
| 11699 | rv = callback_compete.WaitForResult(); |
| 11700 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11701 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11702 | if (rv == ERR_IO_PENDING) |
| 11703 | rv = callback.WaitForResult(); |
| 11704 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11705 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11706 | EXPECT_EQ(0, rv); |
| 11707 | |
| 11708 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11709 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11710 | } |
| 11711 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11712 | // This tests the case that a request is issued via http instead of spdy after |
| 11713 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11714 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11715 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11716 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11717 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11718 | session_deps_.next_protos = next_protos; |
| 11719 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11720 | HttpRequestInfo request; |
| 11721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11722 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11723 | request.load_flags = 0; |
| 11724 | |
| 11725 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11726 | MockWrite( |
| 11727 | "GET / HTTP/1.1\r\n" |
| 11728 | "Host: www.example.org\r\n" |
| 11729 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11730 | }; |
| 11731 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11732 | std::string alternate_protocol_http_header = |
| 11733 | GetAlternateProtocolHttpHeader(); |
| 11734 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11735 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11736 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11737 | MockRead(alternate_protocol_http_header.c_str()), |
| 11738 | MockRead("\r\n"), |
| 11739 | MockRead("hello world"), |
| 11740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11741 | }; |
| 11742 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11743 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11744 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11747 | |
| 11748 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11749 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11752 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11753 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11754 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11755 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11758 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11759 | |
| 11760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11761 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11762 | |
| 11763 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11764 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11765 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11766 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11767 | |
| 11768 | std::string response_data; |
| 11769 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11770 | EXPECT_EQ("hello world", response_data); |
| 11771 | |
| 11772 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11773 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11774 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11775 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11776 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11777 | // immediate server closing of the socket. |
| 11778 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11779 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11780 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11781 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11782 | |
| 11783 | HttpRequestInfo request; |
| 11784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11785 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11786 | request.load_flags = 0; |
| 11787 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11788 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11789 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11790 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11791 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11792 | scoped_ptr<SpdyFrame> req( |
| 11793 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11794 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11795 | |
| 11796 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11797 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11798 | }; |
| 11799 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11800 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11801 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11802 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11804 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11805 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11806 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11807 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11808 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11810 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11811 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11812 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11813 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11814 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11815 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11816 | // it gets it. This is needed since the auth handler may get destroyed |
| 11817 | // before we get a chance to query it. |
| 11818 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11819 | public: |
| 11820 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11821 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11822 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11823 | |
| 11824 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11825 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11826 | const HttpRequestInfo* request, |
| 11827 | const CompletionCallback& callback, |
| 11828 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11829 | *url_ = request->url; |
| 11830 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11831 | credentials, request, callback, auth_token); |
| 11832 | } |
| 11833 | |
| 11834 | private: |
| 11835 | GURL* url_; |
| 11836 | }; |
| 11837 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11838 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11839 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11840 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11841 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11842 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11843 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11844 | session_deps_.proxy_service = |
| 11845 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11846 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11847 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11848 | GURL request_url; |
| 11849 | { |
| 11850 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11851 | new HttpAuthHandlerMock::Factory(); |
| 11852 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11853 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11854 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11855 | auth_factory->set_do_init_from_challenge(true); |
| 11856 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11857 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11858 | |
| 11859 | HttpRequestInfo request; |
| 11860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11861 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11862 | request.load_flags = 0; |
| 11863 | |
| 11864 | // First round goes unauthenticated through the proxy. |
| 11865 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11866 | MockWrite( |
| 11867 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11868 | "Host: www.example.org\r\n" |
| 11869 | "Proxy-Connection: keep-alive\r\n" |
| 11870 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11871 | }; |
| 11872 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11873 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11874 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11875 | MockRead("Alternate-Protocol: 443:"), |
| 11876 | MockRead(GetAlternateProtocolFromParam()), |
| 11877 | MockRead("\r\n"), |
| 11878 | MockRead("Proxy-Connection: close\r\n"), |
| 11879 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11880 | }; |
| 11881 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11882 | data_writes_1, arraysize(data_writes_1)); |
| 11883 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11884 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11885 | // Alternate-Protocol announcement in the first round. It fails due |
| 11886 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11887 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11888 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11889 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11890 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11891 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11892 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11893 | // to obtain a new one. |
| 11894 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11895 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11896 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11897 | // establishment and SPDY framing issues. Alas, the |
| 11898 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11899 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11900 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11901 | scoped_ptr<SpdyFrame> req( |
| 11902 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11903 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11904 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11905 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11906 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11907 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11908 | MockWrite(ASYNC, 0, |
| 11909 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11910 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11911 | "Proxy-Connection: keep-alive\r\n" |
| 11912 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11913 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11914 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11915 | MockWrite(ASYNC, 2, |
| 11916 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11917 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11918 | "Proxy-Connection: keep-alive\r\n" |
| 11919 | "Proxy-Authorization: auth_token\r\n" |
| 11920 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11921 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11922 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11923 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11924 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11925 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11926 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11927 | MockRead(ASYNC, 1, |
| 11928 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11929 | "Proxy-Authenticate: Mock\r\n" |
| 11930 | "Content-Length: 0\r\n" |
| 11931 | "Proxy-Connection: keep-alive\r\n" |
| 11932 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11933 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11934 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11935 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11936 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11937 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11938 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11939 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11940 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11941 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11942 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11943 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11944 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11945 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11946 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11947 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11948 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11949 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11950 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11951 | NULL, 0, NULL, 0); |
| 11952 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11953 | never_finishing_connect); |
| 11954 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11955 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11956 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11958 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11959 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11960 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11961 | |
| 11962 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11963 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11964 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11965 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11966 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11968 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11969 | |
| 11970 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11971 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11972 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11974 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11976 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11977 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11978 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11979 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11980 | |
| 11981 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11982 | TestCompletionCallback callback_3; |
| 11983 | rv = trans_2->RestartWithAuth( |
| 11984 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11986 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11987 | |
| 11988 | // After all that work, these two lines (or actually, just the scheme) are |
| 11989 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11990 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11991 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11992 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11993 | LoadTimingInfo load_timing_info; |
| 11994 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11995 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11996 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11997 | } |
| 11998 | |
| 11999 | // Test that if we cancel the transaction as the connection is completing, that |
| 12000 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12001 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12002 | // Setup everything about the connection to complete synchronously, so that |
| 12003 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12004 | // for is the callback from the HttpStreamRequest. |
| 12005 | // Then cancel the transaction. |
| 12006 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12007 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12008 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12009 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12010 | MockRead(SYNCHRONOUS, "hello world"), |
| 12011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12012 | }; |
| 12013 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12014 | HttpRequestInfo request; |
| 12015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12016 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12017 | request.load_flags = 0; |
| 12018 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12019 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12020 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12023 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12025 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12028 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12029 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12030 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12031 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12033 | trans.reset(); // Cancel the transaction here. |
| 12034 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12035 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12036 | } |
| 12037 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12038 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12039 | // stream is drained properly and added back to the socket pool. The main |
| 12040 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12041 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12042 | // deleted. |
| 12043 | // See http://crbug.com/368418 |
| 12044 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 12045 | MockRead data_reads[] = { |
| 12046 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12047 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12048 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12049 | MockRead(ASYNC, "1"), |
| 12050 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12051 | // HttpNetworkTransaction has been deleted. |
| 12052 | MockRead(ASYNC, "2"), |
| 12053 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12054 | }; |
| 12055 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12057 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12058 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12059 | |
| 12060 | { |
| 12061 | HttpRequestInfo request; |
| 12062 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12063 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12064 | request.load_flags = 0; |
| 12065 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12067 | TestCompletionCallback callback; |
| 12068 | |
| 12069 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 12070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12071 | callback.WaitForResult(); |
| 12072 | |
| 12073 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12074 | ASSERT_TRUE(response != NULL); |
| 12075 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12077 | |
| 12078 | // The transaction and HttpRequestInfo are deleted. |
| 12079 | } |
| 12080 | |
| 12081 | // Let the HttpResponseBodyDrainer drain the socket. |
| 12082 | base::MessageLoop::current()->RunUntilIdle(); |
| 12083 | |
| 12084 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12085 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12086 | } |
| 12087 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12088 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12089 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12090 | session_deps_.proxy_service = |
| 12091 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12092 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12093 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12094 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12095 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12096 | HttpRequestInfo request; |
| 12097 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12098 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12099 | |
| 12100 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12101 | MockWrite( |
| 12102 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12103 | "Host: www.example.org\r\n" |
| 12104 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12105 | }; |
| 12106 | |
| 12107 | MockRead data_reads1[] = { |
| 12108 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12109 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12110 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12111 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12112 | }; |
| 12113 | |
| 12114 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12115 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12118 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12119 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12120 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12122 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 12123 | trans->SetBeforeProxyHeadersSentCallback( |
| 12124 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 12125 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12127 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12129 | |
| 12130 | rv = callback1.WaitForResult(); |
| 12131 | EXPECT_EQ(OK, rv); |
| 12132 | |
| 12133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12134 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12135 | |
| 12136 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12137 | EXPECT_EQ(200, response->headers->response_code()); |
| 12138 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12139 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12140 | EXPECT_TRUE( |
| 12141 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12142 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 12143 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12144 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12145 | |
| 12146 | LoadTimingInfo load_timing_info; |
| 12147 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12148 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12149 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12150 | } |
| 12151 | |
| 12152 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12153 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12154 | session_deps_.proxy_service = |
| 12155 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12156 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12157 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12158 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12159 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12160 | HttpRequestInfo request; |
| 12161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12162 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12163 | |
| 12164 | // Since we have proxy, should try to establish tunnel. |
| 12165 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12166 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12167 | "Host: www.example.org:443\r\n" |
| 12168 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12169 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12170 | MockWrite("GET / HTTP/1.1\r\n" |
| 12171 | "Host: www.example.org\r\n" |
| 12172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12173 | }; |
| 12174 | |
| 12175 | MockRead data_reads1[] = { |
| 12176 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12177 | |
| 12178 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12179 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12180 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12182 | }; |
| 12183 | |
| 12184 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12185 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12186 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12187 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12190 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12191 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12192 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12195 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12196 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12197 | |
| 12198 | rv = callback1.WaitForResult(); |
| 12199 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12200 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12201 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12202 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12203 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12204 | NetLog::PHASE_NONE); |
| 12205 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12206 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12207 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12208 | NetLog::PHASE_NONE); |
| 12209 | |
| 12210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12211 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12212 | |
| 12213 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12214 | EXPECT_EQ(200, response->headers->response_code()); |
| 12215 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12216 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12217 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12218 | EXPECT_TRUE( |
| 12219 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12220 | |
| 12221 | LoadTimingInfo load_timing_info; |
| 12222 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12223 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12224 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12225 | } |
| 12226 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12227 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12228 | // literal host. |
| 12229 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 12230 | session_deps_.proxy_service = |
| 12231 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12232 | BoundTestNetLog log; |
| 12233 | session_deps_.net_log = log.bound().net_log(); |
| 12234 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12235 | |
| 12236 | HttpRequestInfo request; |
| 12237 | request.method = "GET"; |
| 12238 | request.url = GURL("https://[::1]:443/"); |
| 12239 | |
| 12240 | // Since we have proxy, should try to establish tunnel. |
| 12241 | MockWrite data_writes1[] = { |
| 12242 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12243 | "Host: [::1]:443\r\n" |
| 12244 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12245 | |
| 12246 | MockWrite("GET / HTTP/1.1\r\n" |
| 12247 | "Host: [::1]\r\n" |
| 12248 | "Connection: keep-alive\r\n\r\n"), |
| 12249 | }; |
| 12250 | |
| 12251 | MockRead data_reads1[] = { |
| 12252 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12253 | |
| 12254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12256 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12257 | MockRead(SYNCHRONOUS, OK), |
| 12258 | }; |
| 12259 | |
| 12260 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12261 | data_writes1, arraysize(data_writes1)); |
| 12262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12263 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12265 | |
| 12266 | TestCompletionCallback callback1; |
| 12267 | |
| 12268 | scoped_ptr<HttpTransaction> trans( |
| 12269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12270 | |
| 12271 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 12272 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12273 | |
| 12274 | rv = callback1.WaitForResult(); |
| 12275 | EXPECT_EQ(OK, rv); |
| 12276 | TestNetLogEntry::List entries; |
| 12277 | log.GetEntries(&entries); |
| 12278 | size_t pos = ExpectLogContainsSomewhere( |
| 12279 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12280 | NetLog::PHASE_NONE); |
| 12281 | ExpectLogContainsSomewhere( |
| 12282 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12283 | NetLog::PHASE_NONE); |
| 12284 | |
| 12285 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12286 | ASSERT_TRUE(response != NULL); |
| 12287 | |
| 12288 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12289 | EXPECT_EQ(200, response->headers->response_code()); |
| 12290 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12291 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12292 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12293 | EXPECT_TRUE( |
| 12294 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12295 | |
| 12296 | LoadTimingInfo load_timing_info; |
| 12297 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12298 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12299 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12300 | } |
| 12301 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12302 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12303 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12304 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12305 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12306 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12307 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12308 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12309 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12310 | HttpRequestInfo request; |
| 12311 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12312 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12313 | |
| 12314 | // Since we have proxy, should try to establish tunnel. |
| 12315 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12316 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12317 | "Host: www.example.org:443\r\n" |
| 12318 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12319 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12320 | MockWrite("GET / HTTP/1.1\r\n" |
| 12321 | "Host: www.example.org\r\n" |
| 12322 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12323 | }; |
| 12324 | |
| 12325 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12326 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12327 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12328 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12329 | }; |
| 12330 | |
| 12331 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12332 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12334 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12337 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12338 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12339 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12340 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12342 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12344 | |
| 12345 | rv = callback1.WaitForResult(); |
| 12346 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12347 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12348 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12349 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12350 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12351 | NetLog::PHASE_NONE); |
| 12352 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12353 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12354 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12355 | NetLog::PHASE_NONE); |
| 12356 | } |
| 12357 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12358 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12359 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12360 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12361 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12362 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12363 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12364 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12365 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12366 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12367 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12368 | }; |
| 12369 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12370 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12371 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12372 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12373 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12374 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12375 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12377 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12378 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12379 | |
| 12380 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12381 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12382 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12383 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12384 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12385 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12386 | |
| 12387 | HttpRequestInfo request; |
| 12388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12389 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12390 | request.load_flags = 0; |
| 12391 | |
| 12392 | // This is the important line that marks this as a preconnect. |
| 12393 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12394 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12395 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12396 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12397 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12398 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12399 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12401 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12402 | } |
| 12403 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12404 | // Given a net error, cause that error to be returned from the first Write() |
| 12405 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12406 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12407 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12408 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12409 | request_info.url = GURL("https://www.example.com/"); |
| 12410 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12411 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12412 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12413 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12414 | MockWrite data_writes[] = { |
| 12415 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12416 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12417 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12418 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12420 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12421 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12422 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12425 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12426 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12427 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12428 | rv = callback.WaitForResult(); |
| 12429 | ASSERT_EQ(error, rv); |
| 12430 | } |
| 12431 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12432 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12433 | // Just check a grab bag of cert errors. |
| 12434 | static const int kErrors[] = { |
| 12435 | ERR_CERT_COMMON_NAME_INVALID, |
| 12436 | ERR_CERT_AUTHORITY_INVALID, |
| 12437 | ERR_CERT_DATE_INVALID, |
| 12438 | }; |
| 12439 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12440 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12441 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12442 | } |
| 12443 | } |
| 12444 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12445 | // Ensure that a client certificate is removed from the SSL client auth |
| 12446 | // cache when: |
| 12447 | // 1) No proxy is involved. |
| 12448 | // 2) TLS False Start is disabled. |
| 12449 | // 3) The initial TLS handshake requests a client certificate. |
| 12450 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12451 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12452 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12453 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12454 | request_info.url = GURL("https://www.example.com/"); |
| 12455 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12456 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12457 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12458 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12459 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12460 | |
| 12461 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12462 | // CertificateRequest is received for the first time, the handshake will |
| 12463 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12464 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12465 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12467 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12469 | |
| 12470 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12471 | // False Start is not being used, the result of the SSL handshake will be |
| 12472 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12473 | // matches the result of a server sending a handshake_failure alert, |
| 12474 | // rather than a Finished message, because it requires a client |
| 12475 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12476 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12477 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12479 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12480 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12481 | |
| 12482 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12483 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12484 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12485 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12486 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12487 | // requiring a client certificate, this fallback handshake should also |
| 12488 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12489 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12490 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12492 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12493 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12494 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12495 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12496 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12497 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12498 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12499 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12500 | // requiring a client certificate, this fallback handshake should also |
| 12501 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12502 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12503 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12505 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12506 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12507 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12508 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12511 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12512 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12513 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12514 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12515 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12516 | |
| 12517 | // Complete the SSL handshake, which should abort due to requiring a |
| 12518 | // client certificate. |
| 12519 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12520 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12521 | |
| 12522 | // Indicate that no certificate should be supplied. From the perspective |
| 12523 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12524 | // certificate, so this is the same as supply a |
| 12525 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12526 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12527 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12528 | |
| 12529 | // Ensure the certificate was added to the client auth cache before |
| 12530 | // allowing the connection to continue restarting. |
| 12531 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12532 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12533 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12534 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12535 | ASSERT_EQ(NULL, client_cert.get()); |
| 12536 | |
| 12537 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12538 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12539 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12540 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12541 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12542 | |
| 12543 | // Ensure that the client certificate is removed from the cache on a |
| 12544 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12545 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12546 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12547 | } |
| 12548 | |
| 12549 | // Ensure that a client certificate is removed from the SSL client auth |
| 12550 | // cache when: |
| 12551 | // 1) No proxy is involved. |
| 12552 | // 2) TLS False Start is enabled. |
| 12553 | // 3) The initial TLS handshake requests a client certificate. |
| 12554 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12555 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12556 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12557 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12558 | request_info.url = GURL("https://www.example.com/"); |
| 12559 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12560 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12561 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12562 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12563 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12564 | |
| 12565 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12566 | // return successfully after reading up to the peer's Certificate message. |
| 12567 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12568 | // enqueue application data to be sent in the same packet as the |
| 12569 | // ChangeCipherSpec and Finished messages. |
| 12570 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12571 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12572 | // Finished messages. If there was an error negotiating with the peer, |
| 12573 | // such as due to the peer requiring a client certificate when none was |
| 12574 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12575 | // called. |
| 12576 | |
| 12577 | // Like the non-False Start case, when a client certificate is requested by |
| 12578 | // the peer, the handshake is aborted during the Connect() call. |
| 12579 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12580 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12581 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12583 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12585 | |
| 12586 | // When a client certificate is supplied, Connect() will not be aborted |
| 12587 | // when the peer requests the certificate. Instead, the handshake will |
| 12588 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12589 | // the socket. The handshake messages are not processed until Read() is |
| 12590 | // called, which then detects that the handshake was aborted, due to the |
| 12591 | // peer sending a handshake_failure because it requires a client |
| 12592 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12593 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12594 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12596 | MockRead data2_reads[] = { |
| 12597 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12598 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12599 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12600 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12601 | |
| 12602 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12603 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12604 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12605 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12606 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12608 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12609 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12610 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12611 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12612 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12613 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12614 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12616 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12617 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12618 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12619 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12620 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12621 | ssl_data5.cert_request_info = cert_request.get(); |
| 12622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12623 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12624 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12625 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12626 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12627 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12629 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12630 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12631 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12632 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12633 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12634 | |
| 12635 | // Complete the SSL handshake, which should abort due to requiring a |
| 12636 | // client certificate. |
| 12637 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12638 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12639 | |
| 12640 | // Indicate that no certificate should be supplied. From the perspective |
| 12641 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12642 | // certificate, so this is the same as supply a |
| 12643 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12644 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12645 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12646 | |
| 12647 | // Ensure the certificate was added to the client auth cache before |
| 12648 | // allowing the connection to continue restarting. |
| 12649 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12650 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12651 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12652 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12653 | ASSERT_EQ(NULL, client_cert.get()); |
| 12654 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12655 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12656 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12657 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12658 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12659 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12660 | |
| 12661 | // Ensure that the client certificate is removed from the cache on a |
| 12662 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12663 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12664 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12665 | } |
| 12666 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12667 | // Ensure that a client certificate is removed from the SSL client auth |
| 12668 | // cache when: |
| 12669 | // 1) An HTTPS proxy is involved. |
| 12670 | // 3) The HTTPS proxy requests a client certificate. |
| 12671 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12672 | // proxy. |
| 12673 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12674 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12675 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12676 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12677 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12678 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12679 | |
| 12680 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12681 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12682 | |
| 12683 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12684 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12685 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12686 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12687 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12688 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12690 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12692 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12693 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12694 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12696 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12697 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12698 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12699 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12700 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12701 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12702 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12704 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12705 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12706 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12707 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12708 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12709 | requests[0].url = GURL("https://www.example.com/"); |
| 12710 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12711 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12712 | |
| 12713 | requests[1].url = GURL("http://www.example.com/"); |
| 12714 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12715 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12716 | |
| 12717 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12718 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12719 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12720 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12721 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12722 | |
| 12723 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12724 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12725 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12726 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12727 | |
| 12728 | // Complete the SSL handshake, which should abort due to requiring a |
| 12729 | // client certificate. |
| 12730 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12731 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12732 | |
| 12733 | // Indicate that no certificate should be supplied. From the perspective |
| 12734 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12735 | // certificate, so this is the same as supply a |
| 12736 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12737 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12738 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12739 | |
| 12740 | // Ensure the certificate was added to the client auth cache before |
| 12741 | // allowing the connection to continue restarting. |
| 12742 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12743 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12744 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12745 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12746 | ASSERT_EQ(NULL, client_cert.get()); |
| 12747 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12748 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12749 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12750 | HostPortPair("www.example.com", 443), &client_cert, |
| 12751 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12752 | |
| 12753 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12754 | // then consume ssl_data3, which should also fail. The result code is |
| 12755 | // checked against what ssl_data3 should return. |
| 12756 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12757 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12758 | |
| 12759 | // Now that the new handshake has failed, ensure that the client |
| 12760 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12761 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12762 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12763 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12764 | HostPortPair("www.example.com", 443), &client_cert, |
| 12765 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12766 | } |
| 12767 | } |
| 12768 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12769 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12770 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12771 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12772 | |
| 12773 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12774 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12775 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12776 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12777 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12778 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12779 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12780 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12782 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12783 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12784 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12785 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12786 | scoped_ptr<SpdyFrame> host2_req( |
| 12787 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12788 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12789 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12790 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12791 | scoped_ptr<SpdyFrame> host1_resp( |
| 12792 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12793 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12794 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12795 | scoped_ptr<SpdyFrame> host2_resp( |
| 12796 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12797 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12798 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12799 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12800 | CreateMockRead(*host1_resp, 1), |
| 12801 | CreateMockRead(*host1_resp_body, 2), |
| 12802 | CreateMockRead(*host2_resp, 4), |
| 12803 | CreateMockRead(*host2_resp_body, 5), |
| 12804 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12805 | }; |
| 12806 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12807 | IPAddressNumber ip; |
| 12808 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12809 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12810 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12811 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12812 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12813 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12814 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12815 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12816 | HttpRequestInfo request1; |
| 12817 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12818 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12819 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12820 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12822 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12824 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12825 | |
| 12826 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12827 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12828 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12829 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12830 | |
| 12831 | std::string response_data; |
| 12832 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12833 | EXPECT_EQ("hello!", response_data); |
| 12834 | |
| 12835 | // Preload www.gmail.com into HostCache. |
| 12836 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12837 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12838 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12839 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12840 | DEFAULT_PRIORITY, |
| 12841 | &ignored, |
| 12842 | callback.callback(), |
| 12843 | NULL, |
| 12844 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12846 | rv = callback.WaitForResult(); |
| 12847 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12848 | |
| 12849 | HttpRequestInfo request2; |
| 12850 | request2.method = "GET"; |
| 12851 | request2.url = GURL("https://www.gmail.com/"); |
| 12852 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12853 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12855 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12856 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12857 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12858 | |
| 12859 | response = trans2.GetResponseInfo(); |
| 12860 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12861 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12862 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12863 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12864 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12865 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12866 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12867 | } |
| 12868 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12869 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12870 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12871 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12872 | |
| 12873 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12874 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12875 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12876 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12877 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12878 | |
| 12879 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12880 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12882 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12883 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12884 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12885 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12886 | scoped_ptr<SpdyFrame> host2_req( |
| 12887 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12888 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12889 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12890 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12891 | scoped_ptr<SpdyFrame> host1_resp( |
| 12892 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12893 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12894 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12895 | scoped_ptr<SpdyFrame> host2_resp( |
| 12896 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12897 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12898 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12899 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12900 | CreateMockRead(*host1_resp, 1), |
| 12901 | CreateMockRead(*host1_resp_body, 2), |
| 12902 | CreateMockRead(*host2_resp, 4), |
| 12903 | CreateMockRead(*host2_resp_body, 5), |
| 12904 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12905 | }; |
| 12906 | |
| 12907 | IPAddressNumber ip; |
| 12908 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12909 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12910 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12911 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12912 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12913 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12914 | |
| 12915 | TestCompletionCallback callback; |
| 12916 | HttpRequestInfo request1; |
| 12917 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12918 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12919 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12920 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12921 | |
| 12922 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12924 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12925 | |
| 12926 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12927 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12928 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12929 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12930 | |
| 12931 | std::string response_data; |
| 12932 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12933 | EXPECT_EQ("hello!", response_data); |
| 12934 | |
| 12935 | HttpRequestInfo request2; |
| 12936 | request2.method = "GET"; |
| 12937 | request2.url = GURL("https://www.gmail.com/"); |
| 12938 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12939 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12940 | |
| 12941 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12943 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12944 | |
| 12945 | response = trans2.GetResponseInfo(); |
| 12946 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12947 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12948 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12949 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12950 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12951 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12952 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12953 | } |
| 12954 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12955 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12956 | public: |
| 12957 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12958 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12959 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12960 | |
| 12961 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12962 | |
| 12963 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12964 | int Resolve(const RequestInfo& info, |
| 12965 | RequestPriority priority, |
| 12966 | AddressList* addresses, |
| 12967 | const CompletionCallback& callback, |
| 12968 | RequestHandle* out_req, |
| 12969 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12970 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12971 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12972 | } |
| 12973 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12974 | int ResolveFromCache(const RequestInfo& info, |
| 12975 | AddressList* addresses, |
| 12976 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12977 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12978 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12979 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12980 | return rv; |
| 12981 | } |
| 12982 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12983 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12984 | host_resolver_.CancelRequest(req); |
| 12985 | } |
| 12986 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12987 | MockCachingHostResolver* GetMockHostResolver() { |
| 12988 | return &host_resolver_; |
| 12989 | } |
| 12990 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12991 | private: |
| 12992 | MockCachingHostResolver host_resolver_; |
| 12993 | const HostPortPair host_port_; |
| 12994 | }; |
| 12995 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12996 | TEST_P(HttpNetworkTransactionTest, |
| 12997 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12998 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12999 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13000 | |
| 13001 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13002 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13003 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13004 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13005 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13006 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13007 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13008 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13009 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13010 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13011 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13012 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13013 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13014 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13015 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13016 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13017 | scoped_ptr<SpdyFrame> host2_req( |
| 13018 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13019 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13020 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13021 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13022 | scoped_ptr<SpdyFrame> host1_resp( |
| 13023 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13024 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13025 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13026 | scoped_ptr<SpdyFrame> host2_resp( |
| 13027 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13028 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13029 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13030 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13031 | CreateMockRead(*host1_resp, 1), |
| 13032 | CreateMockRead(*host1_resp_body, 2), |
| 13033 | CreateMockRead(*host2_resp, 4), |
| 13034 | CreateMockRead(*host2_resp_body, 5), |
| 13035 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13036 | }; |
| 13037 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13038 | IPAddressNumber ip; |
| 13039 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 13040 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13041 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13042 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13043 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13044 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13045 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13046 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13047 | HttpRequestInfo request1; |
| 13048 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13049 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13050 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13051 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13053 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13055 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13056 | |
| 13057 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13058 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13059 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13060 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13061 | |
| 13062 | std::string response_data; |
| 13063 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13064 | EXPECT_EQ("hello!", response_data); |
| 13065 | |
| 13066 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13067 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13068 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13069 | rv = host_resolver.Resolve(resolve_info, |
| 13070 | DEFAULT_PRIORITY, |
| 13071 | &ignored, |
| 13072 | callback.callback(), |
| 13073 | NULL, |
| 13074 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13075 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13076 | rv = callback.WaitForResult(); |
| 13077 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13078 | |
| 13079 | HttpRequestInfo request2; |
| 13080 | request2.method = "GET"; |
| 13081 | request2.url = GURL("https://www.gmail.com/"); |
| 13082 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13083 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13085 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13086 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13087 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13088 | |
| 13089 | response = trans2.GetResponseInfo(); |
| 13090 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13091 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13092 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13093 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13094 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13095 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13096 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13097 | } |
| 13098 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13099 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13100 | const std::string https_url = "https://www.example.org:8080/"; |
| 13101 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13102 | |
| 13103 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13104 | scoped_ptr<SpdyFrame> req1( |
| 13105 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13106 | |
| 13107 | MockWrite writes1[] = { |
| 13108 | CreateMockWrite(*req1, 0), |
| 13109 | }; |
| 13110 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13111 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13112 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13113 | MockRead reads1[] = { |
| 13114 | CreateMockRead(*resp1, 1), |
| 13115 | CreateMockRead(*body1, 2), |
| 13116 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 13117 | }; |
| 13118 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13119 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13120 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13121 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13122 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13123 | |
| 13124 | // HTTP GET for the HTTP URL |
| 13125 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13126 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13127 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13128 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13129 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13130 | }; |
| 13131 | |
| 13132 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13133 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13134 | MockRead(ASYNC, 2, "hello"), |
| 13135 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13136 | }; |
| 13137 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13138 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13139 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13140 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13141 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13142 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13144 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13145 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13146 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13147 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13148 | |
| 13149 | // Start the first transaction to set up the SpdySession |
| 13150 | HttpRequestInfo request1; |
| 13151 | request1.method = "GET"; |
| 13152 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13153 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13154 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13155 | TestCompletionCallback callback1; |
| 13156 | EXPECT_EQ(ERR_IO_PENDING, |
| 13157 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13158 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13159 | |
| 13160 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13161 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13162 | |
| 13163 | // Now, start the HTTP request |
| 13164 | HttpRequestInfo request2; |
| 13165 | request2.method = "GET"; |
| 13166 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13167 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13168 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13169 | TestCompletionCallback callback2; |
| 13170 | EXPECT_EQ(ERR_IO_PENDING, |
| 13171 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13172 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13173 | |
| 13174 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13175 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13176 | } |
| 13177 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13178 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 13179 | public: |
| 13180 | void Run(bool pooling, bool valid) { |
| 13181 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 13182 | 443); |
| 13183 | HostPortPair alternative("www.example.org", 443); |
| 13184 | |
| 13185 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 13186 | scoped_refptr<X509Certificate> cert( |
| 13187 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 13188 | ASSERT_TRUE(cert.get()); |
| 13189 | bool common_name_fallback_used; |
| 13190 | EXPECT_EQ(valid, |
| 13191 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 13192 | EXPECT_TRUE( |
| 13193 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 13194 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13195 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13196 | ssl.cert = cert; |
| 13197 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13198 | |
| 13199 | // If pooling, then start a request to alternative first to create a |
| 13200 | // SpdySession. |
| 13201 | std::string url0 = "https://www.example.org:443"; |
| 13202 | // Second request to origin, which has an alternative service, and could |
| 13203 | // open a connection to the alternative host or pool to the existing one. |
| 13204 | std::string url1("https://"); |
| 13205 | url1.append(origin.host()); |
| 13206 | url1.append(":443"); |
| 13207 | |
| 13208 | scoped_ptr<SpdyFrame> req0; |
| 13209 | scoped_ptr<SpdyFrame> req1; |
| 13210 | scoped_ptr<SpdyFrame> resp0; |
| 13211 | scoped_ptr<SpdyFrame> body0; |
| 13212 | scoped_ptr<SpdyFrame> resp1; |
| 13213 | scoped_ptr<SpdyFrame> body1; |
| 13214 | std::vector<MockWrite> writes; |
| 13215 | std::vector<MockRead> reads; |
| 13216 | |
| 13217 | if (pooling) { |
| 13218 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13219 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13220 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 13221 | |
| 13222 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 13223 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 13224 | |
| 13225 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13226 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13227 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13228 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 13229 | |
| 13230 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 13231 | reads.push_back(CreateMockRead(*body0, 2)); |
| 13232 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 13233 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 13234 | reads.push_back(CreateMockRead(*body1, 6)); |
| 13235 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 13236 | } else { |
| 13237 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 13238 | |
| 13239 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 13240 | |
| 13241 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13242 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13243 | |
| 13244 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 13245 | reads.push_back(CreateMockRead(*body1, 2)); |
| 13246 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 13247 | } |
| 13248 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13249 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 13250 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13251 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13252 | |
| 13253 | // Connection to the origin fails. |
| 13254 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13255 | StaticSocketDataProvider data_refused; |
| 13256 | data_refused.set_connect_data(mock_connect); |
| 13257 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13258 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13259 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13260 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13261 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13262 | session->http_server_properties(); |
| 13263 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13264 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13265 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13266 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13267 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13268 | |
| 13269 | // First request to alternative. |
| 13270 | if (pooling) { |
| 13271 | scoped_ptr<HttpTransaction> trans0( |
| 13272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13273 | HttpRequestInfo request0; |
| 13274 | request0.method = "GET"; |
| 13275 | request0.url = GURL(url0); |
| 13276 | request0.load_flags = 0; |
| 13277 | TestCompletionCallback callback0; |
| 13278 | |
| 13279 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 13280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13281 | rv = callback0.WaitForResult(); |
| 13282 | EXPECT_EQ(OK, rv); |
| 13283 | } |
| 13284 | |
| 13285 | // Second request to origin. |
| 13286 | scoped_ptr<HttpTransaction> trans1( |
| 13287 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13288 | HttpRequestInfo request1; |
| 13289 | request1.method = "GET"; |
| 13290 | request1.url = GURL(url1); |
| 13291 | request1.load_flags = 0; |
| 13292 | TestCompletionCallback callback1; |
| 13293 | |
| 13294 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13295 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 13296 | base::MessageLoop::current()->RunUntilIdle(); |
| 13297 | if (data.IsReadPaused()) { |
| 13298 | data.CompleteRead(); |
| 13299 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13300 | rv = callback1.WaitForResult(); |
| 13301 | if (valid) { |
| 13302 | EXPECT_EQ(OK, rv); |
| 13303 | } else { |
| 13304 | if (pooling) { |
| 13305 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13306 | } else { |
| 13307 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13308 | } |
| 13309 | } |
| 13310 | } |
| 13311 | }; |
| 13312 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13313 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13314 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13315 | testing::Values(kTestCaseSPDY31, |
| 13316 | kTestCaseHTTP2NoPriorityDependencies, |
| 13317 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13318 | |
| 13319 | // The alternative service host must exhibit a certificate that is valid for the |
| 13320 | // origin host. Test that this is enforced when pooling to an existing |
| 13321 | // connection. |
| 13322 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13323 | Run(true, true); |
| 13324 | } |
| 13325 | |
| 13326 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13327 | Run(true, false); |
| 13328 | } |
| 13329 | |
| 13330 | // The alternative service host must exhibit a certificate that is valid for the |
| 13331 | // origin host. Test that this is enforced when opening a new connection. |
| 13332 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13333 | Run(false, true); |
| 13334 | } |
| 13335 | |
| 13336 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13337 | Run(false, false); |
| 13338 | } |
| 13339 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13340 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13341 | // with the alternative server. That connection should not be used. |
| 13342 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13343 | HostPortPair origin("origin.example.org", 443); |
| 13344 | HostPortPair alternative("alternative.example.org", 443); |
| 13345 | |
| 13346 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13347 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13348 | ssl.SetNextProto(kProtoHTTP11); |
| 13349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13350 | |
| 13351 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13352 | // negotiated. |
| 13353 | StaticSocketDataProvider data; |
| 13354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13355 | |
| 13356 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13357 | // negotiated. In order to test this, a failed connection to the origin is |
| 13358 | // mocked. This way the request relies on the alternate Job. |
| 13359 | StaticSocketDataProvider data_refused; |
| 13360 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13361 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13362 | |
| 13363 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13364 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13365 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13366 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13367 | session->http_server_properties(); |
| 13368 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13369 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13370 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13371 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13372 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13373 | |
| 13374 | scoped_ptr<HttpTransaction> trans( |
| 13375 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13376 | HttpRequestInfo request; |
| 13377 | request.method = "GET"; |
| 13378 | request.url = GURL("https://origin.example.org:443"); |
| 13379 | request.load_flags = 0; |
| 13380 | TestCompletionCallback callback; |
| 13381 | |
| 13382 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13383 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13384 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13385 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13386 | } |
| 13387 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13388 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13389 | // origin, and an alternate one to the alternative server. If the former |
| 13390 | // succeeds, the request should succeed, even if the latter fails because |
| 13391 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13392 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13393 | HostPortPair origin("origin.example.org", 443); |
| 13394 | HostPortPair alternative("alternative.example.org", 443); |
| 13395 | |
| 13396 | // Negotiate HTTP/1.1 with alternative. |
| 13397 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13398 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13400 | |
| 13401 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13402 | // negotiated. |
| 13403 | StaticSocketDataProvider data; |
| 13404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13405 | |
| 13406 | // Negotiate HTTP/1.1 with origin. |
| 13407 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13408 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13410 | |
| 13411 | MockWrite http_writes[] = { |
| 13412 | MockWrite( |
| 13413 | "GET / HTTP/1.1\r\n" |
| 13414 | "Host: origin.example.org\r\n" |
| 13415 | "Connection: keep-alive\r\n\r\n"), |
| 13416 | MockWrite( |
| 13417 | "GET /second HTTP/1.1\r\n" |
| 13418 | "Host: origin.example.org\r\n" |
| 13419 | "Connection: keep-alive\r\n\r\n"), |
| 13420 | }; |
| 13421 | |
| 13422 | MockRead http_reads[] = { |
| 13423 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13424 | MockRead("Content-Type: text/html\r\n"), |
| 13425 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13426 | MockRead("foobar"), |
| 13427 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13428 | MockRead("Content-Type: text/html\r\n"), |
| 13429 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13430 | MockRead("another"), |
| 13431 | }; |
| 13432 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13433 | http_writes, arraysize(http_writes)); |
| 13434 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13435 | |
| 13436 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13437 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13438 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13439 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13440 | session->http_server_properties(); |
| 13441 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13442 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13443 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13444 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13445 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13446 | |
| 13447 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13448 | HttpRequestInfo request1; |
| 13449 | request1.method = "GET"; |
| 13450 | request1.url = GURL("https://origin.example.org:443"); |
| 13451 | request1.load_flags = 0; |
| 13452 | TestCompletionCallback callback1; |
| 13453 | |
| 13454 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13455 | rv = callback1.GetResult(rv); |
| 13456 | EXPECT_EQ(OK, rv); |
| 13457 | |
| 13458 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13459 | ASSERT_TRUE(response1 != nullptr); |
| 13460 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13461 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13462 | |
| 13463 | std::string response_data1; |
| 13464 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13465 | EXPECT_EQ("foobar", response_data1); |
| 13466 | |
| 13467 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13468 | // for alternative service. |
| 13469 | EXPECT_TRUE( |
| 13470 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13471 | |
| 13472 | // Since |alternative_service| is broken, a second transaction to origin |
| 13473 | // should not start an alternate Job. It should pool to existing connection |
| 13474 | // to origin. |
| 13475 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13476 | HttpRequestInfo request2; |
| 13477 | request2.method = "GET"; |
| 13478 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13479 | request2.load_flags = 0; |
| 13480 | TestCompletionCallback callback2; |
| 13481 | |
| 13482 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13483 | rv = callback2.GetResult(rv); |
| 13484 | EXPECT_EQ(OK, rv); |
| 13485 | |
| 13486 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13487 | ASSERT_TRUE(response2 != nullptr); |
| 13488 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13489 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13490 | |
| 13491 | std::string response_data2; |
| 13492 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13493 | EXPECT_EQ("another", response_data2); |
| 13494 | } |
| 13495 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13496 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13497 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13498 | // used. |
| 13499 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13500 | HostPortPair origin("origin.example.org", 443); |
| 13501 | HostPortPair alternative("alternative.example.org", 443); |
| 13502 | std::string origin_url = "https://origin.example.org:443"; |
| 13503 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13504 | |
| 13505 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13506 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13507 | ssl.SetNextProto(kProtoHTTP11); |
| 13508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13509 | |
| 13510 | // HTTP/1.1 data for |request1| and |request2|. |
| 13511 | MockWrite http_writes[] = { |
| 13512 | MockWrite( |
| 13513 | "GET / HTTP/1.1\r\n" |
| 13514 | "Host: alternative.example.org\r\n" |
| 13515 | "Connection: keep-alive\r\n\r\n"), |
| 13516 | MockWrite( |
| 13517 | "GET / HTTP/1.1\r\n" |
| 13518 | "Host: alternative.example.org\r\n" |
| 13519 | "Connection: keep-alive\r\n\r\n"), |
| 13520 | }; |
| 13521 | |
| 13522 | MockRead http_reads[] = { |
| 13523 | MockRead( |
| 13524 | "HTTP/1.1 200 OK\r\n" |
| 13525 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13526 | "Content-Length: 40\r\n\r\n" |
| 13527 | "first HTTP/1.1 response from alternative"), |
| 13528 | MockRead( |
| 13529 | "HTTP/1.1 200 OK\r\n" |
| 13530 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13531 | "Content-Length: 41\r\n\r\n" |
| 13532 | "second HTTP/1.1 response from alternative"), |
| 13533 | }; |
| 13534 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13535 | http_writes, arraysize(http_writes)); |
| 13536 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13537 | |
| 13538 | // This test documents that an alternate Job should not pool to an already |
| 13539 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13540 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13541 | StaticSocketDataProvider data_refused; |
| 13542 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13543 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13544 | |
| 13545 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13546 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13547 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13548 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13549 | session->http_server_properties(); |
| 13550 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13551 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13552 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13553 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13554 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13555 | |
| 13556 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13557 | scoped_ptr<HttpTransaction> trans1( |
| 13558 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13559 | HttpRequestInfo request1; |
| 13560 | request1.method = "GET"; |
| 13561 | request1.url = GURL(alternative_url); |
| 13562 | request1.load_flags = 0; |
| 13563 | TestCompletionCallback callback1; |
| 13564 | |
| 13565 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13566 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13567 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13568 | ASSERT_TRUE(response1); |
| 13569 | ASSERT_TRUE(response1->headers.get()); |
| 13570 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13571 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13572 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13573 | std::string response_data1; |
| 13574 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13575 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13576 | |
| 13577 | // Request for origin.example.org, which has an alternative service. This |
| 13578 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13579 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13580 | // open other connections to alternative server. The Job to origin fails, so |
| 13581 | // this request fails. |
| 13582 | scoped_ptr<HttpTransaction> trans2( |
| 13583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13584 | HttpRequestInfo request2; |
| 13585 | request2.method = "GET"; |
| 13586 | request2.url = GURL(origin_url); |
| 13587 | request2.load_flags = 0; |
| 13588 | TestCompletionCallback callback2; |
| 13589 | |
| 13590 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13591 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13592 | |
| 13593 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13594 | // socket is still open and in the pool. |
| 13595 | scoped_ptr<HttpTransaction> trans3( |
| 13596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13597 | HttpRequestInfo request3; |
| 13598 | request3.method = "GET"; |
| 13599 | request3.url = GURL(alternative_url); |
| 13600 | request3.load_flags = 0; |
| 13601 | TestCompletionCallback callback3; |
| 13602 | |
| 13603 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13604 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13605 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13606 | ASSERT_TRUE(response3); |
| 13607 | ASSERT_TRUE(response3->headers.get()); |
| 13608 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13609 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13610 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13611 | std::string response_data3; |
| 13612 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13613 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13614 | } |
| 13615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13616 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13617 | const std::string https_url = "https://www.example.org:8080/"; |
| 13618 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13619 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13620 | // Separate SPDY util instance for naked and wrapped requests. |
| 13621 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13622 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13623 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13624 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13625 | scoped_ptr<SpdyFrame> connect( |
| 13626 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13627 | scoped_ptr<SpdyFrame> req1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13628 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13629 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13630 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13631 | |
| 13632 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13633 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13634 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13635 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13636 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13637 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13638 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13639 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13640 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13641 | |
| 13642 | MockWrite writes1[] = { |
| 13643 | CreateMockWrite(*connect, 0), |
| 13644 | CreateMockWrite(*wrapped_req1, 2), |
| 13645 | CreateMockWrite(*req2, 5), |
| 13646 | }; |
| 13647 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13648 | scoped_ptr<SpdyFrame> conn_resp( |
| 13649 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13650 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13651 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13652 | scoped_ptr<SpdyFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13653 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13654 | scoped_ptr<SpdyFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13655 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13656 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13657 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13658 | MockRead reads1[] = { |
| 13659 | CreateMockRead(*conn_resp, 1), |
| 13660 | CreateMockRead(*wrapped_resp1, 3), |
| 13661 | CreateMockRead(*wrapped_body1, 4), |
| 13662 | CreateMockRead(*resp2, 6), |
| 13663 | CreateMockRead(*body2, 7), |
| 13664 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 13665 | }; |
| 13666 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13667 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 13668 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13669 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13670 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13671 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13672 | session_deps_.proxy_service = |
| 13673 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13674 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13675 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13676 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13677 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13678 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13679 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13680 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13681 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13682 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13683 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13684 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13685 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13686 | |
| 13687 | // Start the first transaction to set up the SpdySession |
| 13688 | HttpRequestInfo request1; |
| 13689 | request1.method = "GET"; |
| 13690 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13691 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13692 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13693 | TestCompletionCallback callback1; |
| 13694 | EXPECT_EQ(ERR_IO_PENDING, |
| 13695 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13696 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13697 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13698 | |
| 13699 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13700 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13701 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13702 | LoadTimingInfo load_timing_info1; |
| 13703 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13704 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13705 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13706 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13707 | // Now, start the HTTP request |
| 13708 | HttpRequestInfo request2; |
| 13709 | request2.method = "GET"; |
| 13710 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13711 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13712 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13713 | TestCompletionCallback callback2; |
| 13714 | EXPECT_EQ(ERR_IO_PENDING, |
| 13715 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13716 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13717 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13718 | |
| 13719 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13720 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13721 | |
| 13722 | LoadTimingInfo load_timing_info2; |
| 13723 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13724 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13725 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13726 | // HTTP requests over a SPDY session should have a different connection |
| 13727 | // socket_log_id than requests over a tunnel. |
| 13728 | 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] | 13729 | } |
| 13730 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13731 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13732 | // that we do not pool other origins that resolve to the same IP when |
| 13733 | // the certificate does not match the new origin. |
| 13734 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13735 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13736 | const std::string url1 = "http://www.example.org/"; |
| 13737 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13738 | const std::string ip_addr = "1.2.3.4"; |
| 13739 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13740 | // Second SpdyTestUtil instance for the second socket. |
| 13741 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13742 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13743 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13744 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13745 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13746 | scoped_ptr<SpdyFrame> req1( |
| 13747 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13748 | |
| 13749 | MockWrite writes1[] = { |
| 13750 | CreateMockWrite(*req1, 0), |
| 13751 | }; |
| 13752 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13753 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13754 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13755 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13756 | CreateMockRead(*resp1, 1), |
| 13757 | CreateMockRead(*body1, 2), |
| 13758 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13759 | }; |
| 13760 | |
| 13761 | scoped_ptr<DeterministicSocketData> data1( |
| 13762 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 13763 | writes1, arraysize(writes1))); |
| 13764 | IPAddressNumber ip; |
| 13765 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13766 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13767 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 13768 | data1->set_connect_data(connect_data1); |
| 13769 | |
| 13770 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13771 | scoped_ptr<SpdyFrame> req2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13772 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13773 | |
| 13774 | MockWrite writes2[] = { |
| 13775 | CreateMockWrite(*req2, 0), |
| 13776 | }; |
| 13777 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13778 | scoped_ptr<SpdyFrame> resp2( |
| 13779 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13780 | scoped_ptr<SpdyFrame> body2(spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13781 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13782 | CreateMockRead(*resp2, 1), |
| 13783 | CreateMockRead(*body2, 2), |
| 13784 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13785 | }; |
| 13786 | |
| 13787 | scoped_ptr<DeterministicSocketData> data2( |
| 13788 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 13789 | writes2, arraysize(writes2))); |
| 13790 | MockConnect connect_data2(ASYNC, OK); |
| 13791 | data2->set_connect_data(connect_data2); |
| 13792 | |
| 13793 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13794 | // all others direct. |
| 13795 | ProxyConfig proxy_config; |
| 13796 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13797 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13798 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13799 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13800 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13801 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13802 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13803 | // Load a valid cert. Note, that this does not need to |
| 13804 | // be valid for proxy because the MockSSLClientSocket does |
| 13805 | // not actually verify it. But SpdySession will use this |
| 13806 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13807 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13808 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13809 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13810 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13811 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13812 | |
| 13813 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13814 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13815 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13816 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13817 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13818 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13819 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13820 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13821 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13822 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13823 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13824 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13825 | |
| 13826 | // Start the first transaction to set up the SpdySession |
| 13827 | HttpRequestInfo request1; |
| 13828 | request1.method = "GET"; |
| 13829 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13830 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13831 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13832 | TestCompletionCallback callback1; |
| 13833 | ASSERT_EQ(ERR_IO_PENDING, |
| 13834 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 13835 | data1->RunFor(3); |
| 13836 | |
| 13837 | ASSERT_TRUE(callback1.have_result()); |
| 13838 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13839 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13840 | |
| 13841 | // Now, start the HTTP request |
| 13842 | HttpRequestInfo request2; |
| 13843 | request2.method = "GET"; |
| 13844 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13845 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13846 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13847 | TestCompletionCallback callback2; |
| 13848 | EXPECT_EQ(ERR_IO_PENDING, |
| 13849 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13850 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13851 | data2->RunFor(3); |
| 13852 | |
| 13853 | ASSERT_TRUE(callback2.have_result()); |
| 13854 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13855 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13856 | } |
| 13857 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13858 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13859 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13860 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13861 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13862 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13863 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13864 | |
| 13865 | MockRead reads1[] = { |
| 13866 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13867 | }; |
| 13868 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13869 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13870 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13871 | scoped_ptr<SpdyFrame> req2( |
| 13872 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13873 | MockWrite writes2[] = { |
| 13874 | CreateMockWrite(*req2, 0), |
| 13875 | }; |
| 13876 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13877 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13878 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13879 | MockRead reads2[] = { |
| 13880 | CreateMockRead(*resp2, 1), |
| 13881 | CreateMockRead(*body2, 2), |
| 13882 | MockRead(ASYNC, OK, 3) // EOF |
| 13883 | }; |
| 13884 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13885 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13886 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13887 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13888 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13889 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13892 | |
| 13893 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13894 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13896 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13897 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13898 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13899 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13900 | |
| 13901 | // Start the first transaction to set up the SpdySession and verify that |
| 13902 | // connection was closed. |
| 13903 | HttpRequestInfo request1; |
| 13904 | request1.method = "GET"; |
| 13905 | request1.url = GURL(https_url); |
| 13906 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13907 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13908 | TestCompletionCallback callback1; |
| 13909 | EXPECT_EQ(ERR_IO_PENDING, |
| 13910 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13911 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13912 | |
| 13913 | // Now, start the second request and make sure it succeeds. |
| 13914 | HttpRequestInfo request2; |
| 13915 | request2.method = "GET"; |
| 13916 | request2.url = GURL(https_url); |
| 13917 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13918 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13919 | TestCompletionCallback callback2; |
| 13920 | EXPECT_EQ(ERR_IO_PENDING, |
| 13921 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13922 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13923 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13924 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13925 | } |
| 13926 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13927 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13928 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13929 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13930 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13931 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13932 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13933 | |
| 13934 | // Use two different hosts with different IPs so they don't get pooled. |
| 13935 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13936 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13937 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13938 | |
| 13939 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13940 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13941 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13942 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13943 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13945 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13946 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13947 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13948 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13949 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13950 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13951 | scoped_ptr<SpdyFrame> host1_resp( |
| 13952 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13953 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13954 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13955 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13956 | CreateMockRead(*host1_resp, 1), |
| 13957 | CreateMockRead(*host1_resp_body, 2), |
| 13958 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13959 | }; |
| 13960 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13961 | // Use a separate test instance for the separate SpdySession that will be |
| 13962 | // created. |
| 13963 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13964 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13965 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13966 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13967 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13968 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13969 | scoped_ptr<SpdyFrame> host2_req(spdy_util_2.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13970 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13971 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13972 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13973 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13974 | scoped_ptr<SpdyFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13975 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13976 | scoped_ptr<SpdyFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13977 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13978 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13979 | CreateMockRead(*host2_resp, 1), |
| 13980 | CreateMockRead(*host2_resp_body, 2), |
| 13981 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13982 | }; |
| 13983 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13984 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13985 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13986 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13987 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13988 | |
| 13989 | MockWrite http_write[] = { |
| 13990 | MockWrite("GET / HTTP/1.1\r\n" |
| 13991 | "Host: www.a.com\r\n" |
| 13992 | "Connection: keep-alive\r\n\r\n"), |
| 13993 | }; |
| 13994 | |
| 13995 | MockRead http_read[] = { |
| 13996 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13997 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13998 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13999 | MockRead("hello!"), |
| 14000 | }; |
| 14001 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14002 | http_write, arraysize(http_write)); |
| 14003 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14004 | |
| 14005 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14006 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14007 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14008 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14009 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14010 | |
| 14011 | TestCompletionCallback callback; |
| 14012 | HttpRequestInfo request1; |
| 14013 | request1.method = "GET"; |
| 14014 | request1.url = GURL("https://www.a.com/"); |
| 14015 | request1.load_flags = 0; |
| 14016 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14018 | |
| 14019 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 14020 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14021 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14022 | |
| 14023 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14024 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14025 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14026 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14027 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14028 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14029 | |
| 14030 | std::string response_data; |
| 14031 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14032 | EXPECT_EQ("hello!", response_data); |
| 14033 | trans.reset(); |
| 14034 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14035 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14036 | |
| 14037 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14038 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14039 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14040 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14041 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14042 | HttpRequestInfo request2; |
| 14043 | request2.method = "GET"; |
| 14044 | request2.url = GURL("https://www.b.com/"); |
| 14045 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14046 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14047 | |
| 14048 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 14049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14050 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14051 | |
| 14052 | response = trans->GetResponseInfo(); |
| 14053 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14054 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14055 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14056 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14057 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14058 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14059 | EXPECT_EQ("hello!", response_data); |
| 14060 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14061 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14062 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14063 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14064 | |
| 14065 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14066 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14067 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14068 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14069 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14070 | HttpRequestInfo request3; |
| 14071 | request3.method = "GET"; |
| 14072 | request3.url = GURL("http://www.a.com/"); |
| 14073 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14074 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14075 | |
| 14076 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 14077 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14078 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14079 | |
| 14080 | response = trans->GetResponseInfo(); |
| 14081 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14082 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14083 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14084 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 14085 | EXPECT_FALSE(response->was_npn_negotiated); |
| 14086 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14087 | EXPECT_EQ("hello!", response_data); |
| 14088 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14089 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14090 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14091 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14092 | } |
| 14093 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14094 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 14095 | HttpRequestInfo request; |
| 14096 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14097 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14098 | request.load_flags = 0; |
| 14099 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14100 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14101 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14102 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14103 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14104 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14105 | StaticSocketDataProvider data; |
| 14106 | data.set_connect_data(mock_connect); |
| 14107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14108 | |
| 14109 | TestCompletionCallback callback; |
| 14110 | |
| 14111 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14113 | |
| 14114 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14115 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14116 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14117 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14118 | HttpRequestHeaders request_headers; |
| 14119 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14120 | |
| 14121 | ConnectionAttempts attempts; |
| 14122 | trans->GetConnectionAttempts(&attempts); |
| 14123 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14124 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14125 | |
| 14126 | IPEndPoint endpoint; |
| 14127 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14128 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14129 | } |
| 14130 | |
| 14131 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 14132 | HttpRequestInfo request; |
| 14133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14134 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14135 | request.load_flags = 0; |
| 14136 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14137 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14138 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14139 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14140 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14141 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14142 | StaticSocketDataProvider data; |
| 14143 | data.set_connect_data(mock_connect); |
| 14144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14145 | |
| 14146 | TestCompletionCallback callback; |
| 14147 | |
| 14148 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14149 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14150 | |
| 14151 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14152 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14153 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14154 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14155 | HttpRequestHeaders request_headers; |
| 14156 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14157 | |
| 14158 | ConnectionAttempts attempts; |
| 14159 | trans->GetConnectionAttempts(&attempts); |
| 14160 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14161 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14162 | |
| 14163 | IPEndPoint endpoint; |
| 14164 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14165 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14166 | } |
| 14167 | |
| 14168 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14169 | HttpRequestInfo request; |
| 14170 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14171 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14172 | request.load_flags = 0; |
| 14173 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14174 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14175 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14177 | |
| 14178 | MockWrite data_writes[] = { |
| 14179 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14180 | }; |
| 14181 | MockRead data_reads[] = { |
| 14182 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14183 | }; |
| 14184 | |
| 14185 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14186 | data_writes, arraysize(data_writes)); |
| 14187 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14188 | |
| 14189 | TestCompletionCallback callback; |
| 14190 | |
| 14191 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14192 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14193 | |
| 14194 | rv = callback.WaitForResult(); |
| 14195 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14196 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14197 | HttpRequestHeaders request_headers; |
| 14198 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14199 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14200 | } |
| 14201 | |
| 14202 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 14203 | HttpRequestInfo request; |
| 14204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14205 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14206 | request.load_flags = 0; |
| 14207 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14208 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14209 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14211 | |
| 14212 | MockWrite data_writes[] = { |
| 14213 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14214 | }; |
| 14215 | MockRead data_reads[] = { |
| 14216 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14217 | }; |
| 14218 | |
| 14219 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14220 | data_writes, arraysize(data_writes)); |
| 14221 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14222 | |
| 14223 | TestCompletionCallback callback; |
| 14224 | |
| 14225 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14226 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14227 | |
| 14228 | rv = callback.WaitForResult(); |
| 14229 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14230 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14231 | HttpRequestHeaders request_headers; |
| 14232 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14233 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14234 | } |
| 14235 | |
| 14236 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 14237 | HttpRequestInfo request; |
| 14238 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14239 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14240 | request.load_flags = 0; |
| 14241 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14242 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14243 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14245 | |
| 14246 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14247 | MockWrite( |
| 14248 | "GET / HTTP/1.1\r\n" |
| 14249 | "Host: www.example.org\r\n" |
| 14250 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14251 | }; |
| 14252 | MockRead data_reads[] = { |
| 14253 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14254 | }; |
| 14255 | |
| 14256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14257 | data_writes, arraysize(data_writes)); |
| 14258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14259 | |
| 14260 | TestCompletionCallback callback; |
| 14261 | |
| 14262 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14264 | |
| 14265 | rv = callback.WaitForResult(); |
| 14266 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14267 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14268 | HttpRequestHeaders request_headers; |
| 14269 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14270 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14271 | } |
| 14272 | |
| 14273 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 14274 | HttpRequestInfo request; |
| 14275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14276 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14277 | request.load_flags = 0; |
| 14278 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14279 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14280 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14282 | |
| 14283 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14284 | MockWrite( |
| 14285 | "GET / HTTP/1.1\r\n" |
| 14286 | "Host: www.example.org\r\n" |
| 14287 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14288 | }; |
| 14289 | MockRead data_reads[] = { |
| 14290 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14291 | }; |
| 14292 | |
| 14293 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14294 | data_writes, arraysize(data_writes)); |
| 14295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14296 | |
| 14297 | TestCompletionCallback callback; |
| 14298 | |
| 14299 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14300 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14301 | |
| 14302 | rv = callback.WaitForResult(); |
| 14303 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14304 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14305 | HttpRequestHeaders request_headers; |
| 14306 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14307 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14308 | } |
| 14309 | |
| 14310 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14311 | HttpRequestInfo request; |
| 14312 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14313 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14314 | request.load_flags = 0; |
| 14315 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14316 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14317 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14318 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14319 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14320 | |
| 14321 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14322 | MockWrite( |
| 14323 | "GET / HTTP/1.1\r\n" |
| 14324 | "Host: www.example.org\r\n" |
| 14325 | "Connection: keep-alive\r\n" |
| 14326 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14327 | }; |
| 14328 | MockRead data_reads[] = { |
| 14329 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14330 | "Content-Length: 5\r\n\r\n" |
| 14331 | "hello"), |
| 14332 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14333 | }; |
| 14334 | |
| 14335 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14336 | data_writes, arraysize(data_writes)); |
| 14337 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14338 | |
| 14339 | TestCompletionCallback callback; |
| 14340 | |
| 14341 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14342 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14343 | |
| 14344 | rv = callback.WaitForResult(); |
| 14345 | EXPECT_EQ(OK, rv); |
| 14346 | |
| 14347 | HttpRequestHeaders request_headers; |
| 14348 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14349 | std::string foo; |
| 14350 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14351 | EXPECT_EQ("bar", foo); |
| 14352 | } |
| 14353 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14354 | namespace { |
| 14355 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14356 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14357 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14358 | public base::SupportsWeakPtr<FakeStream> { |
| 14359 | public: |
| 14360 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14361 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14362 | |
| 14363 | RequestPriority priority() const { return priority_; } |
| 14364 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14365 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14366 | RequestPriority priority, |
| 14367 | const BoundNetLog& net_log, |
| 14368 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14369 | return ERR_IO_PENDING; |
| 14370 | } |
| 14371 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14372 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14373 | HttpResponseInfo* response, |
| 14374 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14375 | ADD_FAILURE(); |
| 14376 | return ERR_UNEXPECTED; |
| 14377 | } |
| 14378 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14379 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14380 | ADD_FAILURE(); |
| 14381 | return ERR_UNEXPECTED; |
| 14382 | } |
| 14383 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14384 | int ReadResponseBody(IOBuffer* buf, |
| 14385 | int buf_len, |
| 14386 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14387 | ADD_FAILURE(); |
| 14388 | return ERR_UNEXPECTED; |
| 14389 | } |
| 14390 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14391 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14392 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14393 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14394 | ADD_FAILURE(); |
| 14395 | return false; |
| 14396 | } |
| 14397 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14398 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14399 | ADD_FAILURE(); |
| 14400 | return false; |
| 14401 | } |
| 14402 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14403 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14404 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14405 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14406 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14407 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14408 | ADD_FAILURE(); |
| 14409 | return 0; |
| 14410 | } |
| 14411 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14412 | int64_t GetTotalSentBytes() const override { |
| 14413 | ADD_FAILURE(); |
| 14414 | return 0; |
| 14415 | } |
| 14416 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14417 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14418 | ADD_FAILURE(); |
| 14419 | return false; |
| 14420 | } |
| 14421 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14422 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14423 | |
| 14424 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14425 | ADD_FAILURE(); |
| 14426 | } |
| 14427 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14428 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14429 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14430 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14431 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14432 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14433 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14434 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14435 | |
| 14436 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14437 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14438 | private: |
| 14439 | RequestPriority priority_; |
| 14440 | |
| 14441 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14442 | }; |
| 14443 | |
| 14444 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14445 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14446 | class FakeStreamRequest : public HttpStreamRequest, |
| 14447 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14448 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14449 | FakeStreamRequest(RequestPriority priority, |
| 14450 | HttpStreamRequest::Delegate* delegate) |
| 14451 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14452 | delegate_(delegate), |
| 14453 | websocket_stream_create_helper_(NULL) {} |
| 14454 | |
| 14455 | FakeStreamRequest(RequestPriority priority, |
| 14456 | HttpStreamRequest::Delegate* delegate, |
| 14457 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14458 | : priority_(priority), |
| 14459 | delegate_(delegate), |
| 14460 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14461 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14462 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14463 | |
| 14464 | RequestPriority priority() const { return priority_; } |
| 14465 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14466 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14467 | websocket_stream_create_helper() const { |
| 14468 | return websocket_stream_create_helper_; |
| 14469 | } |
| 14470 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14471 | // Create a new FakeStream and pass it to the request's |
| 14472 | // delegate. Returns a weak pointer to the FakeStream. |
| 14473 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14474 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14475 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14476 | // immediately delete |fake_stream|. |
| 14477 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14478 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14479 | return weak_stream; |
| 14480 | } |
| 14481 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14482 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14483 | ADD_FAILURE(); |
| 14484 | return ERR_UNEXPECTED; |
| 14485 | } |
| 14486 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14487 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14488 | ADD_FAILURE(); |
| 14489 | return LoadState(); |
| 14490 | } |
| 14491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14492 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14493 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14494 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14495 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14496 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14497 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14498 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14499 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14500 | const ConnectionAttempts& connection_attempts() const override { |
| 14501 | static ConnectionAttempts no_attempts; |
| 14502 | return no_attempts; |
| 14503 | } |
| 14504 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14505 | private: |
| 14506 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14507 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14508 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14509 | |
| 14510 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14511 | }; |
| 14512 | |
| 14513 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14514 | class FakeStreamFactory : public HttpStreamFactory { |
| 14515 | public: |
| 14516 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14517 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14518 | |
| 14519 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14520 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14521 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14522 | return last_stream_request_; |
| 14523 | } |
| 14524 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14525 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14526 | RequestPriority priority, |
| 14527 | const SSLConfig& server_ssl_config, |
| 14528 | const SSLConfig& proxy_ssl_config, |
| 14529 | HttpStreamRequest::Delegate* delegate, |
| 14530 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14531 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14532 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14533 | return fake_request; |
| 14534 | } |
| 14535 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14536 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14537 | const HttpRequestInfo& info, |
| 14538 | RequestPriority priority, |
| 14539 | const SSLConfig& server_ssl_config, |
| 14540 | const SSLConfig& proxy_ssl_config, |
| 14541 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14542 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14543 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14544 | FakeStreamRequest* fake_request = |
| 14545 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14546 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14547 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14548 | } |
| 14549 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14550 | void PreconnectStreams(int num_streams, |
| 14551 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14552 | const SSLConfig& server_ssl_config, |
| 14553 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14554 | ADD_FAILURE(); |
| 14555 | } |
| 14556 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14557 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14558 | ADD_FAILURE(); |
| 14559 | return NULL; |
| 14560 | } |
| 14561 | |
| 14562 | private: |
| 14563 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14564 | |
| 14565 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14566 | }; |
| 14567 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14568 | // TODO(ricea): Maybe unify this with the one in |
| 14569 | // url_request_http_job_unittest.cc ? |
| 14570 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14571 | public: |
| 14572 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14573 | bool using_proxy) |
| 14574 | : state_(connection.release(), using_proxy) {} |
| 14575 | |
| 14576 | // Fake implementation of HttpStreamBase methods. |
| 14577 | // This ends up being quite "real" because this object has to really send data |
| 14578 | // on the mock socket. It might be easier to use the real implementation, but |
| 14579 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14580 | // difficult. |
| 14581 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14582 | RequestPriority priority, |
| 14583 | const BoundNetLog& net_log, |
| 14584 | const CompletionCallback& callback) override { |
| 14585 | state_.Initialize(request_info, priority, net_log, callback); |
| 14586 | return OK; |
| 14587 | } |
| 14588 | |
| 14589 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14590 | HttpResponseInfo* response, |
| 14591 | const CompletionCallback& callback) override { |
| 14592 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14593 | response, callback); |
| 14594 | } |
| 14595 | |
| 14596 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14597 | return parser()->ReadResponseHeaders(callback); |
| 14598 | } |
| 14599 | |
| 14600 | int ReadResponseBody(IOBuffer* buf, |
| 14601 | int buf_len, |
| 14602 | const CompletionCallback& callback) override { |
| 14603 | NOTREACHED(); |
| 14604 | return ERR_IO_PENDING; |
| 14605 | } |
| 14606 | |
| 14607 | void Close(bool not_reusable) override { |
| 14608 | if (parser()) |
| 14609 | parser()->Close(true); |
| 14610 | } |
| 14611 | |
| 14612 | bool IsResponseBodyComplete() const override { |
| 14613 | NOTREACHED(); |
| 14614 | return false; |
| 14615 | } |
| 14616 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14617 | bool IsConnectionReused() const override { |
| 14618 | NOTREACHED(); |
| 14619 | return false; |
| 14620 | } |
| 14621 | void SetConnectionReused() override { NOTREACHED(); } |
| 14622 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14623 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14624 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14625 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14626 | NOTREACHED(); |
| 14627 | return 0; |
| 14628 | } |
| 14629 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14630 | int64_t GetTotalSentBytes() const override { |
| 14631 | NOTREACHED(); |
| 14632 | return 0; |
| 14633 | } |
| 14634 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14635 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14636 | NOTREACHED(); |
| 14637 | return false; |
| 14638 | } |
| 14639 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14640 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14641 | |
| 14642 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14643 | NOTREACHED(); |
| 14644 | } |
| 14645 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14646 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14647 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14648 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14649 | |
| 14650 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14651 | |
| 14652 | UploadProgress GetUploadProgress() const override { |
| 14653 | NOTREACHED(); |
| 14654 | return UploadProgress(); |
| 14655 | } |
| 14656 | |
| 14657 | HttpStream* RenewStreamForAuth() override { |
| 14658 | NOTREACHED(); |
| 14659 | return nullptr; |
| 14660 | } |
| 14661 | |
| 14662 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14663 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14664 | NOTREACHED(); |
| 14665 | return scoped_ptr<WebSocketStream>(); |
| 14666 | } |
| 14667 | |
| 14668 | private: |
| 14669 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14670 | HttpBasicState state_; |
| 14671 | |
| 14672 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14673 | }; |
| 14674 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14675 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14676 | // worth doing. |
| 14677 | class FakeWebSocketStreamCreateHelper : |
| 14678 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14679 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14680 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14681 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14682 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14683 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 14684 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14685 | } |
| 14686 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14687 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14688 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14689 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14690 | NOTREACHED(); |
| 14691 | return NULL; |
| 14692 | }; |
| 14693 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14694 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14695 | |
| 14696 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14697 | NOTREACHED(); |
| 14698 | return scoped_ptr<WebSocketStream>(); |
| 14699 | } |
| 14700 | }; |
| 14701 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14702 | } // namespace |
| 14703 | |
| 14704 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14705 | // stream request on start. |
| 14706 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14707 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14708 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14709 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14710 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14711 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14712 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14713 | |
| 14714 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14715 | |
| 14716 | HttpRequestInfo request; |
| 14717 | TestCompletionCallback callback; |
| 14718 | EXPECT_EQ(ERR_IO_PENDING, |
| 14719 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14720 | |
| 14721 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14722 | fake_factory->last_stream_request(); |
| 14723 | ASSERT_TRUE(fake_request != NULL); |
| 14724 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14725 | } |
| 14726 | |
| 14727 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14728 | // updates to its stream request. |
| 14729 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14730 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14731 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14732 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14733 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14734 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14735 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14736 | |
| 14737 | HttpRequestInfo request; |
| 14738 | TestCompletionCallback callback; |
| 14739 | EXPECT_EQ(ERR_IO_PENDING, |
| 14740 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14741 | |
| 14742 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14743 | fake_factory->last_stream_request(); |
| 14744 | ASSERT_TRUE(fake_request != NULL); |
| 14745 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14746 | |
| 14747 | trans.SetPriority(LOWEST); |
| 14748 | ASSERT_TRUE(fake_request != NULL); |
| 14749 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14750 | } |
| 14751 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14752 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14753 | // updates to its stream. |
| 14754 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14755 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14756 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14757 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14758 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14759 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14760 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14761 | |
| 14762 | HttpRequestInfo request; |
| 14763 | TestCompletionCallback callback; |
| 14764 | EXPECT_EQ(ERR_IO_PENDING, |
| 14765 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14766 | |
| 14767 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14768 | fake_factory->last_stream_request(); |
| 14769 | ASSERT_TRUE(fake_request != NULL); |
| 14770 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14771 | ASSERT_TRUE(fake_stream != NULL); |
| 14772 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14773 | |
| 14774 | trans.SetPriority(LOWEST); |
| 14775 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14776 | } |
| 14777 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14778 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14779 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14780 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14781 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14782 | std::string test_cases[] = {"ws://www.example.org/", |
| 14783 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14784 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14785 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14786 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14787 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14788 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14789 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14790 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14791 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14792 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14793 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14794 | &websocket_stream_create_helper); |
| 14795 | |
| 14796 | HttpRequestInfo request; |
| 14797 | TestCompletionCallback callback; |
| 14798 | request.method = "GET"; |
| 14799 | request.url = GURL(test_cases[i]); |
| 14800 | |
| 14801 | EXPECT_EQ(ERR_IO_PENDING, |
| 14802 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14803 | |
| 14804 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14805 | fake_factory->last_stream_request(); |
| 14806 | ASSERT_TRUE(fake_request != NULL); |
| 14807 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14808 | fake_request->websocket_stream_create_helper()); |
| 14809 | } |
| 14810 | } |
| 14811 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14812 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14813 | // if the transport socket pool is stalled on the global socket limit. |
| 14814 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14815 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14816 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14817 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14818 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14819 | |
| 14820 | // Set up SSL request. |
| 14821 | |
| 14822 | HttpRequestInfo ssl_request; |
| 14823 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14824 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14825 | |
| 14826 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14827 | MockWrite( |
| 14828 | "GET / HTTP/1.1\r\n" |
| 14829 | "Host: www.example.org\r\n" |
| 14830 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14831 | }; |
| 14832 | MockRead ssl_reads[] = { |
| 14833 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14834 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14835 | MockRead("hello world"), |
| 14836 | MockRead(SYNCHRONOUS, OK), |
| 14837 | }; |
| 14838 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14839 | ssl_writes, arraysize(ssl_writes)); |
| 14840 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14841 | |
| 14842 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14844 | |
| 14845 | // Set up HTTP request. |
| 14846 | |
| 14847 | HttpRequestInfo http_request; |
| 14848 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14849 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14850 | |
| 14851 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14852 | MockWrite( |
| 14853 | "GET / HTTP/1.1\r\n" |
| 14854 | "Host: www.example.org\r\n" |
| 14855 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14856 | }; |
| 14857 | MockRead http_reads[] = { |
| 14858 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14859 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14860 | MockRead("falafel"), |
| 14861 | MockRead(SYNCHRONOUS, OK), |
| 14862 | }; |
| 14863 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14864 | http_writes, arraysize(http_writes)); |
| 14865 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14866 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14867 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14868 | |
| 14869 | // Start the SSL request. |
| 14870 | TestCompletionCallback ssl_callback; |
| 14871 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14872 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14873 | ASSERT_EQ(ERR_IO_PENDING, |
| 14874 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14875 | BoundNetLog())); |
| 14876 | |
| 14877 | // Start the HTTP request. Pool should stall. |
| 14878 | TestCompletionCallback http_callback; |
| 14879 | scoped_ptr<HttpTransaction> http_trans( |
| 14880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14881 | ASSERT_EQ(ERR_IO_PENDING, |
| 14882 | http_trans->Start(&http_request, http_callback.callback(), |
| 14883 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14884 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14885 | |
| 14886 | // Wait for response from SSL request. |
| 14887 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14888 | std::string response_data; |
| 14889 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14890 | EXPECT_EQ("hello world", response_data); |
| 14891 | |
| 14892 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14893 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14894 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14895 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14896 | |
| 14897 | // The HTTP request can now complete. |
| 14898 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14899 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14900 | EXPECT_EQ("falafel", response_data); |
| 14901 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14902 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14903 | } |
| 14904 | |
| 14905 | // Tests that when a SSL connection is established but there's no corresponding |
| 14906 | // request that needs it, the new socket is closed if the transport socket pool |
| 14907 | // is stalled on the global socket limit. |
| 14908 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14909 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14910 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14911 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14912 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14913 | |
| 14914 | // Set up an ssl request. |
| 14915 | |
| 14916 | HttpRequestInfo ssl_request; |
| 14917 | ssl_request.method = "GET"; |
| 14918 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14919 | |
| 14920 | // No data will be sent on the SSL socket. |
| 14921 | StaticSocketDataProvider ssl_data; |
| 14922 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14923 | |
| 14924 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14926 | |
| 14927 | // Set up HTTP request. |
| 14928 | |
| 14929 | HttpRequestInfo http_request; |
| 14930 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14931 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14932 | |
| 14933 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14934 | MockWrite( |
| 14935 | "GET / HTTP/1.1\r\n" |
| 14936 | "Host: www.example.org\r\n" |
| 14937 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14938 | }; |
| 14939 | MockRead http_reads[] = { |
| 14940 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14941 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14942 | MockRead("falafel"), |
| 14943 | MockRead(SYNCHRONOUS, OK), |
| 14944 | }; |
| 14945 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14946 | http_writes, arraysize(http_writes)); |
| 14947 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14948 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14949 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14950 | |
| 14951 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14952 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14953 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14954 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14955 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 14956 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14957 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14958 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14959 | |
| 14960 | // Start the HTTP request. Pool should stall. |
| 14961 | TestCompletionCallback http_callback; |
| 14962 | scoped_ptr<HttpTransaction> http_trans( |
| 14963 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14964 | ASSERT_EQ(ERR_IO_PENDING, |
| 14965 | http_trans->Start(&http_request, http_callback.callback(), |
| 14966 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14967 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14968 | |
| 14969 | // The SSL connection will automatically be closed once the connection is |
| 14970 | // established, to let the HTTP request start. |
| 14971 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14972 | std::string response_data; |
| 14973 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14974 | EXPECT_EQ("falafel", response_data); |
| 14975 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14976 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14977 | } |
| 14978 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14979 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14980 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14981 | element_readers.push_back( |
| 14982 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14983 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14984 | |
| 14985 | HttpRequestInfo request; |
| 14986 | request.method = "POST"; |
| 14987 | request.url = GURL("http://www.foo.com/"); |
| 14988 | request.upload_data_stream = &upload_data_stream; |
| 14989 | request.load_flags = 0; |
| 14990 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14991 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14992 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14994 | // Send headers successfully, but get an error while sending the body. |
| 14995 | MockWrite data_writes[] = { |
| 14996 | MockWrite("POST / HTTP/1.1\r\n" |
| 14997 | "Host: www.foo.com\r\n" |
| 14998 | "Connection: keep-alive\r\n" |
| 14999 | "Content-Length: 3\r\n\r\n"), |
| 15000 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15001 | }; |
| 15002 | |
| 15003 | MockRead data_reads[] = { |
| 15004 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15005 | MockRead("hello world"), |
| 15006 | MockRead(SYNCHRONOUS, OK), |
| 15007 | }; |
| 15008 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15009 | arraysize(data_writes)); |
| 15010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15011 | |
| 15012 | TestCompletionCallback callback; |
| 15013 | |
| 15014 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15015 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15016 | |
| 15017 | rv = callback.WaitForResult(); |
| 15018 | EXPECT_EQ(OK, rv); |
| 15019 | |
| 15020 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15021 | ASSERT_TRUE(response != NULL); |
| 15022 | |
| 15023 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15024 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15025 | |
| 15026 | std::string response_data; |
| 15027 | rv = ReadTransaction(trans.get(), &response_data); |
| 15028 | EXPECT_EQ(OK, rv); |
| 15029 | EXPECT_EQ("hello world", response_data); |
| 15030 | } |
| 15031 | |
| 15032 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15033 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 15034 | TEST_P(HttpNetworkTransactionTest, |
| 15035 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15036 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15037 | MockWrite data_writes[] = { |
| 15038 | MockWrite("GET / HTTP/1.1\r\n" |
| 15039 | "Host: www.foo.com\r\n" |
| 15040 | "Connection: keep-alive\r\n\r\n"), |
| 15041 | MockWrite("POST / HTTP/1.1\r\n" |
| 15042 | "Host: www.foo.com\r\n" |
| 15043 | "Connection: keep-alive\r\n" |
| 15044 | "Content-Length: 3\r\n\r\n"), |
| 15045 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15046 | }; |
| 15047 | |
| 15048 | MockRead data_reads[] = { |
| 15049 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15050 | "Content-Length: 14\r\n\r\n"), |
| 15051 | MockRead("first response"), |
| 15052 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15053 | "Content-Length: 15\r\n\r\n"), |
| 15054 | MockRead("second response"), |
| 15055 | MockRead(SYNCHRONOUS, OK), |
| 15056 | }; |
| 15057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15058 | arraysize(data_writes)); |
| 15059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15060 | |
| 15061 | TestCompletionCallback callback; |
| 15062 | HttpRequestInfo request1; |
| 15063 | request1.method = "GET"; |
| 15064 | request1.url = GURL("http://www.foo.com/"); |
| 15065 | request1.load_flags = 0; |
| 15066 | |
| 15067 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15068 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15069 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 15070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15071 | |
| 15072 | rv = callback.WaitForResult(); |
| 15073 | EXPECT_EQ(OK, rv); |
| 15074 | |
| 15075 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 15076 | ASSERT_TRUE(response1 != NULL); |
| 15077 | |
| 15078 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 15079 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15080 | |
| 15081 | std::string response_data1; |
| 15082 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 15083 | EXPECT_EQ(OK, rv); |
| 15084 | EXPECT_EQ("first response", response_data1); |
| 15085 | // Delete the transaction to release the socket back into the socket pool. |
| 15086 | trans1.reset(); |
| 15087 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15088 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15089 | element_readers.push_back( |
| 15090 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15091 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15092 | |
| 15093 | HttpRequestInfo request2; |
| 15094 | request2.method = "POST"; |
| 15095 | request2.url = GURL("http://www.foo.com/"); |
| 15096 | request2.upload_data_stream = &upload_data_stream; |
| 15097 | request2.load_flags = 0; |
| 15098 | |
| 15099 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15100 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15101 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 15102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15103 | |
| 15104 | rv = callback.WaitForResult(); |
| 15105 | EXPECT_EQ(OK, rv); |
| 15106 | |
| 15107 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 15108 | ASSERT_TRUE(response2 != NULL); |
| 15109 | |
| 15110 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 15111 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15112 | |
| 15113 | std::string response_data2; |
| 15114 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 15115 | EXPECT_EQ(OK, rv); |
| 15116 | EXPECT_EQ("second response", response_data2); |
| 15117 | } |
| 15118 | |
| 15119 | TEST_P(HttpNetworkTransactionTest, |
| 15120 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15121 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15122 | element_readers.push_back( |
| 15123 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15124 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15125 | |
| 15126 | HttpRequestInfo request; |
| 15127 | request.method = "POST"; |
| 15128 | request.url = GURL("http://www.foo.com/"); |
| 15129 | request.upload_data_stream = &upload_data_stream; |
| 15130 | request.load_flags = 0; |
| 15131 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15132 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15133 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15134 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15135 | // Send headers successfully, but get an error while sending the body. |
| 15136 | MockWrite data_writes[] = { |
| 15137 | MockWrite("POST / HTTP/1.1\r\n" |
| 15138 | "Host: www.foo.com\r\n" |
| 15139 | "Connection: keep-alive\r\n" |
| 15140 | "Content-Length: 3\r\n\r\n" |
| 15141 | "fo"), |
| 15142 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15143 | }; |
| 15144 | |
| 15145 | MockRead data_reads[] = { |
| 15146 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15147 | MockRead("hello world"), |
| 15148 | MockRead(SYNCHRONOUS, OK), |
| 15149 | }; |
| 15150 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15151 | arraysize(data_writes)); |
| 15152 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15153 | |
| 15154 | TestCompletionCallback callback; |
| 15155 | |
| 15156 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15157 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15158 | |
| 15159 | rv = callback.WaitForResult(); |
| 15160 | EXPECT_EQ(OK, rv); |
| 15161 | |
| 15162 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15163 | ASSERT_TRUE(response != NULL); |
| 15164 | |
| 15165 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15166 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15167 | |
| 15168 | std::string response_data; |
| 15169 | rv = ReadTransaction(trans.get(), &response_data); |
| 15170 | EXPECT_EQ(OK, rv); |
| 15171 | EXPECT_EQ("hello world", response_data); |
| 15172 | } |
| 15173 | |
| 15174 | // This tests the more common case than the previous test, where headers and |
| 15175 | // body are not merged into a single request. |
| 15176 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15177 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15178 | |
| 15179 | HttpRequestInfo request; |
| 15180 | request.method = "POST"; |
| 15181 | request.url = GURL("http://www.foo.com/"); |
| 15182 | request.upload_data_stream = &upload_data_stream; |
| 15183 | request.load_flags = 0; |
| 15184 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15185 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15186 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15187 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15188 | // Send headers successfully, but get an error while sending the body. |
| 15189 | MockWrite data_writes[] = { |
| 15190 | MockWrite("POST / HTTP/1.1\r\n" |
| 15191 | "Host: www.foo.com\r\n" |
| 15192 | "Connection: keep-alive\r\n" |
| 15193 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15194 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15195 | }; |
| 15196 | |
| 15197 | MockRead data_reads[] = { |
| 15198 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15199 | MockRead("hello world"), |
| 15200 | MockRead(SYNCHRONOUS, OK), |
| 15201 | }; |
| 15202 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15203 | arraysize(data_writes)); |
| 15204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15205 | |
| 15206 | TestCompletionCallback callback; |
| 15207 | |
| 15208 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15209 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15210 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15211 | // they can't be merged with the body in a single send. Not currently |
| 15212 | // necessary since a chunked body is never merged with headers, but this makes |
| 15213 | // the test more future proof. |
| 15214 | base::RunLoop().RunUntilIdle(); |
| 15215 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15216 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15217 | |
| 15218 | rv = callback.WaitForResult(); |
| 15219 | EXPECT_EQ(OK, rv); |
| 15220 | |
| 15221 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15222 | ASSERT_TRUE(response != NULL); |
| 15223 | |
| 15224 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15225 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15226 | |
| 15227 | std::string response_data; |
| 15228 | rv = ReadTransaction(trans.get(), &response_data); |
| 15229 | EXPECT_EQ(OK, rv); |
| 15230 | EXPECT_EQ("hello world", response_data); |
| 15231 | } |
| 15232 | |
| 15233 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15234 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15235 | element_readers.push_back( |
| 15236 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15237 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15238 | |
| 15239 | HttpRequestInfo request; |
| 15240 | request.method = "POST"; |
| 15241 | request.url = GURL("http://www.foo.com/"); |
| 15242 | request.upload_data_stream = &upload_data_stream; |
| 15243 | request.load_flags = 0; |
| 15244 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15245 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15246 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15247 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15248 | |
| 15249 | MockWrite data_writes[] = { |
| 15250 | MockWrite("POST / HTTP/1.1\r\n" |
| 15251 | "Host: www.foo.com\r\n" |
| 15252 | "Connection: keep-alive\r\n" |
| 15253 | "Content-Length: 3\r\n\r\n"), |
| 15254 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15255 | }; |
| 15256 | |
| 15257 | MockRead data_reads[] = { |
| 15258 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15259 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15260 | MockRead("hello world"), |
| 15261 | MockRead(SYNCHRONOUS, OK), |
| 15262 | }; |
| 15263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15264 | arraysize(data_writes)); |
| 15265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15266 | |
| 15267 | TestCompletionCallback callback; |
| 15268 | |
| 15269 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15270 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15271 | |
| 15272 | rv = callback.WaitForResult(); |
| 15273 | EXPECT_EQ(OK, rv); |
| 15274 | |
| 15275 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15276 | ASSERT_TRUE(response != NULL); |
| 15277 | |
| 15278 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15279 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15280 | |
| 15281 | std::string response_data; |
| 15282 | rv = ReadTransaction(trans.get(), &response_data); |
| 15283 | EXPECT_EQ(OK, rv); |
| 15284 | EXPECT_EQ("hello world", response_data); |
| 15285 | } |
| 15286 | |
| 15287 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15288 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15289 | element_readers.push_back( |
| 15290 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15291 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15292 | |
| 15293 | HttpRequestInfo request; |
| 15294 | request.method = "POST"; |
| 15295 | request.url = GURL("http://www.foo.com/"); |
| 15296 | request.upload_data_stream = &upload_data_stream; |
| 15297 | request.load_flags = 0; |
| 15298 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15299 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15300 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15301 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15302 | // Send headers successfully, but get an error while sending the body. |
| 15303 | MockWrite data_writes[] = { |
| 15304 | MockWrite("POST / HTTP/1.1\r\n" |
| 15305 | "Host: www.foo.com\r\n" |
| 15306 | "Connection: keep-alive\r\n" |
| 15307 | "Content-Length: 3\r\n\r\n"), |
| 15308 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15309 | }; |
| 15310 | |
| 15311 | MockRead data_reads[] = { |
| 15312 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15313 | MockRead("hello world"), |
| 15314 | MockRead(SYNCHRONOUS, OK), |
| 15315 | }; |
| 15316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15317 | arraysize(data_writes)); |
| 15318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15319 | |
| 15320 | TestCompletionCallback callback; |
| 15321 | |
| 15322 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15323 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15324 | |
| 15325 | rv = callback.WaitForResult(); |
| 15326 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15327 | } |
| 15328 | |
| 15329 | TEST_P(HttpNetworkTransactionTest, |
| 15330 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15331 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15332 | element_readers.push_back( |
| 15333 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15334 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15335 | |
| 15336 | HttpRequestInfo request; |
| 15337 | request.method = "POST"; |
| 15338 | request.url = GURL("http://www.foo.com/"); |
| 15339 | request.upload_data_stream = &upload_data_stream; |
| 15340 | request.load_flags = 0; |
| 15341 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15342 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15343 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15345 | // Send headers successfully, but get an error while sending the body. |
| 15346 | MockWrite data_writes[] = { |
| 15347 | MockWrite("POST / HTTP/1.1\r\n" |
| 15348 | "Host: www.foo.com\r\n" |
| 15349 | "Connection: keep-alive\r\n" |
| 15350 | "Content-Length: 3\r\n\r\n"), |
| 15351 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15352 | }; |
| 15353 | |
| 15354 | MockRead data_reads[] = { |
| 15355 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15356 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15357 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15358 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15359 | MockRead(SYNCHRONOUS, OK), |
| 15360 | }; |
| 15361 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15362 | arraysize(data_writes)); |
| 15363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15364 | |
| 15365 | TestCompletionCallback callback; |
| 15366 | |
| 15367 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15369 | |
| 15370 | rv = callback.WaitForResult(); |
| 15371 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15372 | } |
| 15373 | |
| 15374 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15375 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15376 | element_readers.push_back( |
| 15377 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15378 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15379 | |
| 15380 | HttpRequestInfo request; |
| 15381 | request.method = "POST"; |
| 15382 | request.url = GURL("http://www.foo.com/"); |
| 15383 | request.upload_data_stream = &upload_data_stream; |
| 15384 | request.load_flags = 0; |
| 15385 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15386 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15387 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15388 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15389 | // Send headers successfully, but get an error while sending the body. |
| 15390 | MockWrite data_writes[] = { |
| 15391 | MockWrite("POST / HTTP/1.1\r\n" |
| 15392 | "Host: www.foo.com\r\n" |
| 15393 | "Connection: keep-alive\r\n" |
| 15394 | "Content-Length: 3\r\n\r\n"), |
| 15395 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15396 | }; |
| 15397 | |
| 15398 | MockRead data_reads[] = { |
| 15399 | MockRead("HTTP 0.9 rocks!"), |
| 15400 | MockRead(SYNCHRONOUS, OK), |
| 15401 | }; |
| 15402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15403 | arraysize(data_writes)); |
| 15404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15405 | |
| 15406 | TestCompletionCallback callback; |
| 15407 | |
| 15408 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15409 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15410 | |
| 15411 | rv = callback.WaitForResult(); |
| 15412 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15413 | } |
| 15414 | |
| 15415 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15416 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15417 | element_readers.push_back( |
| 15418 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15419 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15420 | |
| 15421 | HttpRequestInfo request; |
| 15422 | request.method = "POST"; |
| 15423 | request.url = GURL("http://www.foo.com/"); |
| 15424 | request.upload_data_stream = &upload_data_stream; |
| 15425 | request.load_flags = 0; |
| 15426 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15427 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15428 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15429 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15430 | // Send headers successfully, but get an error while sending the body. |
| 15431 | MockWrite data_writes[] = { |
| 15432 | MockWrite("POST / HTTP/1.1\r\n" |
| 15433 | "Host: www.foo.com\r\n" |
| 15434 | "Connection: keep-alive\r\n" |
| 15435 | "Content-Length: 3\r\n\r\n"), |
| 15436 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15437 | }; |
| 15438 | |
| 15439 | MockRead data_reads[] = { |
| 15440 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15441 | MockRead(SYNCHRONOUS, OK), |
| 15442 | }; |
| 15443 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15444 | arraysize(data_writes)); |
| 15445 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15446 | |
| 15447 | TestCompletionCallback callback; |
| 15448 | |
| 15449 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15450 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15451 | |
| 15452 | rv = callback.WaitForResult(); |
| 15453 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15454 | } |
| 15455 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15456 | // Verify that proxy headers are not sent to the destination server when |
| 15457 | // establishing a tunnel for a secure WebSocket connection. |
| 15458 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15459 | HttpRequestInfo request; |
| 15460 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15461 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15462 | AddWebSocketHeaders(&request.extra_headers); |
| 15463 | |
| 15464 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15465 | session_deps_.proxy_service = |
| 15466 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15467 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15468 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15469 | |
| 15470 | // Since a proxy is configured, try to establish a tunnel. |
| 15471 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15472 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15473 | "Host: www.example.org:443\r\n" |
| 15474 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15475 | |
| 15476 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15477 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15478 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15479 | "Host: www.example.org:443\r\n" |
| 15480 | "Proxy-Connection: keep-alive\r\n" |
| 15481 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15482 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15483 | MockWrite("GET / HTTP/1.1\r\n" |
| 15484 | "Host: www.example.org\r\n" |
| 15485 | "Connection: Upgrade\r\n" |
| 15486 | "Upgrade: websocket\r\n" |
| 15487 | "Origin: http://www.example.org\r\n" |
| 15488 | "Sec-WebSocket-Version: 13\r\n" |
| 15489 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15490 | }; |
| 15491 | |
| 15492 | // The proxy responds to the connect with a 407, using a persistent |
| 15493 | // connection. |
| 15494 | MockRead data_reads[] = { |
| 15495 | // No credentials. |
| 15496 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15497 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15498 | MockRead("Content-Length: 0\r\n"), |
| 15499 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15500 | |
| 15501 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15502 | |
| 15503 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15504 | MockRead("Upgrade: websocket\r\n"), |
| 15505 | MockRead("Connection: Upgrade\r\n"), |
| 15506 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15507 | }; |
| 15508 | |
| 15509 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15510 | arraysize(data_writes)); |
| 15511 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15512 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15514 | |
| 15515 | scoped_ptr<HttpTransaction> trans( |
| 15516 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15517 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15518 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15519 | &websocket_stream_create_helper); |
| 15520 | |
| 15521 | { |
| 15522 | TestCompletionCallback callback; |
| 15523 | |
| 15524 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15526 | |
| 15527 | rv = callback.WaitForResult(); |
| 15528 | EXPECT_EQ(OK, rv); |
| 15529 | } |
| 15530 | |
| 15531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15532 | ASSERT_TRUE(response); |
| 15533 | ASSERT_TRUE(response->headers.get()); |
| 15534 | EXPECT_EQ(407, response->headers->response_code()); |
| 15535 | |
| 15536 | { |
| 15537 | TestCompletionCallback callback; |
| 15538 | |
| 15539 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15540 | callback.callback()); |
| 15541 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15542 | |
| 15543 | rv = callback.WaitForResult(); |
| 15544 | EXPECT_EQ(OK, rv); |
| 15545 | } |
| 15546 | |
| 15547 | response = trans->GetResponseInfo(); |
| 15548 | ASSERT_TRUE(response); |
| 15549 | ASSERT_TRUE(response->headers.get()); |
| 15550 | |
| 15551 | EXPECT_EQ(101, response->headers->response_code()); |
| 15552 | |
| 15553 | trans.reset(); |
| 15554 | session->CloseAllConnections(); |
| 15555 | } |
| 15556 | |
| 15557 | // Verify that proxy headers are not sent to the destination server when |
| 15558 | // establishing a tunnel for an insecure WebSocket connection. |
| 15559 | // This requires the authentication info to be injected into the auth cache |
| 15560 | // due to crbug.com/395064 |
| 15561 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15562 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15563 | HttpRequestInfo request; |
| 15564 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15565 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15566 | AddWebSocketHeaders(&request.extra_headers); |
| 15567 | |
| 15568 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15569 | session_deps_.proxy_service = |
| 15570 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15571 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15572 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15573 | |
| 15574 | MockWrite data_writes[] = { |
| 15575 | // Try to establish a tunnel for the WebSocket connection, with |
| 15576 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15577 | // they cannot and will not use the same TCP/IP connection as the |
| 15578 | // preflight HTTP request. |
| 15579 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15580 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15581 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15582 | "Proxy-Connection: keep-alive\r\n" |
| 15583 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15584 | |
| 15585 | MockWrite( |
| 15586 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15587 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15588 | "Connection: Upgrade\r\n" |
| 15589 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15590 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15591 | "Sec-WebSocket-Version: 13\r\n" |
| 15592 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15593 | }; |
| 15594 | |
| 15595 | MockRead data_reads[] = { |
| 15596 | // HTTP CONNECT with credentials. |
| 15597 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15598 | |
| 15599 | // WebSocket connection established inside tunnel. |
| 15600 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15601 | MockRead("Upgrade: websocket\r\n"), |
| 15602 | MockRead("Connection: Upgrade\r\n"), |
| 15603 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15604 | }; |
| 15605 | |
| 15606 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15607 | arraysize(data_writes)); |
| 15608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15609 | |
| 15610 | session->http_auth_cache()->Add( |
| 15611 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15612 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15613 | |
| 15614 | scoped_ptr<HttpTransaction> trans( |
| 15615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15616 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15617 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15618 | &websocket_stream_create_helper); |
| 15619 | |
| 15620 | TestCompletionCallback callback; |
| 15621 | |
| 15622 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15623 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15624 | |
| 15625 | rv = callback.WaitForResult(); |
| 15626 | EXPECT_EQ(OK, rv); |
| 15627 | |
| 15628 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15629 | ASSERT_TRUE(response); |
| 15630 | ASSERT_TRUE(response->headers.get()); |
| 15631 | |
| 15632 | EXPECT_EQ(101, response->headers->response_code()); |
| 15633 | |
| 15634 | trans.reset(); |
| 15635 | session->CloseAllConnections(); |
| 15636 | } |
| 15637 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15638 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15639 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15640 | element_readers.push_back( |
| 15641 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15642 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15643 | |
| 15644 | HttpRequestInfo request; |
| 15645 | request.method = "POST"; |
| 15646 | request.url = GURL("http://www.foo.com/"); |
| 15647 | request.upload_data_stream = &upload_data_stream; |
| 15648 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15649 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15650 | scoped_ptr<HttpTransaction> trans( |
| 15651 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15652 | MockWrite data_writes[] = { |
| 15653 | MockWrite("POST / HTTP/1.1\r\n" |
| 15654 | "Host: www.foo.com\r\n" |
| 15655 | "Connection: keep-alive\r\n" |
| 15656 | "Content-Length: 3\r\n\r\n"), |
| 15657 | MockWrite("foo"), |
| 15658 | }; |
| 15659 | |
| 15660 | MockRead data_reads[] = { |
| 15661 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15662 | MockRead(SYNCHRONOUS, OK), |
| 15663 | }; |
| 15664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15665 | arraysize(data_writes)); |
| 15666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15667 | |
| 15668 | TestCompletionCallback callback; |
| 15669 | |
| 15670 | EXPECT_EQ(ERR_IO_PENDING, |
| 15671 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15672 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15673 | |
| 15674 | std::string response_data; |
| 15675 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15676 | |
| 15677 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15678 | trans->GetTotalSentBytes()); |
| 15679 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15680 | trans->GetTotalReceivedBytes()); |
| 15681 | } |
| 15682 | |
| 15683 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15684 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15685 | element_readers.push_back( |
| 15686 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15687 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15688 | |
| 15689 | HttpRequestInfo request; |
| 15690 | request.method = "POST"; |
| 15691 | request.url = GURL("http://www.foo.com/"); |
| 15692 | request.upload_data_stream = &upload_data_stream; |
| 15693 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15694 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15695 | scoped_ptr<HttpTransaction> trans( |
| 15696 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15697 | MockWrite data_writes[] = { |
| 15698 | MockWrite("POST / HTTP/1.1\r\n" |
| 15699 | "Host: www.foo.com\r\n" |
| 15700 | "Connection: keep-alive\r\n" |
| 15701 | "Content-Length: 3\r\n\r\n"), |
| 15702 | MockWrite("foo"), |
| 15703 | }; |
| 15704 | |
| 15705 | MockRead data_reads[] = { |
| 15706 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15707 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15708 | MockRead(SYNCHRONOUS, OK), |
| 15709 | }; |
| 15710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15711 | arraysize(data_writes)); |
| 15712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15713 | |
| 15714 | TestCompletionCallback callback; |
| 15715 | |
| 15716 | EXPECT_EQ(ERR_IO_PENDING, |
| 15717 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15718 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15719 | |
| 15720 | std::string response_data; |
| 15721 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15722 | |
| 15723 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15724 | trans->GetTotalSentBytes()); |
| 15725 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15726 | trans->GetTotalReceivedBytes()); |
| 15727 | } |
| 15728 | |
| 15729 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15730 | ChunkedUploadDataStream upload_data_stream(0); |
| 15731 | |
| 15732 | HttpRequestInfo request; |
| 15733 | request.method = "POST"; |
| 15734 | request.url = GURL("http://www.foo.com/"); |
| 15735 | request.upload_data_stream = &upload_data_stream; |
| 15736 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15737 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15738 | scoped_ptr<HttpTransaction> trans( |
| 15739 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15740 | // Send headers successfully, but get an error while sending the body. |
| 15741 | MockWrite data_writes[] = { |
| 15742 | MockWrite("POST / HTTP/1.1\r\n" |
| 15743 | "Host: www.foo.com\r\n" |
| 15744 | "Connection: keep-alive\r\n" |
| 15745 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15746 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15747 | }; |
| 15748 | |
| 15749 | MockRead data_reads[] = { |
| 15750 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15751 | MockRead(SYNCHRONOUS, OK), |
| 15752 | }; |
| 15753 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15754 | arraysize(data_writes)); |
| 15755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15756 | |
| 15757 | TestCompletionCallback callback; |
| 15758 | |
| 15759 | EXPECT_EQ(ERR_IO_PENDING, |
| 15760 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15761 | |
| 15762 | base::RunLoop().RunUntilIdle(); |
| 15763 | upload_data_stream.AppendData("f", 1, false); |
| 15764 | |
| 15765 | base::RunLoop().RunUntilIdle(); |
| 15766 | upload_data_stream.AppendData("oo", 2, true); |
| 15767 | |
| 15768 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15769 | |
| 15770 | std::string response_data; |
| 15771 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15772 | |
| 15773 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15774 | trans->GetTotalSentBytes()); |
| 15775 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15776 | trans->GetTotalReceivedBytes()); |
| 15777 | } |
| 15778 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15779 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
| 15780 | session_deps_.next_protos = NextProtosDefaults(); |
| 15781 | session_deps_.enable_npn = true; |
| 15782 | |
| 15783 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15785 | |
| 15786 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15787 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15788 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15789 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15790 | } |
| 15791 | |
| 15792 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
| 15793 | session_deps_.next_protos = NextProtosDefaults(); |
| 15794 | session_deps_.enable_npn = false; |
| 15795 | |
| 15796 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15798 | |
| 15799 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15800 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15801 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15802 | } |
| 15803 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15804 | } // namespace net |